Apple Pay
Introduction
Apple Pay can be utilized as a checkout option on a payment page as well as a direct checkout option on the cart page (fast checkout). Loading the Apple Pay button via COPYandPAY payment widget is just like loading any other brand, i.e. in step 2, APPLEPAY must be specified as a brand. Once the Apple Pay button will be used by the consumer, the Apple Pay payment sheet will appear on the device.
As soon as the consumer starts to interact with the Apple Pay payment sheet, several events will be triggered. All events can be consumed by implementing the COPYandPAY API callback functions. All callback functions offered by the Apple Pay SDK are wrapped into the COPYandPAY API. No interaction with the Apple Pay SDK is required.
For steering the Apple Pay payment sheet or for updating data on the Apple Pay payment sheet after the consumer started to interact with it, several options are available.
Apple Pay on the payment page
Loading the Apple Pay button via COPYandPAY payment widget is just like loading any other brand, i.e. in step 2, APPLEPAY must be specified as a brand.
See an example below.
Note that the Apple Pay button only appears on compatible devices.
Todo Java Script
Apple Pay options
As with other options, you can modify the Apple Pay payment sheet behavior by usingwpwlOptions.applePay
. Parameter | Mandatory | Description | Default value | Examples |
---|---|---|---|---|
version | No | The Apple Pay Javascript API version. For the best compatibility, use the lowest possible version number that supports the features required. The versions which operating systems first support are listed below:
| 1 | version: 3 |
displayName | No | A string of 64 or fewer UTF-8 characters containing the canonical name for your store, suitable for display. Do not localize the name. The value is displayed in the Touch Bar on supported models of MacBook Pro. | N/A | displayName: “MyStore” |
total | Yes/No | An object representing the total for the payment. It can contain the following properties:
| amount:{checkout amount} type:final | total: { label: “COMPANY, INC.” } |
currencyCode | Yes/No | The three-letter ISO 4217 currency code for the payment. If not specified, the currency from the checkout is used. This parameter is required for the fast checkout. | {checkout currency} | currencyCode: “USD” |
checkAvailability | No | Specify the Apple Pay support detection method. The value must be one of the followings:
| canMakePayments | checkAvailability: “canMakePaymentsWithActiveCard” |
merchantIdentifier | Yes/No | The merchant ID created when the merchant enrolled in Apple Pay. This parameter is required when checkAvailability is “canMakePaymentsWithActiveCard” | N/A | merchantIdentifier: “com.company” |
style | No | The Apple Pay button style. The value must be one of the followings: “white-with-line”, “white”, “black”. | white-with-line | style: “black” |
countryCode | No | The merchant’s two-letter ISO 3166 country code. | wpwlOptions.locale | countryCode: “US” |
merchantCapabilities | No | The payment capabilities supported by the merchant. The supported values are:
If both or neither supportsCredit and supportsDebit values are supplied, the transaction allows both credit and debit cards. | supports3DS | merchantCapabilities: [“supports3DS”, “supportsCredit”] |
supportedNetworks | No | The payment networks supported by the merchant. The supported values are: “amex”, “cartesBancaires” (4), “chinaUnionPay”, “discover”, “eftpos” (4), “electron” (4), “elo” (5), “interac”, “jcb” (2), “mada” (5), “maestro” (4), “masterCard”, “privateLabel”, “visa”, “vPay” (4). Note that the numbers in the parentheses indicate the Apple Pay versions where they are first available, e.g. “jcb” is only available starting from version 2. The payment networks without numbers are available from version 1. | [“amex”, “discover”, “masterCard”, “visa”] | supportedNetworks: [“amex”, “chinaUnionPay”, “discover”, “jcb”, “masterCard”, “visa”] |
lineItems | No | An array of items explaining additional charges, discounts, and pending costs. Each item represents a line on the payment sheet. The item must contain:
Note that you should provide the total separately by using the total property. Also, the array cannot be empty, if present. | N/A | lineItems: [{ label: “Bag Subtotal”, amount: “35.00” }, { label: “Free Shipping”, amount: “0.00” }, { label: “Estimated Tax”, amount: “3.06” }] |
shippingMethods | No | An array of available methods for shipping physical goods. Each shipping method must contain:
| N/A | shippingMethods: [{ label: “Free Shipping”, amount: “0.00”, identifier: “free”, detail: “Delivers in five business days”, }, { label: “Express Shipping”, amount: “5.00”, identifier: “express”, detail: “Delivers in two business days”, }] |
shippingType | No | Indicate how purchased items are to be shipped. The value must be one of the followings: “shipping”, “delivery”, “storePickup”, “servicePickup”. | shipping | shippingType: “shipping” |
supportedCountries | No | An array that limits payment cards to those that were issued in specific countries. Indicate the supported countries by using ISO 3166 country codes. The supportedCountries list does not affect the currency used for the transaction, and it applies to all payment cards in Wallet. Available in Apple Pay JS API version 3. | N/A | supportedCountries: [“US”] |
requiredShippingContactFields | No | An array of shipping information that you require from the user to fulfill the order. The supported field names are: “email”, “name”, “phone”, “postalAddress”, and starting from version 3: “phoneticName”. | N/A | requiredShippingContactFields: [ “postalAddress”, “email” ] |
requiredBillingContactFields | No | An array of billing information that you require from the user to process the transaction. The supported field names are: “email”, “name”, “phone”, “postalAddress”, and starting from version 3: “phoneticName”. | N/A | requiredBillingContactFields: [ “postalAddress” ] |
submitOnPaymentAuthorized | No | Automatically submit customer information and billing address received from Apple Pay as a part of the transaction. Possible values are:
Note that this parameter must be used together with the parameter requiredBillingContactFields to request “email”, “name”, “phone”, and “postalAddress” from Apple Pay. | N/A | submitOnPaymentAuthorized: [ “customer”, “billing” ] |
Apple Pay callback functions
wpwlOptions.applePay
. Callback function | Description | Examples |
---|---|---|
onCancel | An event handler that is called when the Apple Pay payment sheet is dismissed. Note that this function can be called even after the onPaymentAuthorized event handler has been called. | onCancel: function () { } |
onPaymentMethodSelected | An event handler that is called when a new payment method is selected. The event parameter is an object that describes the selected Apple Pay payment card. The object contains:
| onPaymentMethodSelected: function (paymentMethod) { // Calculate new costs return { newTotal: { label: “Total”, amount: “42.00” }, newLineItems: [{ label: “Shipping”, amount: “2.00” }, { label: “Tax”, amount: “3.00” }] }; } |
onShippingContactSelected | An event handler that is called when a shipping contact is selected in the payment sheet. The event parameter is a redacted shipping contact. The redacted information includes only the necessary data for completing tasks such as calculating taxes or shipping costs. The information may differ based on the user’s geographic region. For Canada and United Kingdom, a redacted shipping address contains only the first three characters of the postal code. For US addresses, the redacted zip code contains the first five digits. The full postal code is provided after the user authorizes the transaction. See
| onShippingContactSelected: function (shippingContact) { // Calculate new costs return { newTotal: { label: “Total”, amount: “42.00” }, newLineItems: [{ label: “Shipping”, amount: “2.00” }, { label: “Tax”, amount: “3.00” }] }; } |
onShippingMethodSelected | An event handler that is called when a shipping method is selected in the payment sheet. The event parameter is an object that describes the selected shipping method for delivering physical goods. The object contains:
| onShippingMethodSelected: function (shippingMethod) { // Calculate new costs return { newTotal: { label: “Total”, amount: “42.00” }, newLineItems: [{ label: “Shipping”, amount: “2.00” }, { label: “Tax”, amount: “3.00” }] }; } |
onPaymentAuthorized | An event handler that is called when the user has authorized the Apple Pay payment with Touch ID, Face ID, or passcode. The event parameter contains: shippingContact and billingContact. For each object, the possible properties are:
| onPaymentAuthorized: function (payment) { //Save contacts from //payment.shippingContact //and //payment.billingContact } |
Promises
Your handler can return a promise if it needs to do an asynchronous work. It can be any thenable object. In particular, both JavaScript Promise and jQuery Promise are supported. For example, the total amount might have been changed because a different shipping method was selected. You will need to implementonPaymentAuthorized
, and use an ajax call to your server to do a server-to-server call to update the checkout amount. The function should return a promise, which once fulfilled, should signify that the call is completed.
Example: wpwlOptions.applePay.onPaymentAuthorized = function(payment) {
// Call your server to update the checkout
return $.post("https://your.server", {
amount: theNewAmount
}).then(function() {
return {
status: "SUCCESS"
};
});
};
Options and callback example
For example, you might want to offer several shipping options by usingapplePay.shippingMethods
, or calculate the tax when a shipping address is selected by using applePay.onShippingContactSelected
.
To quick start your integration, we recommend use our example code below as a guidance (Click js tab to see the code example). Todo Java Script
Errors
Your handlersonShippingContactSelected
and onPaymentAuthorized
can return an array of errors if there is something wrong with the given shippingContact or billingContact. Each error can point to a specific problem in a contact field. The object structure is as follows: Parameter | Description |
---|---|
code | Must be one of the followings:
|
contactField | Must be one of the followings: “phoneNumber”, “emailAddress”, “name”, “phoneticName”, “postalAddress”, “addressLines”, “locality”, “subLocality”, “postalCode”, “administrativeArea”, “subAdministrativeArea”, “country”, “countryCode”, if the code is “shippingContactInvalid” or “billingContactInvalid”. Otherwise, this field is optional. |
message | A localized, user-facing string that describes the error. |