Skip to main content

Introduction

This guide covers the steps to integrate Apple Pay as a payment option. For users that are supported, users can select Apple Pay and complete the transaction on their device via the Apple Pay payment sheet. Push will authorize the transaction with the user’s bank and return the payment result to your backend.

Step 1: Display Apple Pay option to user

Load the SDK from the CDN

To render the Apple Pay option, you must load the Push Javascript SDK from our CDN.
<script src="https://cdn.pushcash.com/sdk/push.umd.js"></script>

Render Apple Pay button

Display an option for the user to select Apple Pay as their payment method. Make a call to the Push Cash SDK to determine if Apple Pay is supported on the user’s device.
const supported = window.PushCash.ApplePayAvailable()

if (supported) {
   // render Apple Pay option to DOM
}
See Apple’s human interface design guidelines for guidance on how to present the option to users.

Step 2: Create Apple Pay Intent & Token

Once a user has selected to use Apple Pay, present the Apple Pay experience to them. In order to do this, you must:
  1. Register a user
  2. Create an Apple Pay intent & token

Register a user

If a user has not previously used Push, you must register them. Make a request to the create user endpoint with all the required information and store the user ID returned in the response in your database along with the user record.
It is important to ensure that users are registered only once with Push. If a user has previously used Push for a withdrawal OR deposit, you MUST re-use the user created from that flow in order to ensure that the user’s stored payment information is persisted.

Create Apple Pay Intent & Token

Make a request to Push to create a payment intent. Submit the user ID, the payment amount & currency, direction = cash_in, and type = apple_pay.
curl --request POST \
	--url https://sandbox.pushcash.com/intent \
 	--header 'Authorization: Bearer '$PUSH_API_KEY \
	--header 'X-Idempotency-Key: 1234' \
	--data '{
		"user_id": "user_lVpbPL0K1XIiHx0DxipRbD",
		"amount": 1000,
		"direction": "cash_in",
		"currency": "USD",
		"type": "apple_pay"
	}'
The response will contain the intent ID and Apple Pay token:
{
   "id": "intent_production_mbDRHFi3dxIZEtykHsgUGC",
   "token": "MCkFtYXpvbiBSRFMxCzAJBgNVBAgMAldBMTAwLgYDVQQDDCdB..."}

Step 3: Launch Apple Pay Experience

After creating a payment intent and token with Push, use the token to initiate the Apple Pay experience on the user’s device via the Push SDK.

Use token to create an Apple Pay session

Use the Apple Pay token to create a new session.
const session = new window.PushCash.ApplePay({
   'token': '<your-token>'
});

Start session & specify callback

Set the callback on the session. The callback will receive an intent ID which can be used to fetch the intent status from the Push Cash API. In your callback function, you should:
  1. Make a request to get an intent with the intent ID
  2. Update your database with the payment result
  3. Notify the user by displaying your transaction confirmation page
const callback = (intentID) => {
   // handle callback
}
Initiate the Apple Pay payment experience, presenting the payment sheet to the user. Status will either be:
  1. Approved - payment was approved
  2. Declined - payment was declined
  3. Canceled - user canceled payment / didn’t happen
session.start(callback);
I