Masterpass

Masterpass

This class represents an Masterpass component. Instances of this class have methods for launching a new window to process a transaction with Masterpass.

Constructor

new Masterpass(options)

You cannot use this constructor directly. Use braintree.masterpass.create instead.

Parameters:
Name Type Description
options object

see masterpass.create

Source:

Methods

teardown(callbackopt) → {Promise|void}

Cleanly tear down anything set up by create.

Parameters:
Name Type Attributes Description
callback callback <optional>

Called on completion. If no callback is provided, teardown returns a promise.

Source:
Examples
masterpassInstance.teardown();

With callback

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

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

Launches the Masterpass flow and returns a nonce payload. Only one Masterpass flow should be active at a time. One way to achieve this is to disable your Masterpass button while the flow is open.

Braintree will apply these properties in options.config. Merchants should not override these values, except for advanced usage.

  • environment
  • requestToken
  • callbackUrl
  • merchantCheckoutId
  • allowedCardTypes
  • version
Parameters:
Name Type Attributes Description
options object

All options for initiating the Masterpass payment flow.

Properties
Name Type Attributes Description
currencyCode string

The currency code to process the payment.

subtotal string

The amount to authorize for the transaction.

config object <optional>

All configuration parameters accepted by Masterpass lightbox, except function data type. These options will override the values set by Braintree server. Please see https://developer.mastercard.com/page/masterpass-lightbox-parameters for more information.

frameOptions object <optional>

Used to configure the window that contains the Masterpass login.

Properties
Name Type Attributes Description
width number <optional>

Popup width to be used instead of default value (450px).

height number <optional>

Popup height to be used instead of default value (660px).

top number <optional>

The top position of the popup window to be used instead of default value, that is calculated based on provided height, and parent window size.

left number <optional>

The left position to the popup window to be used instead of default value, that is calculated baed on provided width, and parent window size.

callback callback <optional>

The second argument, data, is a tokenizePayload. If no callback is provided, the method will return a Promise that resolves with a tokenizePayload.

Source:
Example
button.addEventListener('click', function () {
  // Disable the button so that we don't attempt to open multiple popups.
  button.setAttribute('disabled', 'disabled');

  // Because tokenize opens a new window, this must be called
  // as a result of a user action, such as a button click.
  masterpassInstance.tokenize({
    currencyCode: 'USD',
    subtotal: '10.00'
  }).then(function (payload) {
    button.removeAttribute('disabled');
    // Submit payload.nonce to your server
  }).catch(function (tokenizeError) {
    button.removeAttribute('disabled');
    // Handle flow errors or premature flow closure

    switch (tokenizeErr.code) {
      case 'MASTERPASS_POPUP_CLOSED':
        console.error('Customer closed Masterpass popup.');
        break;
      case 'MASTERPASS_ACCOUNT_TOKENIZATION_FAILED':
        console.error('Masterpass tokenization failed. See details:', tokenizeErr.details);
        break;
      case 'MASTERPASS_FLOW_FAILED':
        console.error('Unable to initialize Masterpass flow. Are your options correct?', tokenizeErr.details);
        break;
      default:
        console.error('Error!', tokenizeErr);
    }
  });
});

Type Definitions

Address :object

Masterpass Address object.

Properties:
Name Type Description
countryCodeAlpha2 string

The customer's country code.

extendedAddress string

The customer's extended address.

locality string

The customer's locality.

postalCode string

The customer's postal code.

region string

The customer's region.

streetAddress string

The customer's street address.

Source:

tokenizePayload :object

Properties:
Name Type Description
nonce string

The payment method nonce.

description string

The human readable description.

type string

The payment method type, always MasterpassCard.

details object

Additional account details.

Properties
Name Type Description
cardType string

Type of card, ex: Visa, MasterCard.

lastFour string

Last four digits of card number.

lastTwo string

Last two digits of card number.

contact object

The customer's contact information.

Properties
Name Type Description
firstName string

The customer's first name.

lastName string

The customer's last name.

phoneNumber string

The customer's phone number.

emailAddress string

The customer's email address.

billingAddress Masterpass~Address

The customer's billing address.

shippingAddress Masterpass~Address

The customer's shipping address.

Source: