Apple Pay Hosted Checkout Initial Setup
Initial Setup
Contents
Prerequisites
Set up Apple Pay Merchant ID
Cardknox supports two solutions to help you set up your Apple Pay Merchant ID:
Set up Apple Pay Merchant ID through your Merchant Portal - A simple solution where Cardknox handles all communications with Apple and takes care of all certificates.
Set up Apple Pay Merchant ID using your own Apple account - in this case it will be your responsibility for mainlining account, domain and certificates up to date with Apple.
Implementing Apple Pay Hosted Checkout
Client-Side Integration
Adding Reference to iFields
Find the latest version of iFields at: https://cdn.cardknox.com/ifields/versions.htm
Step 1: Add the iFields.js file after the <head> tag on your payment page:
Adding JavaScript Objects for Apple Pay button
Step 1: Add the following JS snippet inside the <body> where the Apple Pay button is desired.
Step 2: Create JavaScript object that holds all of the properties/methods required to process Apple Pay.
For a full sample code please refer to Apple Pay iFields Integration
Step 3: Implement desired callbacks.
For the list of available callbacks, please refer to Apple Pay Object.
There are three main callbacks that must be implemented (the rest are optional):
onGetTransactionInfo - calculates the total amount based on the charge amount, fees, taxes, shipping costs, etc.
onValidateMerchant - a callback to be called to validate the Apple Pay Merchant.
onPaymentAuthorize - a callback that will be called after the consumer pays and Apple returns a token with all of the requested consumer information, like the billing address, shipping address, etc. This is where you need to make an ajax call to your server with the Apple Payload. The sample for making an ajax call is below.
Sample Code for Making Ajax Call:
For full sample code, please refer to Apple Pay iFields Integration
Step 4: Create JavaScript function that will initialize iFields.
initAP function above returns Request Object.
Enable Apple Pay
window.ckApplePay object - controls initialization of Apple Pay button
Method | Call Required | Description |
enableApplePay | Yes | Initializes and enables Apple Pay Button. Takes EnableApplePayParams object. |
updateAmount | Conditional | Updates amount on Apple Sheet. |
You can provide either All, One, or None of the parameters for enableApplePay call.
initFunction Required - either function name or function itself to initialize Apple Pay.
amountField Optional - if specified, the Apple Pay total amount will be automatically updated whenever the amount has changed.
amountField is not specified - in this case, it’s up to you to provide the correct amount for Apple Pay. One of the ways to do it is to call window.ckApplePay.updateAmount manually.
EnableApplePayParams Object
Name | Type | Required | Description |
initFunction | String|Object | Yes | Either function name or function itself to initialize Apple Pay |
amountField | String|Object | No | Field containing amount. Could be either the name of the field (String) or the field itself (Object) |
Server-Side Integration
Server Endpoint Creation
A server endpoint is needed in order to accept the Apple Payload from Hosted Checkout.
Step 1: Create an endpoint and method for API Integration on your server side that takes an object containing total transaction amount and Apple Payload and makes a call to Cardknox. Sample Object:
API Integration
This section assumes that you already know how to integrate other payments with Cardknox API
Below are the steps to integrate Apple Pay with the Cardknox API:
Once the consumer confirms the payment, Apple Pay API generates an Apple Payload in the form of a JSON string.
Integration Steps:
Extract the paymentData from the payload.
Encode it with Base64 encoding.
Set
xCardNum
field to the encoded value above.Set
xDigitalWalletType
to ApplePay.Set the remaining required fields:
xAmount
the Transaction Amount.xCommand
- Set to one of the values that starts with cc: like cc:sale, cc:auth, etc.xBillFirstName
xBillLastName
xBillStreet
xBillCity
xBillState
xBillZip
Sample Request:
For more details, please contact your Cardknox Representative.
Questions?
Contact support@cardknox.com
Last updated