LocalPayment

LocalPayment

This class represents a LocalPayment component. Instances of this class can open a LocalPayment window for paying with alternate payments local to a specific country. Any additional UI, such as disabling the page while authentication is taking place, is up to the developer.

Constructor

new LocalPayment(options)

Do not use this constructor directly. Use braintree-web.local-payment.create instead.

Parameters:
Name Type Description
options object

see local-payment.create

Source:

Members

teardown

Cleanly remove anything set up by create.

Source:
Examples
localPaymentInstance.teardown();

With callback

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

Methods

closeWindow() → {void}

Closes the LocalPayment window if it is open.

Source:
Example
localPaymentInstance.closeWindow();

focusWindow() → {void}

Focuses the LocalPayment window if it is open.

Source:
Example
localPaymentInstance.focusWindow();

hasTokenizationParams() → {Boolean}

Checks if required tokenizaiton parameters are available in querystring for manual toenization requests.

Source:
Example
// if query string contains
// ?btLpToken=token&btLpPaymentId=payment-id&btLpPayerId=payer-id
localPaymentInstance.hasTokenizationParams(); // true

// if query string is missing required params
localPaymentInstance.hasTokenizationParams(); // false

if (localPaymentInstance.hasTokenizationParams()) {
  localPaymentInstance.tokenize();
}

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

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

Parameters:
Name Type Attributes Description
options object

All options for initiating the local payment payment flow.

Properties
Name Type Description
fallback object

Configuration for what to do when app switching back from a Bank app on a mobile device.

Properties
Name Type Description
buttonText string

The text to insert into a button to redirect back to the merchant page.

url string

The url to redirect to when the redirect button is activated. Query params will be added to the url to process the data returned from the bank.

amount string

The amount to authorize for the transaction.

currencyCode string

The currency to process the payment.

paymentType string

The type of local payment.

email string

Payer email of the customer.

givenName string

First name of the customer.

surname string

Last name of the customer.

phone string

Phone number of the customer.

shippingAddressRequired boolean

Indicates whether or not the payment needs to be shipped. For digital goods, this should be false. Defaults to false.

address.streetAddress string

Line 1 of the Address (eg. number, street, etc). An error will occur if this address is not valid.

address.extendedAddress string

Line 2 of the Address (eg. suite, apt #, etc.). An error will occur if this address is not valid.

address.locality string

Customer's city.

address.region string

Customer's region or state.

address.postalCode string

Customer's postal code.

address.countryCode string

Customer's country code.

onPaymentStart function

A function that will be called with two parameters: an object containing the paymentId and a continueCallback that must be called to launch the flow. You can use method to do any preprocessing on your server before the flow begins..

callback callback <optional>

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

Source:
Example
button.addEventListener('click', function () {
  // Disable the button when local payment is in progress
  button.setAttribute('disabled', 'disabled');

  // Because startPayment opens a new window, this must be called
  // as a result of a user action, such as a button click.
  localPaymentInstance.startPayment({
    paymentType: 'ideal',
    fallback: {
      buttonText: 'Return to Merchant',
      url: 'https://example.com/my-checkout-page'
    },
    amount: '10.00',
    currencyCode: 'EUR',
    onPaymentStart: function (data, continueCallback) {
      // Do any preprocessing before starting the flow
      // data.paymentId is the ID of the localPayment
      continueCallback();
    }
  }).then(function (payload) {
    button.removeAttribute('disabled');
    // Submit payload.nonce to your server
  }).catch(function (startPaymentError) {
    button.removeAttribute('disabled');
    // Handle flow errors or premature flow closure
    console.error('Error!', startPaymentError);
  });
});

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

Manually tokenizes params for a local payment received from PayPal.When app switching back from a mobile application (such as a bank application for an iDEAL payment), the window may lose context with the parent page. In that case, a fallback url is used, and this method can be used to finish the flow.

Parameters:
Name Type Attributes Description
params object <optional>

All options for tokenizing local payment parameters. If no params are passed in, the params will be pulled off of the query string of the page.

Properties
Name Type Description
btLpToken string

The token representing the local payment. Aliased to token if btLpToken is not present.

btLpPaymentId string

The payment id for the local payment. Aliased to paymentId if btLpPaymentId is not present.

btLpPayerId string

The payer id for the local payment. Aliased to PayerID if btLpPayerId is not present.

callback callback <optional>

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

Source:
Example
localPaymentInstance.tokenize().then(function (payload) {
  // send payload.nonce to your server
}).catch(function (err) {
  // handle tokenization error
});