if (window.PaymentRequest) {
// We're good to go...
} else {
// Alas! Use your traditional checkout form...
}
var methodData = [{
supportedMethods: ['basic-card']
}];
var details = {
total: {
label: 'Lovely socks',
amount: {currency: 'GBP', value: '12.00'}
}
};
// Show payment UI and handle result
new PaymentRequest(methodData, details)
.show()
.then(function(paymentResponse) {
// Process via gateway/processor, then...
paymentResponse.complete('success');
})
.catch(function(error) {
// Unable to complete, e.g. user cancelled
});
var details = {
displayItems: [
...
{
label: "Loyalty discount",
amount: { currency: "GBP", value : "-1.00" },
}
],
total: {
label: 'Total',
amount: {currency: 'GBP', value: '11.00'}
},
...
...
shippingOptions: [
{
id: 'standard',
label: 'Standard shipping',
amount: {currency: 'GBP', value: '1.50'},
selected: true
}
]
};
var options = {
requestPayerName: true,
requestPayerEmail: true,
requestPayerPhone: true,
requestShipping: true
};
new PaymentRequest(methodData, details, options)
...
Chrome for Android v53+
Samsung Internet v5.0+
Chrome desktop v61+
Edge v15+
Mozilla
Apple
paymentRequest.addEventListener('shippingaddresschange', function(event) {
// Say we check the address and we can offer these options:
event.updateWith({
shippingOptions: [
{
id: 'standard',
label: 'Standard Shipping (5-7 Days)',
amount: {value: '0', currency: 'GBP'}
}, {
id: 'express',
label: 'Express Shipping (2-3 Days)',
amount: {value: '3.50', currency: 'GBP'}
}
],
...
const paymentDetails = {
// Or if we can't offer any shipping to this address
shippingOptions: [],
...
};
event.updateWith(paymentDetails);
if (paymentRequest.canMakePayment) {
paymentRequest.canMakePayment().then(result => {
if (result) {
// User has an active payment method
} else {
// No active payment method yet, but user can add
}
}).catch(function(error) {
// Unable to determine
});
}
WePay.wallet.beginTokenization(...);
supportedMethods: ['https://android.com/pay'],
data: {
merchantName: 'Android Pay Demo',
// merchant ID obtained from Google that maps to your origin
merchantId: '01234567890123456789',
environment: 'TEST',
allowedCardNetworks: ['AMEX', 'DISCOVER', 'MASTERCARD', 'VISA'],
paymentMethodTokenizationParameters: {
tokenizationType: 'GATEWAY_TOKEN',
parameters: {
'gateway': 'stripe',
'stripe:publishableKey': 'xx_demo_xxxxxxxxxxxxxxxxxxxxxxxx',
'stripe:version': '2016-07-06',
}
}
}
request.show().then(function(result) {
// POST the result to server
return fetch('/pay', {
method: 'POST',
body: JSON.stringify(result.toJSON()),
...
})
// Then check response status & JSON &
// call result.complete() with 'success' / 'fail'
let method = [{
supportedMethods: ['https://apple.com/apple-pay'],
data: {
supportedNetworks: [
'amex', 'discover', 'masterCard', 'visa'
],
countryCode: 'US',
validationEndpoint: '/applepay/validate/',
merchantIdentifier: 'merchant.com.agektmr.payment'
}
}];
// With your service worker registration
return Promise.all([
registration.paymentManager.instruments.set(
"dc2de27a-ca5e-4fbd-883e-b6ded6c69d4f",
{
name: "Visa ending ****4756",
enabledMethods: ["basic-card"]
}),
registration.paymentManager.instruments.set(
"c8126178-3bba-4d09-8f00-0771bcfd3b11",
{
name: "My Bob Pay Account: john@example.com",
enabledMethods: ["https://bobpay.com/"]
})
]);
These slides are at
Further resources
Please leave us feedback on Meetup