Technical Reference

Pay

Pay Kit initializes to window.CashApp when you include our script and exposes an asynchronous pay method which requires a Client ID. The Promise resolves an instance of Pay.

1<script src="https://kit.cash.app/v1/pay.js"></script>
2<script>
3 const pay = await window.CashApp.pay({ clientId: 'YOUR_CLIENT_ID');
4</script>

Parameters

NameTypeDescription
clientIdstringA short application identifier that Cash App uses to attribute API calls to your integration.

addEventListener

Pay exposes an addEventListener method that listens for events throughout the lifecycle of paying.

1pay.addEventListener('CUSTOMER_REQUEST_APPROVED', (data) => {});

Parameters

NameTypeDescription
type"CUSTOMER_INTERACTION" | "CUSTOMER_DISMISSED" | "CUSTOMER_REQUEST_APPROVED" | "CUSTOMER_REQUEST_DECLINED" | "CUSTOMER_REQUEST_FAILED"event type
listenerPayEventListenerevent handler

PayEventListener: (data: PayEventData) => void

The "CUSTOMER_REQUEST_DECLINED" and "CUSTOMER_REQUEST_FAILED" events will not receive data.

PayEventData: CustomerInteractionData | CustomerRequestData

CustomerInteractionData
NameTypeDescription
isMobilebooleanValue is true if the customer is using a mobile device where Cash App can be installed.
CustomerRequestData
NameTypeDescription
customerProfileCustomerCustomer
grantsPartial<Record<keyof Actions, GrantDetail>>A map of actions to details about a grant
referenceIdstringA reference to your system (for example, a cart or checkout identifier)
Customer

The Customer who approved the request.

NameTypeDescription
cashtagstringPublic identifier for the customer on Cash App. Learn more
idstringUnique 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:

NameTypeDescription
expiresAtDateWhen the grant will expire, at which point, you will need to create a new Customer Request.
grantIdstringID of Grant that can be used to create a payment.

Returns

void


removeEventListener

Pay exposes a removeEventListener method that removes an event listener previously registered with addEventListener.

1const createPayment = ({ grants }) => {
2 // create your payment with the grant
3};
4
5pay.addEventListener('CUSTOMER_REQUEST_APPROVED', createPayment);
6
7// when your application needs to destroy, teardown, unmount, etc.
8pay.removeEventListener('CUSTOMER_REQUEST_APPROVED', createPayment);

Parameters

NameTypeDescription
type"CUSTOMER_INTERACTION" | "CUSTOMER_DISMISSED" | "CUSTOMER_REQUEST_APPROVED" | "CUSTOMER_REQUEST_DECLINED" | "CUSTOMER_REQUEST_FAILED"event type
listenerPayEventListenerevent handler

Returns

void


customerRequest

Pay exposes a customerRequest method that creates a Customer Request with one or more actions. You’ll need a Merchant to create a payment.

1await pay.customerRequest({
2 actions: {
3 payment: {
4 amount: {
5 currency: 'USD',
6 value: 1234, // $12.34
7 },
8 scopeId: 'merchant_id_from_network_api',
9 },
10 },
11 redirectURL: window.location.href, // where mobile customers should be redirected to
12 referenceId: 'your_reference_id', // perhaps a cart or checkout identifier
13});

Parameters

The customerRequest method takes a CustomerRequestDetails object as its only argument. It has the following properties:

NameTypeDescription
actionsActionsActions the customer will allow the merchant to perform.
redirectURLstringThe destination for the customer after approving (or declining) in Cash App for mobile redirect flow. Must be a secure URL.
referenceId (optional)stringA reference to your system (for example, a cart or checkout identifier). Maximum length 1024 characters.

Actions is an object with optional onFile and payment properties, but at least one must exist.

onFile
NameTypeDescription
scopeIdstringID of the client or brand account that will charge Customers.
accountReferenceIdstringIdentifier of the account or Customer associated to the on-file action.
payment
NameTypeDescription
amount (optional)AmountThe amount to charge the customer.
scopeIdstringThe ID of the client, brand, or merchant account that will charge customers.
Amount

Amount to charge the customer.

NameTypeDescription
currencystring”USD” is currently the only accepted value.
valuenumberThe lowest unit of the associated currency (for example, cents for USD).

Returns

Promise<CustomerRequestController>

CustomerRequestController

CustomerRequestController controls the Customer Request.

1const details = { referenceId: 'initial', redirectURL: '...', actions: { ... } };
2const { update } = await pay.customerRequest(details)
3
4details.referenceId = 'final'
5
6const success = await update(details)
7if (success) {
8 // continue creating payment with latest details
9} else {
10 // creating payment could possibly fail if a more complex change was made to `details`
11}
update

The update method will update your Customer Request. The same validation applies (for example, must have at least one action) except redirectURL cannot be changed.

NameTypeDescription
detailsCustomerRequestDetailsNew value for the details of the Customer Request.

Returns Promise<boolean> to indicate if the update was successful. An example of when an update would not be successful is if the Customer Request has already been approved.


render

Pay exposes a render method that renders a managed Cash App Pay UI into your DOM.

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

Parameters

NameTypeDescription
targetstring | HTMLElementThe location to insert Cash App Pay’s UI in your DOM.
options (optional)RenderOptionsSee details about RenderOptions below.

RenderOptions is an object with these optional properties:

NameTypeDescription
buttonButtonOptions | falseSee details about ButtonOptions below. If false, no button will be rendered, and you should provide your own.
managebooleanIf true, Pay Kit will manage beginning the authorization flow. See RenderController below for more details. Defaults to true.

ButtonOptions is an object with these optional properties:

NameTypeDescription
shape"round" | "semiround"The shape of the Cash App Pay button. Defaults to “round”
size"medium" | "small"The size of the Cash App Pay button. Defaults to “medium”
theme"dark" | "light"The theme of the Cash App Pay button. Defaults to “dark”
width"full" | "static"The width of the Cash App Pay button. Defaults to “static”

Returns

Promise<RenderController>

RenderController

RenderController can control rendering.

begin

The begin method will begin the authorization flow for the customer if the manage option was false. Otherwise, it is a no-op. To use your own button and control the flow, you must set both manage and button to false.

1const { begin } = await pay.render('#cash-app-pay', {
2 button: false,
3 manage: false,
4});
5
6document.querySelector('#my-checkout-button').addEventListener('click', () => {
7 // NB: a customer may be redirected away from your page
8 begin();
9});
destroy

The destroy method will remove the Cash App Pay UI from your DOM.

1const { destroy } = await pay.render('#cash-app-pay');
2
3// when your application needs to teardown, unmount, etc.
4destroy();

restart

Pay exposes a restart method that removes all rendered UI as well as the current customer request.

In a single page app,pay.restart() must be called whenever the buyer leaves the checkout page. You can only make a new customer request after restart, if the current customer request is approved.

1await pay.restart();

Parameters

None

Returns

void

Custom elements

Pay Kit provides custom elements to help customize checkout experiences while making it easy to follow brand guidelines.

The <cash-app-pay-logo> element renders the Cash App Pay logo and can be customized with two attributes:

NameTypeDescription
size"medium" | "small"The size of the logo.
theme"dark" | "light"The theme of the logo.

Customer

The <cash-app-pay-customer> element renders the Cash App Pay logo and a customer’s $Cashtag. The cashtag attribute is required and will be automatically truncated if needed. The element will grow to fill its parent container.

1<cash-app-pay-customer cashtag="$jack" />