The 123Flip app is integrated with Stripe, a payment processor or gateway that allows your users or customers to safely and efficiently transfer funds from their credit cards or bank accounts in a variety of currencies.

This integration can provide extra revenue earning for developer. In the case of 123Flip app, users who wants to add personalized message and link needs to pay a small token known as sponsor fee.

Work flow: select a game to sponsor > verify google sign-in > credit card payment

Integrate Stripe in Android [Server side]

To integrate Stripe in android app, we will first begin with the server side and then go to android studio. On server side, we need to write the some server codes (which is actually quite short).

I use VS editor and test on Node.JS server on workstation before deploying somewhere in the cloud. I deploy the server codes to Heroku, which is a platform or service (PaaS) that enables developers to build, run, and operate applications entirely in the cloud. I choose Heroku because it offers a free plan.

Download and install the following free tools and sign up a free account with Heroku.

* Node.JS [link]
* VS code (for editing) [link]
* Creates Stripe account [link]
* Heroku CLI [link] + Git [link]

Installation steps for Node.JS, VS code, and Stripe account

How to Install Node.js on Window 10
Install and Use Visual Studio Code on Windows 10 (VS Code)
Create Stripe Account and Providing Your Developer The API Keys

Step 1:
(i) In Build.gradle, add stripe, okhttp & gson library
(ii) In AndroidManifest.xml, add internet permission

(i) In Build.gradle, add :
//Stripe dependency
    implementation 'com.stripe:stripe-android:18.0.0'
// for network call
    implementation 'com.squareup.okhttp3:okhttp:4.4.0'
    implementation 'com.google.code.gson:gson:2.8.6'
(ii) In AndroidManifest.xml, add :
<uses-permission android:name="android.permission.INTERNET"/>

Step 2:
Add server code in server.js (VS code)

const express = require("express");
const app = express();
// This is your test secret API key.
const stripe = require("stripe")("sk_test_51JiugAJfHDlzUJLDt39KpbTq33H0983xeErpLas2IjWz5Y6ihVW8msoEiARxPOuO9yVEzLE9CL0qXqR8Cm3LSsyz007YQE4Gj2");
Read more

Step 3:
(i) Test and run server.js in Node.js
(ii) Deploy server.js to Heroku

Stripe Payment Integration with android | Server Code

Step 4:
Design your payment UI in activity_checkout.xml with Stripe CardInputWidget

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
Read more

Step 5:
In CheckoutActivity.kt (when payButton is clicked):
(i) startCheckout() is called to get paymentIntentClientSecret key
(ii) Transaction result is returned in onPaymentResult()
(iii) Payment is completed

class CheckoutActivity : AppCompatActivity() {
    private val CHECKOUTACITIVTY_REQUEST_CODE = 321

    // 10.0.2.2 is the Android emulator's alias to localhost
    //private val backendUrl = "http://10.0.2.2:4242/"
    private val backendUrl = "https://diok.herokuapp.com/"
    private val httpClient = OkHttpClient()
    private lateinit var paymentIntentClientSecret: String
    private lateinit var paymentLauncher: PaymentLauncher
    lateinit var body : RequestBody
Read more