Render the Apple Pay button
- Copy the publishable key from Payment Form.
In the Zuora UI, click your username in the upper right and navigate to Settings > Payments > Payment Form. On the Publishable Keys tab, copy the key.
- Initialize an instance of the Zuora object with your publishable key.
- Populate the configuration parameters and generate a payment session when the end customers click the Apple Pay button.
The following table describes the parameters:
Parameter Type Description currencystring Required.
The ISO 4217 alphabetic currency code, such as "USD".
amountstring Required.
The total amount for the payment.
supportedNetworksarray Required.
The payment networks supported by your Apple Pay integration. Specify the values as an array of strings, such as ["visa", "masterCard", "amex", "discover"]
Before specifying this field, check the following information:
- The networks supported by your payment gateway integration. See the file:///Users/vmathews/Downloads/Zuora_Payments%202/Manage_payment_gateway_integrations_and_payment_methods/Set_up_payment_gateway_integrations.html specific to your payment gateway integration for details.
- The allowed values. See https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest/1916122-supportednetworks#discussion for details.
countryCodestring The ISO 3166-1 alpha-2 code of the country where the transaction is processed, such as "US".
If it is not specified, the default value US is used.
localestring The locale code, which is the combination of ISO language code and ISO country code, such as "en_US".
If it is not specified, the default value en_US is used.
merchantInfoobject Contains information about the merchant. You must specify the
merchantNamefield (string) within this object. The provided merchant name and Zuora's merchant ID will be used to render the Apple Pay button. There is no need to specify the merchant ID in this object, because Zuora's merchant ID is automatically applied.Example:
merchantInfo: { merchantName: "Example Merchant" }If
merchantNameandmerchantInfoare not specified, the information configured in the Public Business Information setting for Payment Link will be used. Ensure you have enabled the Payment Link feature. See the following articles for instructions:- Follow the instructions in https://knowledgecenter.zuora.com/Zuora_Payments/Process_payments/Payments_settings/Enable_payment_features_by_yourself to enable the Payment Link feature.
- Follow the instructions in https://knowledgecenter.zuora.com/Zuora_Payments/Process_payments/Payment_Forms_and_Payment_Links/Payment_Link/Y_Add_public_business_information_to_invoice_payment_page to configure the Public Business Information setting.
buttonTypestring Default: plain
A string that indicates the button type that you can display to initiate Apple Pay transactions. For details about allowed values, see the following articles in Apple’s documentation:
buttonStylestring Default: black
A string that indicates the supported appearance for an Apple Pay Button. For details about allowed values, see the following articles in Apple’s documentation:
buttonRadiusstring Default: 7px
The button corner radius in pixels, such as 10px.
buttonHeightstring The button height in pixels, such as 30px.
Note:The following parameters should not be specified when rendering the button:
- The https://developer.apple.com/documentation/apple_pay_on_the_web/applepaylineitem/1916085-label parameter required by Apple Pay is automatically populated with the value from the Business Name field of the https://knowledgecenter.zuora.com/Zuora_Payments/Process_payments/Payment_Forms_and_Payment_Links/Payment_Link/Y_Add_public_business_information_to_invoice_payment_page.
- The
accountIdparameter should not be specified when rendering the button. It can be specified when implementing the server-side API integration. - Specifying a gateway instance is not supported when rendering the button. You can do it when implementing the server-side API integration.
- Mount the button component to the container.
- Handle the payment result.
Here is an example of the code implementation:
<script> const publishableKey = "pk_rO0ABXenAF2s7QAF…"; const renderForm = () => { const zuora = Zuora(publishableKey); zuora.createApplePayButton({ currency: "USD", amount: "10.00", countryCode: "US", locale: "en_US", buttonType: "pay", buttonStyle: "white-outline", buttonRadius: "20px", buttonHeight: "50px", supportedNetworks: ["visa", "masterCard", "amex", "discover"], createPaymentSession: () => { return new Promise((resolve, reject) => { fetch("/sdk-test/payment-session.json?seed=" + Math.random(), { method: "GET", }).then((response) => { if (response.ok) { return response.json(); } else { return reject("Payment session request is rejected."); } }).then((data) => { return resolve(data.token); }).catch((error) => { return reject(error); }); }); }, onComplete: (result) => { console.log("=========="); console.log("Payment Result"); console.log("=========="); console.log(`transaction result: ${JSON.stringify(result)}`); alert(`transaction result: ${JSON.stringify(result)}`); } }).then(function(applePayButton) { applePayButton.mount("#payment-form-container") }).catch(function(error) { console.error(error); }); } function resultMessage(message) { const container = document.querySelector("#result-message"); container.innerHTML = message; } </script>The onComplete function returns result in the following structure:
On Success
{ success: true, paymentMethodId?: string; paymentId?: string; }On Error
{ success: false, error: { type: string; code: string; message: string; } }