Skip to content

Commit

Permalink
Allow specifying requiredShippingContactFields in Apple Pay
Browse files Browse the repository at this point in the history
User can (optionally) request additional fields from Apple Pay, such as
email, shipping address, etc, and process the responses on new emitters
from `onShippingContactSelected` and `onPaymentAuthorized`.
  • Loading branch information
emcro committed Aug 29, 2018
1 parent 7204a30 commit d4d50f7
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/recurly/apple-pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ApplePay extends Emitter {
supportedNetworks: this.config.supportedNetworks,
merchantCapabilities: this.config.merchantCapabilities,
requiredBillingContactFields: ['postalAddress'],
requiredShippingContactFields: this.config.requiredShippingContactFields,
total: this.totalLineItem
});

Expand Down Expand Up @@ -199,6 +200,7 @@ class ApplePay extends Emitter {

this.config.merchantCapabilities = info.merchantCapabilities || [];
this.config.supportedNetworks = info.supportedNetworks || [];
this.config.requiredShippingContactFields = options.requiredShippingContactFields || [];

this.emit('ready');
}
Expand Down Expand Up @@ -301,6 +303,9 @@ class ApplePay extends Emitter {
onShippingContactSelected (event) {
const status = this.session.STATUS_SUCCESS;
const newShippingMethods = [];

this.emit('shippingContactSelected', event);

this.session.completeShippingContactSelection(status, newShippingMethods, this.finalTotalLineItem, this.lineItems);
}

Expand Down Expand Up @@ -345,6 +350,7 @@ class ApplePay extends Emitter {
debug('Token received', token);

this.session.completePayment(this.session.STATUS_SUCCESS);
this.emit('authorized', event);
this.emit('token', token);
}
});
Expand Down

0 comments on commit d4d50f7

Please sign in to comment.