apple-pay
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

ApplePay

Wrapper for working with Apple Pay payments

nodenpm version

npm downloadsnpm

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);
  }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    34
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    34
  • 1.0.1
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i apple-pay

Weekly Downloads

31

Version

1.0.2

License

MIT

Unpacked Size

10.4 kB

Total Files

9

Last publish

Collaborators

  • scrum