Initializes the payment request.
Arguments
- methodData -
Array<PaymentMethodData>
- details -
PaymentDetailsInit
- ?options -
PaymentOptions
Example
const METHOD_DATA = [
{
supportedMethods: ['apple-pay'],
data: {
merchantIdentifier: 'merchant.com.your-app.namespace',
supportedNetworks: ['visa', 'mastercard', 'amex'],
countryCode: 'US',
currencyCode: 'USD'
}
}
];
const DETAILS = {
id: 'demo',
displayItems: [
{
label: 'Movie Ticket',
amount: { currency: 'USD', value: '15.00' }
},
{
label: 'Shipping',
amount: { currency: 'USD', value: '0.00' }
}
],
total: {
label: 'Merchant Name',
amount: { currency: 'USD', value: '15.00' }
},
shippingOptions: [
{
id: 'economy',
label: 'Economy Shipping',
amount: { currency: 'USD', value: '0.00' },
detail: 'Arrives in 3-5 days',
selected: true
},
{
id: 'express',
label: 'Express Shipping',
amount: { currency: 'USD', value: '5.00' },
detail: 'Arrives tomorrow'
}
]
};
const OPTIONS = {
requestPayerName: true,
requestPayerPhone: true,
requestPayerEmail: true,
requestShipping: true
};
const paymentRequest = new PaymentRequest(METHOD_DATA, DETAILS, OPTIONS);
Determines if a payment request can be used to accept a payment based on the supported networks provided in the payment method data.
Example
paymentRequest.canMakePayments()
.then(canMakePayments => {
if (canMakePayments) {
return paymentRequest.show();
}
// Show fallback payment method
});
(IOS only) Determines if user has active cards in Apple pay that matches passed networks.
Arguments
- usingNetworks -
Array
Example
PaymentRequest
.canMakePaymentsUsingNetworks(['Visa', 'AmEx', 'MasterCard'])
.then(canMakePayments => {
if (canMakePayments) {
// do some stuff
}
});
(IOS Only) Takes the user to the wallet app to add a payment method.
Example
PaymentRequest.openPaymentSetup();
Displays the payment request to the user.
Example
paymentRequest
.show()
.then(paymentResponse => chargePaymentResponse(paymentResponse));
Dismisses the payment request.
Example
paymentRequest.abort();
Returns the payment requests's details.id
Example
console.log(paymentRequest.id); // demo
A payment request's shippingAddress
is populated when the user provides a shipping address. It is null
by default.
Example
console.log(paymentRequest.shippingAddress); // null
A payment request's shippingOption
is populated when the user chooses a shipping option. It is null
by default.
Example
console.log(paymentRequest.shippingOption); // economy