Pay Kit Android: Getting Started
Prerequisites
- All integrations require a Client ID provided by Cash App (see Deliverables: Cash App Pay Partner Engineering)
- To authorize payments for a specific Merchant or Brand, you’ll need to create a Merchant or create a Brand using the Cash App REST APIs.
One-time payments can be authorized for a Merchant, Brand, or Client. On-file payments can only be authorized for a Brand or Client.
General SDK information
- Minimum Android supported SDK:
21 - Target Android SDK:
36
Step 1: Import the dependency
Get the latest version of the SDK from Maven.
Gradle
Gradle version catalogs
For the latest released version, check GitHub Releases or Cash App Pay Android SDK on Maven Central.
Step 2: Create an SDK instance
Use the Sandbox environment during the development phase and use the production environment for your actual production releases. Use the Sandbox App to more closely simulate a production experience while on Sandbox environment. This application is optional, but highly recommended as it will simulate Cash App, and allow you to easy trigger edge-cases for testing.
Use CashAppPayFactory to create an instance of the SDK.
- During setup, specify the development environment you will use: Sandbox or Production.
- To create a new instance of the SDK, pass
client ID. This is a required field. - The function
createSandbox()will create an SDK instance in the Sandbox environment.
Creating a Sandbox SDK instance:
Creating a Production SDK instance:
Step 3: Register for state updates
To receive updates from Pay Kit, implement the CashAppPayListener interface.
- The interface exposes a single function, which gets called whenever there’s an internal state change emitted by the SDK.
- Register with the SDK instance you’ve created above:
- Use the
unregisterfunction after you have finished using the SDK:
States
CashAppPayState is a sealed class parameter. We recommend that you use a Kotlin when statement when integrating with the SDK. The following are examples of critical states:
Step 4: Handling Deep Linking
The authorization flow brings Cash App to the foreground on the Customer’s device. After the Customer either authorizes or declines the request, your app must be returned to the foreground.
To call your app back to the foreground, declare an incoming intent filter on your app’s Android Manifest. When creating a customer request, pass a corresponding redirect URI that uses the SDK.
Example integration
AndroidManifest
Step 5: Create a Customer Request
Create a Customer Request as soon as you know the amount you want to charge or if you want to create an on-file payment request. We recommend that you create this request as soon as your checkout view controller loads, so that the Customer can authorize the request immediately.
Note: If you’re using Afterpay SDK together with Cash App Pay SDK, the merchantId contained within that data is the same as scopeId in this context.
Example of a One-Time Payment
To charge $5.00 as a one-time payment, the create request call might look like this:
Example of an On-File Payment
Example of a Payout
With payouts you can send money to a user’s Cash App account. For mobile development the Pay Kit SDK, the payout workflow is identical to the two above.
Step 6: Authorize the Customer Request
After the SDK is in the ReadyToAuthorize state, display the enabled Cash App Pay button. When the Customer taps the button, you can authorize the Customer Request.
Example
The Button provided by the SDK is unmanaged. It is a stylized button that isn’t aware of SDK events out-of-the-box. It is the developer’s responsibility to call the above method when the button is clicked and also manage any disabled and loading states.
Your app will redirect to Cash App for authorization. When the authorization is completed, your redirect URI is called to open your app. The SDK fetches your authorized request and returns it to your callback listener as one of 2 states: Approved or Declined.
Step 7: Pass Grants to the Backend and Create Payment
The Approved state contains a Grants list object associated with it and it can be used with the Cash App Create Payment API. Pass these grants to your backend and call the CreatePayment API as a server-to-server call to complete your payment.