ApplePay

ApplePay

This class represents an Apple Pay component. Instances of this class have methods for validating the merchant server and tokenizing payments.

Constructor

new ApplePay(options)

You cannot use this constructor directly. Use braintree.apple-pay.create instead.

Parameters:
Name Type Description
options object

Options

Source:

Methods

decoratePaymentRequest(paymentRequest) → {external:ApplePayPaymentRequest}

Merges a payment request with Braintree defaults The following properties are assigned to paymentRequest if not already defined

  • countryCode
  • currencyCode
  • merchantCapabilities
  • supportedNetworks
Parameters:
Name Type Description
paymentRequest external:ApplePayPaymentRequest

The payment request details to apply on top of those from Braintree.

Source:
Example
var applePay = require('braintree-web/apple-pay');

applePay.create({client: clientInstance}, function (createErr, applePayInstance) {
  // ...
  var paymentRequest = applePay.decoratePaymentRequest({
   total: {
     label: 'My Company',
     amount: '19.99'
  });

  console.log(paymentRequest);
  // { total: { }, countryCode: 'US', currencyCode: 'USD', merchantCapabilities: [ ], supportedNetworks: [ ] }

performValidation(options, callback) → {void}

Validates the merchant website, as required by ApplePaySession before payment can be authorized.

Parameters:
Name Type Description
options object

Options

Properties
Name Type Attributes Description
validationURL string

The validationURL fram an ApplePayValidateMerchantEvent.

displayName string <optional>
  • The canonical name for your store.
  • The system may display this name to the user.
  • Use a 128-character or less, UTF-8 string.
  • Do not localize the name.
merchantIdentifier string <optional>

Your Apple merchant identifier. This is the Apple Merchant ID created on the Apple Developer Portal. Defaults to the merchant identifier specified in the Braintree Control Panel. You can use this field to override the merchant identifier for this transaction.

callback callback

The second argument, data, is the Apple Pay merchant session object. Pass the merchant session to your Apple Pay session's completeMerchantValidation method.

Source:
Example
var applePay = require('braintree-web/apple-pay');

applePay.create({client: clientInstance}, function (createErr, applePayInstance) {
  var session = new ApplePaySession(1, {
    // This should be the payment request object that
    // contains the information needed to display the payment sheet.
  });

  session.onvalidatemerchant = function (event) {
    applePay.performValidation({
      validationURL: event.validationURL
    }, function(err, validationData) {
      if (err) {
        console.error(err);
        return;
      }
      session.completeMerchantValidation(validationData);
    });
  };
});

tokenize(options, callback) → {void}

Tokenizes an Apple Pay payment.

Parameters:
Name Type Description
options object

Options

Properties
Name Type Description
token object

The payment.token property of an external:ApplePayPaymentAuthorizedEvent

callback callback

The second argument, data, is the tokenized payload.

Source:
Example
var applePay = require('braintree-web/apple-pay');

applePay.create({client: clientInstance}, function (createErr, applePayInstance) {
  var session = new ApplePaySession(1, { });

  session.onpaymentauthorized = function (event) {
    applePay.tokenize({
      token: event.payment.token
    }, function (err, tokenizedPayload) {
      if (err) {
        session.completePayment(ApplePaySession.STATUS_FAILURE);
        return;
      }
      session.completePayment(ApplePaySession.STATUS_SUCCESS);

      // Send the tokenizedPayload to your server.
    });
 };
});