To use the Pay Kit SDK to create a shopper request, a merchant loads the script from Cash App's global CDN. The following scripts are available for sandbox development and production environments:

  • Sandbox development:
    <script src="https://sandbox.kit.cash.app/v1/pay.js"></script>

  • Production:
    <script src="https://kit.cash.app/v1/pay.js"></script>

Initialize the Pay Kit

Once the scripts are loaded, merchants initiate the Pay Kit with a clientId provided by Radial Payment Solutions (RPS):

const pay = await window.CashApp.pay({ clientId: 'YOUR_CLIENT_ID' });

The preceding code is doing the following:

  • window.CashApp.pay(...): This function call initiates a payment using the Pay Kit. window.CashApp is an object that contains the pay method, which starts the payment process.It becomes available after including the Pay Kit script on the webpage.

  • await: This keyword is used because window.CashApp.pay(...) is an asyncronous function that returns a Promise. A Promise is an object representing the completion or failure of an asynchronous operation. In this case, await is used to wait for the payment process to complete before moving on to the next line of code.

  • { clientId: 'YOUR_CLIENT_ID' }: This is the configuration object passed to the pay method.

    Note: There are separate clientIds for sandbox development and production.

Render the Cash App Pay and Create the Customer Request

Pay Kit provides a fully managed UI that you can customize to fit the checkout experience. To add the CashApp button, a division, (that is, "div") container needs to exist that the Cash App UI window can populate.

html: <div id="cash-app-pay"><!-- Populated by Pay Kit --></div>

Generate the Cash App Pay Button

Merchants initiate a request to perform actions on a customer's account. Approved actions result in grants that can be used to create payments. The Pay Kit exposes a customerRequest method that creates a Customer Request with one or more actions. Note: Once you make this call, the Cash App Pay button appears. When the customer clicks the button using a web-based checkout, the QR code is shown.

Copy
await pay.customerRequest({
                        actions: {
                        payment: {
                        amount: {
                        currency: "USD",
                        value: 1234,
                        },
                        scopeId: 'merchant_id',
                        },
                        },
                        redirectURL: "redirect_url",
                        referenceId: "reference-id",
                        });

                    await pay.render('#cash-app-container');


This code generates the Cash App Pay button when the CustomerRequest call is made.

Listen for Events

The Pay Kit SDK emits a number of events throughout the lifecycle of a payment. One of the most important ones is CUSTOMER_REQUEST_APPROVED, which is emitted after a shopper approves a one-time payment or other action. You use this data to create a payment, as shown in the following example.

Copy
cashAppPay.addEventListener('CUSTOMER_REQUEST_APPROVED', (data) => {
                        grandId = data.grants.payment.grantId;
                    });

Events

Event Name Event Description Event Return Type - PayEventData Further Action
CUSTOMER_INTERACTION This event is triggered whenever the QR popup is shown CustomerInteractionData Customer will scan the QR Code and approve/decline payment, The QR Code refreshes by itself for every 30 seconds
CUSTOMER_DISMISSED This event is triggered when the customer closes the QR popup No Data Returned Customer can click on CashAppPay button and do the payment again
CUSTOMER_REQUEST_APPROVED This event is triggered whenever the customer scans the QR code and approves the payment via the Cash App CustomerRequestData Get thegrantIdfrom the response and send it to Radial EPS via the PaymentAuthorizationRequest
CUSTOMER_REQUEST_DECLINED This event is triggered whenever the customer scans the QR code and declines the payment via the Cash App No Data Returned In the event of Customer Declining the Payment, it is upto the webstore to route the customer to appropriate page to do the new payment
CUSTOMER_REQUEST_FAILED      

PayEventData: CustomerInteractionData | CustomerRequestData

CustomerInteractionData
Name Type Description
isMobile boolean Value is true if the customer is using a mobile device where Cash App can be installed.
CustomerRequestData
Name Type Description
customerProfile Customer Customer details
grants Partial<Record<keyof Actions, GrantDetail>> A map of actions to details about a grant
referenceId string A reference to your system (for example, a cart or checkout identifier)
Customer

The Customer who approved the request.

Name Type Description
cashtag string Public identifier for the customer on Cash App.
id string A Unique identifier for this customer issued by Cash App.
Grants

The map of action to details about a grant may have keys payment or onFile (same as Actions below). GrantDetail has the following properties:

Name Type Description
expiresAt Date When the grant will expire
grantId string ID of Grant that can be used to Create Payment.

 

Parameters

Name Type Description
actions Actions Actions the customer will allow the merchant to perform.
actions.payment.amount Amount The amount to charge the customer.
actions.payment.amount.currency string "USD" is currently the only accepted value.
actions.payment.amount.value number The lowest unit of the associated currency (for example, 1234 for 12.34 USD).
actions.payment.scopeId string ID of the client or brand account that will charge Customers.
redirectURL string The destination for the customer after approving (or declining) in Cash App for mobile redirect flow. Must be a secure URL.
referenceId (optional) string A reference to merchants system (for example, a cart or checkout identifier). Maximum length 1024 characters.

Once the Grant ID is received, the webstore should send the Authorization request with the Grant Id. Refer to Create Payment for the next steps.