Skip to content

Latest commit

 

History

History
143 lines (110 loc) · 2.49 KB

PaymentRequest.md

File metadata and controls

143 lines (110 loc) · 2.49 KB

PaymentRequest

constructor(methodData, details, ?options)

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

show()

Displays the payment request to the user.

Example
paymentRequest
  .show()
  .then(paymentResponse => chargePaymentResponse(paymentResponse));

abort()

Dismisses the payment request.

Example
paymentRequest.abort();

id

Returns the payment requests's details.id

Example
console.log(paymentRequest.id); // demo

shippingAddress

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

shippingOption

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