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.applePay.create instead.

Parameters:
Name Type Description
options object

Options

Source:

Members

merchantIdentifier

A special merchant ID which represents the merchant association with Braintree. Required when using ApplePaySession.canMakePaymentsWithActiveCard.

Source:
Example
var promise = ApplePaySession.canMakePaymentsWithActiveCard(applePayInstance.merchantIdentifier);
promise.then(function (canMakePaymentsWithActiveCard) {
  if (canMakePaymentsWithActiveCard) {
    // Set up Apple Pay buttons
  }
});

Methods

createPaymentRequest(paymentRequest) → {external:ApplePayPaymentRequest}

Merges a payment request with Braintree defaults to return an {external:ApplePayPaymentRequest}.

The following properties are assigned to paymentRequest if not already defined. Their default values come from the Braintree gateway.

  • 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 (applePayErr, applePayInstance) {
  if (applePayErr) {
    // Handle error here
    return;
  }

  var paymentRequest = applePayInstance.createPaymentRequest({
    total: {
      label: 'My Company',
      amount: '19.99'
    }
  });

  var session = new ApplePaySession(2, paymentRequest);

  // ...

performValidation(options, callbackopt) → {Promise|void}

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

Parameters:
Name Type Attributes Description
options object

Options

Properties
Name Type Description
validationURL string

The validationURL fram an ApplePayValidateMerchantEvent.

displayName string

The canonical name for your store. Use a non-localized name. This parameter should be a UTF-8 string that is a maximum of 128 characters. The system may display this name to the user.

callback callback <optional>

The second argument, data, is the Apple Pay merchant session object. If no callback is provided, performValidation returns a promise. 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 (applePayErr, applePayInstance) {
  if (applePayErr) {
    // Handle error here
    return;
  }

  var paymentRequest = applePayInstance.createPaymentRequest({
    total: {
      label: 'My Company',
      amount: '19.99'
    }
  });
  var session = new ApplePaySession(2, paymentRequest);

  session.onvalidatemerchant = function (event) {
    applePayInstance.performValidation({
      validationURL: event.validationURL,
      displayName: 'My Great Store'
    }, function (validationErr, validationData) {
      if (validationErr) {
        console.error(validationErr);
        session.abort();
        return;
      }

      session.completeMerchantValidation(validationData);
    });
  };
});

teardown(callbackopt) → {Promise|void}

Cleanly tear down anything set up by create.

Parameters:
Name Type Attributes Description
callback callback <optional>

Called once teardown is complete. No data is returned if teardown completes successfully.

Source:
Examples
applePayInstance.teardown();

With callback

applePayInstance.teardown(function () {
  // teardown is complete
});

tokenize(options, callbackopt) → {Promise|void}

Tokenizes an Apple Pay payment. This will likely be called in your ApplePaySession's onpaymentauthorized callback.

Parameters:
Name Type Attributes Description
options object

Options

Properties
Name Type Description
token object

The payment.token property of an external:ApplePayPaymentAuthorizedEvent.

callback callback <optional>

The second argument, data, is a tokenizePayload. If no callback is provided, tokenize returns a promise that resolves with a tokenizePayload.

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

applePay.create({client: clientInstance}, function (applePayErr, applePayInstance) {
  if (applePayErr) {
    // Handle error here
    return;
  }

  var paymentRequest = applePayInstance.createPaymentRequest({
    total: {
      label: 'My Company',
      amount: '19.99'
    }
  });
  var session = new ApplePaySession(2, paymentRequest);

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

      // Send the tokenizedPayload to your server here!
    });
  };

  // ...
});

Type Definitions

tokenizePayload :object

Properties:
Name Type Description
nonce string

The payment method nonce.

details object

Additional details.

Properties
Name Type Description
cardType string

Type of card, ex: Visa, MasterCard.

cardHolderName string

The name of the card holder.

dpanLastTwo string

Last two digits of card number.

description string

A human-readable description.

type string

The payment method type, always ApplePayCard.

binData object

Information about the card based on the bin.

Properties
Name Type Description
commercial string

Possible values: 'Yes', 'No', 'Unknown'.

countryOfIssuance string

The country of issuance.

debit string

Possible values: 'Yes', 'No', 'Unknown'.

durbinRegulated string

Possible values: 'Yes', 'No', 'Unknown'.

healthcare string

Possible values: 'Yes', 'No', 'Unknown'.

issuingBank string

The issuing bank.

payroll string

Possible values: 'Yes', 'No', 'Unknown'.

prepaid string

Possible values: 'Yes', 'No', 'Unknown'.

productId string

The product id.

Source: