Constructor
new LocalPayment(options)
Do not use this constructor directly. Use braintree-web.local-payment.create instead.
Parameters:
Name | Type | Description |
---|---|---|
options |
object |
Methods
closeWindow() → {void}
Closes the LocalPayment window if it is open.
focusWindow() → {void}
Focuses the LocalPayment window if it is open.
hasTokenizationParams() → {Boolean}
Checks if required tokenization parameters are available in querystring for manual tokenization requests.
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, callback) → {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 | Description |
---|---|---|
options |
LocalPayment~StartPaymentOptions | LocalPayment~StartPaymentPayUponInvoiceOptions |
Options for initiating the local payment payment flow. |
callback |
callback |
The second argument, |
Examples
localPaymentInstance.startPayment({
paymentType: 'ideal',
paymentTypeCountryCode: 'NL',
fallback: {
buttonText: 'Return to Merchant',
url: 'https://example.com/my-checkout-page'
},
amount: '10.00',
currencyCode: 'EUR',
givenName: 'Joe',
surname: 'Doe',
address: {
countryCode: 'NL'
},
onPaymentStart: function (data, continueCallback) {
// Do any preprocessing before starting the flow
// data.paymentId is the ID of the localPayment
continueCallback();
}
}).then(function (payload) {
// Submit payload.nonce to your server
}).catch(function (startPaymentError) {
// Handle flow errors or premature flow closure
console.error('Error!', startPaymentError);
});
localPaymentInstance.startPayment({
paymentType: 'pay_upon_invoice',
amount: '100.00',
currencyCode: 'EUR',
givenName: 'Max',
surname: 'Mustermann',
address: { // This is used as the shipping address.
streetAddress: 'Taunusanlage 12',
locality: 'Frankfurt',
postalCode: '60325',
countryCode: 'DE',
},
billingAddress: {
streetAddress: 'Schönhauser Allee 84',
locality: 'Berlin',
postalCode: '10439',
countryCode: 'DE'
},
birthDate: '1990-01-01',
email: 'buyer@example.com',
locale: 'en-DE',
customerServiceInstructions: 'Customer service phone is +49 6912345678.',
lineItems: [{
category: 'PHYSICAL_GOODS',
name: 'Basketball Shoes',
quantity: '1',
unitAmount: '81.00',
unitTaxAmount: '19.00',
}],
phone: '6912345678',
phoneCountryCode: '49',
correlationId: correlationId,
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
localPaymentInstance.startPayment({
paymentType: 'blik',
paymentTypeCountryCode: 'PL',
amount: '10.00',
currencyCode: 'PLN',
givenName: 'Joe',
surname: 'Doe',
phone: '1234566789',
address: {
streetAddress: 'Mokotowska 1234',
locality: 'Warsaw',
postalCode: '02-697',
countryCode: 'PL',
},
blikOptions: {
level_0: {
authCode: "123456",
},
},
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
localPaymentInstance.startPayment({
paymentType: 'blik',
paymentTypeCountryCode: 'PL',
amount: '10.00',
currencyCode: 'PLN',
givenName: 'Joe',
surname: 'Doe',
phone: '1234566789',
address: {
streetAddress: 'Mokotowska 1234',
locality: 'Warsaw',
postalCode: '02-697',
countryCode: 'PL',
},
blikOptions: {
oneClick: {
authCode: "123456",
consumerReference: "ABCde123",
aliasLabel: "my uniq alias",
},
},
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
localPaymentInstance.startPayment({
paymentType: 'blik',
paymentTypeCountryCode: 'PL',
amount: '10.00',
currencyCode: 'PLN',
givenName: 'Joe',
surname: 'Doe',
phone: '1234566789',
address: {
streetAddress: 'Mokotowska 1234',
locality: 'Warsaw',
postalCode: '02-697',
countryCode: 'PL',
},
blikOptions: {
oneClick: {
consumerReference: "ABCde123",
aliasKey: "123456789",
},
},
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
localPaymentInstance.startPayment({
paymentType: 'mbway',
amount: '10.00',
currencyCode: 'EUR',
givenName: 'Joe',
surname: 'Doe',
phone: '1234566789',
phoneCountryCode: '351'
address: {
streetAddress: 'Rua Escura 12',
locality: 'Porto',
postalCode: '4465-283',
countryCode: 'PT',
},
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
localPaymentInstance.startPayment({
paymentType: 'bancomatpay',
amount: '10.00',
currencyCode: 'EUR',
givenName: 'Joe',
surname: 'Doe',
phone: '1234566789',
phoneCountryCode: '49'
address: {
streetAddress: 'Via del Corso 12',
locality: 'Roma',
postalCode: '00100',
countryCode: 'IT',
},
onPaymentStart: function (data) {
// NOTE: It is critical here to store data.paymentId on your server
// so it can be mapped to a webhook sent by Braintree once the
// buyer completes their payment.
console.log('Payment ID:', data.paymentId);
},
}).catch(function (err) {
// Handle any error calling startPayment.
console.error(err);
});
teardown(callbackopt) → {Promise|void}
Cleanly remove anything set up by create.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
callback |
<optional> |
Called on completion. |
Examples
localPaymentInstance.teardown();
localPaymentInstance.teardown(function () {
// teardown is complete
});
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
|
||||||||||||
callback |
callback |
<optional> |
The second argument, |
Example
localPaymentInstance.tokenize().then(function (payload) {
// send payload.nonce to your server
}).catch(function (err) {
// handle tokenization error
});
Type Definitions
StartPaymentOptions :object
Options used for most local payment types.
Properties:
Name | Type | Attributes | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fallback |
object |
Configuration for what to do when app switching back from a Bank app on a mobile device. Only applicable to the popup flow. Properties
|
||||||||||||||||||||||
windowOptions |
object |
<optional> |
The options for configuring the window that is opened when starting the payment. Only applicable to the popup flow. Properties
|
|||||||||||||||||||||
amount |
string |
The amount to authorize for the transaction. |
||||||||||||||||||||||
currencyCode |
string |
The currency to process the payment (three-character ISO-4217). |
||||||||||||||||||||||
displayName |
string |
<optional> |
The merchant name displayed inside of the window that is opened when starting the payment. |
|||||||||||||||||||||
paymentType |
string |
The type of local payment. See https://developer.paypal.com/braintree/docs/guides/local-payment-methods/client-side-custom |
||||||||||||||||||||||
paymentTypeCountryCode |
string |
The country code of the local payment. This value must be one of the supported country codes for a given local payment type listed here. For local payments supported in multiple countries, this value may determine which banks are presented to the customer. |
||||||||||||||||||||||
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. |
||||||||||||||||||||||
recurrent |
boolean |
Enable recurrent payment. |
||||||||||||||||||||||
customerId |
string |
The customer's id in merchant's system (required for recurrent payments). |
||||||||||||||||||||||
shippingAddressRequired |
boolean |
Indicates whether or not the payment needs to be shipped. For digital goods, this should be false. Defaults to false. |
||||||||||||||||||||||
address |
object |
The shipping address. Properties
|
||||||||||||||||||||||
onPaymentStart |
function |
A function that will be called with two parameters: an object containing the |
StartPaymentOptions :object
Options used for the seamless/oneclick BLIK local payment type.
Properties:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
amount |
string |
The amount to authorize for the transaction. |
|||||||||||||||||||||||||||||||
currencyCode |
string |
The currency to process the payment (three-character ISO-4217). |
|||||||||||||||||||||||||||||||
displayName |
string |
<optional> |
The merchant name displayed inside of the window that is opened when starting the payment. |
||||||||||||||||||||||||||||||
paymentType |
string |
The type of local payment. Must be |
|||||||||||||||||||||||||||||||
paymentTypeCountryCode |
string |
The country code of the local payment. This value must be one of the supported country codes for a given local payment type listed here. For local payments supported in multiple countries, this value may determine which banks are presented to the customer. |
|||||||||||||||||||||||||||||||
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 |
object |
The shipping address. Properties
|
|||||||||||||||||||||||||||||||
blikOptions |
object |
Blik seamless/oneclick specific options. Should contain only one object: Properties
|
|||||||||||||||||||||||||||||||
onPaymentStart |
function |
A function that will be called with an object containing the |
StartPaymentPayUponInvoiceOptions :object
Options used for the Pay Upon Invoice local payment type.
Properties:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
amount |
string |
The amount to authorize for the transaction. |
|||||||||||||||||||||||||||||
currencyCode |
string |
The currency to process the payment (three-character ISO-4217). |
|||||||||||||||||||||||||||||
displayName |
string |
<optional> |
The merchant name displayed inside of the window that is opened when starting the payment. |
||||||||||||||||||||||||||||
paymentType |
string |
The type of local payment. Must be |
|||||||||||||||||||||||||||||
paymentTypeCountryCode |
string |
<optional> |
The country code of the local payment. This value must be one of the supported country codes for a given local payment type listed here. For local payments supported in multiple countries, this value may determine which banks are presented to the customer. |
||||||||||||||||||||||||||||
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. |
|||||||||||||||||||||||||||||
phoneCountryCode |
string |
The country calling code. |
|||||||||||||||||||||||||||||
birthDate |
string |
The birth date of the customer in |
|||||||||||||||||||||||||||||
address |
object |
The shipping address. Properties
|
|||||||||||||||||||||||||||||
shippingAmount |
string |
<optional> |
The shipping fee for all items. This value can not be a negative number. |
||||||||||||||||||||||||||||
discountAmount |
string |
<optional> |
The discount for all items. This value can not be a negative number. |
||||||||||||||||||||||||||||
billingAddress |
object |
The billing address. Properties
|
|||||||||||||||||||||||||||||
lineItems |
Array.<object> |
List of line items. Properties
|
|||||||||||||||||||||||||||||
locale |
string |
The BCP 47-formatted locale. PayPal supports a five-character code. For example, |
|||||||||||||||||||||||||||||
customerServiceInstructions |
string |
Instructions for how to contact the merchant's customer service. Maximum 4,000 characters. |
|||||||||||||||||||||||||||||
correlationId |
string |
Used to correlate user sessions with server transactions. |
|||||||||||||||||||||||||||||
onPaymentStart |
function |
A function that will be called with an object containing the |