Cash App Pay on iOS
Accept Cash App Pay in your iOS app with your Afterpay merchant account. The Afterpay SDK works with the Cash App Pay Kit iOS SDK: Pay Kit sends the customer to Cash App to approve the payment, and the Afterpay SDK connects that approval to your Afterpay order.
Cash App Pay is available in the US.
You can accept Cash App Pay in two ways:
Set up Pay Kit
Both flows use the same Pay Kit setup.
Install Pay Kit
Add the cash-app-pay-ios-sdk package with Swift Package Manager:
Add the PayKit product to your app target, and add PayKitUI if you use the Cash App Pay button. You can also install Pay Kit with CocoaPods: pod 'CashAppPayKit' and pod 'CashAppPayKitUI'.
Handle the redirect from Cash App
After the customer approves or declines the payment, Cash App opens your app with a redirect URL. Register a custom URL scheme or a universal link for your app. Then post CashAppPay.RedirectNotification when your app opens the URL:
Observe Pay Kit states
Pay Kit reports its progress through the CashAppPayObserver protocol. Update your UI for each state:
If Cash App isn’t installed, the customer is sent to a web page to download it, and Pay Kit stays in the polling state. Set a timeout for this state. When it expires, dismiss any loading indicator and let the customer start again or choose another payment method.
Server checkout
This flow uses the merchant configuration that you set with Afterpay.setConfiguration(_:). For details, see Configure the SDK.
Step 1: Create a checkout for Cash App Pay
Your server calls Create Checkout with isCashAppPay set to true and returns the token to your app.
Set both merchant.redirectConfirmUrl and merchant.redirectCancelUrl in the request. If you don’t, Create Checkout returns an error.
Step 2: Create Pay Kit
Create Pay Kit with Afterpay.cashAppClientId and the same environment as your Afterpay configuration:
Step 3: Sign the token and create a customer request
Sign the checkout token with the Afterpay SDK. Then use the signing data to create a Pay Kit customer request. Do this as soon as your checkout screen loads, so that the customer can approve the payment without waiting.
The completion handler runs on a background queue, so move to the main queue before you update your UI. If you haven’t set the configuration, or Afterpay.enabled is false, the SDK doesn’t call the completion handler.
Pay Kit moves to creatingCustomerRequest, then to readyToAuthorize.
Step 4: Authorize the customer request
When the customer taps the Cash App Pay button, authorize the request. Pay Kit opens Cash App.
Step 5: Validate the order
When Pay Kit moves to approved, validate the order with the Afterpay SDK. Don’t skip this step. As with signing, the completion handler runs on a background queue.
Step 6: Capture the payment
Your server captures the payment with Capture Full Payment, or authorizes it with Auth to capture later. Use the checkout token, as for any other Afterpay order. The grantId request field is only for payments with a stored on-file grant, so don’t send the grant from this checkout.
Afterpay Button
This flow uses the Afterpay Button configuration instead of the merchant configuration:
Step 1: Create the checkout
Call checkoutV3WithCashAppPay with the customer and order total. Store the result.
Step 2: Create Pay Kit and the customer request
Create Pay Kit with Afterpay.checkoutV3CashAppClientId, which reads the Afterpay Button configuration. For the endpoint, use the same environment that you passed to CheckoutV3Configuration: Afterpay.environment reads the merchant configuration, so it’s nil if you set only the Afterpay Button configuration. Then create the customer request with the signing data from the payload:
When Pay Kit moves to readyToAuthorize and the customer taps the Cash App Pay button, call authorizeCustomerRequest(_:).
Step 3: Confirm the checkout
When Pay Kit moves to approved, confirm the checkout with the grant. The SDK returns the virtual card details and the time before which you must authorize the card.
Test Cash App Pay
In the sandbox, test with the Cash App sandbox app. Make sure that Pay Kit and the Afterpay SDK use the same environment.