Welcome to Zuora Product Documentation

Explore our rich library of product information

Render the Apple Pay button

  1. 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.

  2. Initialize an instance of the Zuora object with your publishable key.
  3. Populate the configuration parameters and generate a payment session when the end customers click the Apple Pay button.

    The following table describes the parameters:

    ParameterTypeDescription
    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:

    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 merchantName field (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 merchantName and merchantInfo are 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:

    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:

  4. Mount the button component to the container.
  5. 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;
        }
    }