To save a Cash App Pay payment method for future payments, you must attach it to a Customer.
Create a Customer object when your customer creates an account with your business. Associate the ID of the Customer object with your own internal representation of a customer. Alternatively, you can create the Customer object before you save a payment method for future payments.
Include the following code on your server to create a new Customer.
Save your customer’s Cash App Pay credentials($Cashtag) to charge their account for future, off-session payments. Your custom payment form must present a written notice of authorization before confirming the PaymentIntent or SetupIntent.
The authorization terms only need to be displayed the first time you save a customer’s $Cashtag.
We recommend that you use the following text for your custom payment form:
By continuing, you authorize Rocket Rides to debit your Cash App account for this payment and future payments in accordance with Rocket Rides's terms, until this authorization is revoked. You can change this anytime in your Cash App Settings.
Use the Setup Intents API to collect payment method details in advance and determine the final amount or payment date at a later point. This is useful for:
Saving payment methods for customers so their later purchases don’t require authentications
A SetupIntent is an object that represents your intent to set up a customer’s payment method for future payments. The SetupIntent tracks the steps of this set-up process. Create a SetupIntent on your server with payment_method_types set to cashapp and specify the Customer’s ID and usage=off_session or usage=on_session.
The SetupIntent includes a client secret that the client side uses to securely complete the payment process. You can use different approaches to pass the client secret to the client side.
Retrieve the client secret from an endpoint on your server, using the browser’s fetch function. This approach is best if your client side is a single-page application, particularly one built with a modern frontend framework like React. Create the server endpoint that serves the client secret:
get '/secret'do
intent =# ... Create or retrieve the SetupIntent{client_secret: intent.client_secret}.to_json
end
And then fetch the client secret with JavaScript on the client side:
(async()=>{const response =awaitfetch('/secret');const{client_secret: clientSecret}=await response.json();// Render the form using the clientSecret})();
Next, you save Cash App Pay on the client with Stripe.js.
Include the Stripe.js script on your checkout page by adding it to the head of your HTML file.
Create an instance of Stripe.js with the following JavaScript on your checkout page:
client.js
// Set your publishable key. Remember to change this to your live publishable key in production!// See your keys here: https://dashboard.stripe.com/apikeysconst stripe =Stripe(
'pk_test_TYooMQauvdEDq54NiTphI7jx'
);
Use stripe.confirmCashappSetup to confirm the setupIntent on the client side, with a return_url and an optional mandate_data. Use the return_url to redirect customers to a specific page after the SetupIntent succeeds.
client.js
const form = document.getElementById('setup-form');
form.addEventListener('submit',function(event){
event.preventDefault();// Set the clientSecret here
stripe.confirmCashappSetup(
clientSecret,{
payment_method:{
type:'cashapp',},
return_url:'https://www.example.com/checkout/done',},);});
Customers can authenticate Cash App Pay with mobile or desktop apps. After calling confirmCashappSetup, the client the customer uses determines the authentication method such as redirect for mobile or QR code for desktop. The authentication response also includes a payment method ID that you need to use in the next step to make a PaymentIntent.
After calling confirmCashappSetup, Stripe redirects your customers to Cash App for authorization. After they authorize the payment, Stripe sends them to the Setup Intent’s return_url. Stripe adds setup_intent, setup_intent_client_secret, redirect_pm_type, and redirect_status as URL query parameters, along with any existing query parameters in the return_url.
An authentication session expires after 10 minutes, and the SetupIntent’s status transitions back to require_payment_method. After the status transitions, the customer sees an authorization error and must restart the process.
After you create a PaymentMethod, you can accept future Cash App Pay payments by creating and confirming a PaymentIntent. When confirming a PaymentIntent, use the same payment method ID from the previous SetupIntent or PaymentIntent object. The off_session value must also be set to true if the customer isn’t in a checkout flow for this PaymentIntent.
There are two ways to revoke a reusable payment method:
A customer can deactivate a reusable payment method in the Cash App mobile application. In this case, Stripe sends a mandate.updated event. Subscribe to webhook events, and call detach PaymentMethod to deactivate it.
A customer can also deactivate a reusable payment method on your UI, if supported. In this case, your server can call detach PaymentMethod to deactivate it.