apple-pay
v1.0.2
Published
Wrapper for working with Apple Pay payments
Downloads
225
Readme
ApplePay
Wrapper for working with Apple Pay payments
Why ?
Simplifies interaction with native ApplePay API. Support:
- [x] Auto detect
supportsVersion
- [x] Filters unsupported
supportedNetworks
version based - [x] Static getter method
isPaymentAvailable
Install
npm i -S apple-pay
Note: This project is compatible with node v14+
Usage
import ApplePay, { STATUS_SUCCESS, STATUS_FAILURE } from 'apple-pay';
if (ApplePay.isPaymentAvailable) {
const paymentRequest = {
total: {
label: 'Merchant name',
amount: '10.0'
},
countryCode: 'US',
currencyCode: 'USD',
supportedCountries: ['US'],
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['amex', 'discover']
}
const session = new ApplePay({
onValidateMerchant,
onPaymentAuthorized,
paymentRequest
});
async function onValidateMerchant(event) {
const body = JSON.stringify({
validationURL: event.validationURL
});
const response = await fetch('you/validate/merchant/url', { body });
const json = await response.json();
session.completeMerchantValidation(json);
}
async function onPaymentAuthorized(event) {
const body = JSON.stringify({
paymentToken: event.payment.token
});
const response = await fetch('you/payment/authorized/url', { body });
const status = response.ok ? STATUS_SUCCESS : STATUS_FAILURE;
session.completePayment(status);
}
}