From d4d50f7b1e64604800afd04897671c74515dfdd7 Mon Sep 17 00:00:00 2001 From: Emmanuel Crouvisier Date: Wed, 29 Aug 2018 16:32:08 -0400 Subject: [PATCH] Allow specifying requiredShippingContactFields in Apple Pay 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`. --- lib/recurly/apple-pay.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/recurly/apple-pay.js b/lib/recurly/apple-pay.js index 08752cdc2..b4c4b3234 100644 --- a/lib/recurly/apple-pay.js +++ b/lib/recurly/apple-pay.js @@ -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 }); @@ -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'); } @@ -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); } @@ -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); } });