Constructor
new PaymentRequestComponent(options)
Do not use this constructor directly. Use braintree-web.payment-request.create instead.
Parameters:
Name | Type | Description |
---|---|---|
options |
object |
The Payment Request Component create options. |
Methods
canMakePayment(configuration, callbackopt) → {Promise|void}
Check if the customer can make payments.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
configuration |
object | ||
callback |
callback |
<optional> |
Called on completion. |
Example
var paymentDetails = {
total: {
label: 'Total',
amount: {
currency: 'USD',
value: '10.00',
}
}
};
paymentRequestInstance.canMakePayment({
details: paymentDetails
}).then(function (result) {
if (result) {
// set up payment request button
}
});
createSupportedPaymentMethodsConfiguration(type, overridesopt) → {object}
Create an object to pass into tokenize to specify a custom configuration. If no overrides are provided, the default configuration will be provided.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
string |
The supported payment method type. Possible values are |
|
overrides |
object |
<optional> |
The configuration overrides for the data property on the supported payment methods objects. If not passed in, the default configuration for the specified type will be provided. If a property is not provided, the value from the default configruation will be used. |
Examples
var configuration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard');
configuration.supportedMethods; // 'basic-card'
configuration.data.supportedNetworks; // ['visa', 'mastercard', 'amex'] <- whatever the supported card networks for the merchant account are
var configuration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard', {
supportedNetworks: ['visa'],
supportedTypes: ['credit', 'debit']
});
configuration.supportedMethods; // 'basic-card'
configuration.data.supportedNetworks; // ['visa']
configuration.data.supportedTypes; // ['credit', 'debit']
on(event, handler) → {void}
Subscribes a handler function to a named event. event
should be shippingAddressChange or shippingOptionChange. For convenience, you can also listen on shippingaddresschange
or shippingoptionchange
to match the event listeners in the Payment Request API documentation. Events will emit a shippingEventObject.
Parameters:
Name | Type | Description |
---|---|---|
event |
string |
The name of the event to which you are subscribing. |
handler |
function |
A callback to handle the event. |
Example
braintree.paymentRequest.create({ ... }, function (createErr, paymentRequestInstance) {
paymentRequestInstance.on('shippingAddressChange', function (event) {
console.log(event.target.shippingAddress);
});
});
teardown(callbackopt) → {Promise|void}
Cleanly remove anything set up by create.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
callback |
<optional> |
Called on completion. |
Examples
paymentRequestInstance.teardown();
paymentRequestInstance.teardown(function () {
// teardown is complete
});
tokenize(configuration, callbackopt) → {Promise|void}
Tokenizes a Payment Request
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
configuration |
object | ||
callback |
callback |
<optional> |
The second argument, |
Examples
paymentRequestInstance.tokenize({
details: {
total: {
label: 'Price',
amount: {
currency: 'USD',
value: '100.00'
}
}
}
}).then(function (payload) {
// send payload.nonce to server
// examine the raw response (with card details removed for security) from the payment request
console.log(payload.details.rawPaymentResponse);
}).catch(function (err) {
if (err.code === 'PAYMENT_REQUEST_CANCELED') {
// payment request was canceled by user
} else {
// an error occurred while processing
}
});
var basicCardConfiguration = paymentRequestInstance.createSupportedPaymentMethodsConfiguration('basicCard', {
supportedNetworks: ['visa']
};
paymentRequestInstance.tokenize({
supportedPaymentMethods: [basicCardConfiguration],
details: {
total: {
label: 'Price',
amount: {
currency: 'USD',
value: '100.00'
}
}
}
}).then(function (payload) {
// send payload.nonce to your server
});
paymentRequestInstance.tokenize({
details: {
total: {
label: 'Price',
amount: {
currency: 'USD',
value: '100.00'
}
}
},
options: {
requestPayerName: true,
requestPayerPhone: true,
requestPayerEmail: true
}
}).then(function (payload) {
// send payload.nonce to your server
// collect additional info from the raw response
console.log(payload.details.rawPaymentResponse);
});
var shippingOptions = [
{
id: 'economy',
label: 'Economy Shipping (5-7 Days)',
amount: {
currency: 'USD',
value: '0',
},
}, {
id: 'express',
label: 'Express Shipping (2-3 Days)',
amount: {
currency: 'USD',
value: '5',
},
}, {
id: 'next-day',
label: 'Next Day Delivery',
amount: {
currency: 'USD',
value: '12',
},
},
];
var paymentDetails = {
total: {
label: 'Total',
amount: {
currency: 'USD',
value: '10.00',
}
},
shippingOptions: shippingOptions
};
paymentRequestInstance.on('shippingAddressChange', function (event) {
// validate shipping address on event.target.shippingAddress
// make changes to the paymentDetails or shippingOptions if necessary
event.updateWith(paymentDetails)
});
paymentRequestInstance.on('shippingOptionChange', function (event) {
shippingOptions.forEach(function (option) {
option.selected = option.id === event.target.shippingOption;
});
event.updateWith(paymentDetails)
});
paymentRequestInstance.tokenize({
details: paymentDetails,
options: {
requestShipping: true
}
}).then(function (payload) {
// send payload.nonce to your server
// collect shipping information from payload
console.log(payload.details.rawPaymentResponse.shippingAddress);
});
Type Definitions
paymentRequestConfiguration :object
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
configuration.details |
object |
The payment details. For details on this object, see Google's PaymentRequest API documentation. |
|
configuration.supportedPaymentMethods |
array |
<optional> |
The supported payment methods. If not passed in, the supported payment methods from the merchant account that generated the authorization for the client will be used. For details on this array, see Google's PaymentRequest API documentation. |
configuration.options |
object |
<optional> |
Additional payment request options. For details on this object, see Google's PaymentRequest API documentation. |
shippingEventObject :object
The event payload sent from on.
Properties:
Name | Type | Description |
---|---|---|
target |
object |
An object which contains data about the event. |
updateWith |
function |
A method to call with the updated Payment Request details. |
tokenizePayload :object
Properties:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
nonce |
string |
The payment method nonce. |
||||||||||||||||||||||||||||||
details |
object |
Additional account details. Properties
|
||||||||||||||||||||||||||||||
description |
string |
A human-readable description. |
||||||||||||||||||||||||||||||
type |
string |
The payment method type, |
||||||||||||||||||||||||||||||
binData |
object |
Information about the card based on the bin. Properties
|
Events
shippingAddressChange :PaymentRequestComponent~shippingEventObject
This event is emitted when the customer selects a shipping address.
Example
braintree.paymentRequest.create({ ... }, function (createErr, paymentRequestInstance) {
paymentRequestInstance.on('shippingAddressChange', function (event) {
// validate event.target.shippingAddress if needed
event.updateWith(paymentRequestDetails);
});
});
shippingOptionChange :PaymentRequestComponent~shippingEventObject
This event is emitted when the customer selects a shipping option.
Example
braintree.paymentRequest.create({ ... }, function (createErr, paymentRequestInstance) {
paymentRequestInstance.on('shippingOptionChange', function (event) {
// validate event.target.shippingOption if needed
paymentRequestDetails.shippingOptions.forEach(function (option) {
option.selected = option.id === event.target.shippingOption;
});
event.updateWith(paymentRequestDetails);
});
});