Skip to content

Latest commit

 

History

History
187 lines (142 loc) · 3.32 KB

PaymentRequest.md

File metadata and controls

187 lines (142 loc) · 3.32 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);

canMakePayments()

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

static canMakePaymentsUsingNetworks()

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

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