@paydock/client-sdk 1.10.60-beta → 1.10.74-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +146 -23
  2. package/bundles/widget.umd.js +760 -124
  3. package/bundles/widget.umd.min.js +1 -1
  4. package/lib/api/api-charge-internal.d.ts +52 -0
  5. package/lib/api/api-charge-internal.js +12 -1
  6. package/lib/api/api-charge-internal.js.map +1 -1
  7. package/lib/canvas-3ds/canvas-3ds.d.ts +17 -1
  8. package/lib/canvas-3ds/canvas-3ds.js +30 -4
  9. package/lib/canvas-3ds/canvas-3ds.js.map +1 -1
  10. package/lib/canvas-3ds/services/gpayments-service.d.ts +42 -0
  11. package/lib/canvas-3ds/services/gpayments-service.js +162 -0
  12. package/lib/canvas-3ds/services/gpayments-service.js.map +1 -0
  13. package/lib/canvas-3ds/services/index.d.ts +1 -0
  14. package/lib/canvas-3ds/services/index.js +2 -0
  15. package/lib/canvas-3ds/services/index.js.map +1 -0
  16. package/lib/canvas-3ds/services/standalone3ds-service.d.ts +21 -0
  17. package/lib/canvas-3ds/services/standalone3ds-service.js +32 -0
  18. package/lib/canvas-3ds/services/standalone3ds-service.js.map +1 -0
  19. package/lib/components/param.d.ts +20 -3
  20. package/lib/components/param.js +2 -0
  21. package/lib/components/param.js.map +1 -1
  22. package/lib/helper/access-token.d.ts +6 -0
  23. package/lib/helper/access-token.js +17 -0
  24. package/lib/helper/access-token.js.map +1 -1
  25. package/lib/wallet-buttons/apple.wallet-service.d.ts +13 -1
  26. package/lib/wallet-buttons/apple.wallet-service.js +67 -41
  27. package/lib/wallet-buttons/apple.wallet-service.js.map +1 -1
  28. package/lib/wallet-buttons/flypay.wallet-service.js +1 -4
  29. package/lib/wallet-buttons/flypay.wallet-service.js.map +1 -1
  30. package/lib/wallet-buttons/google.wallet-service.d.ts +29 -0
  31. package/lib/wallet-buttons/google.wallet-service.js +240 -0
  32. package/lib/wallet-buttons/google.wallet-service.js.map +1 -0
  33. package/lib/wallet-buttons/interfaces.d.ts +4 -1
  34. package/lib/wallet-buttons/mastercard.wallet-service.js +7 -1
  35. package/lib/wallet-buttons/mastercard.wallet-service.js.map +1 -1
  36. package/lib/wallet-buttons/paypal.wallet-service.js +3 -3
  37. package/lib/wallet-buttons/paypal.wallet-service.js.map +1 -1
  38. package/lib/wallet-buttons/stripe.wallet-service.d.ts +1 -0
  39. package/lib/wallet-buttons/stripe.wallet-service.js +9 -3
  40. package/lib/wallet-buttons/stripe.wallet-service.js.map +1 -1
  41. package/lib/wallet-buttons/wallet-buttons.d.ts +44 -13
  42. package/lib/wallet-buttons/wallet-buttons.js +37 -12
  43. package/lib/wallet-buttons/wallet-buttons.js.map +1 -1
  44. package/lib/wallet-buttons/wallet-service.d.ts +2 -1
  45. package/lib/wallet-buttons/wallet-service.js.map +1 -1
  46. package/lib/widget/configuration.d.ts +3 -3
  47. package/lib/widget/configuration.js +8 -7
  48. package/lib/widget/configuration.js.map +1 -1
  49. package/lib/widget/multi-widget.d.ts +10 -10
  50. package/lib/widget/multi-widget.js +15 -9
  51. package/lib/widget/multi-widget.js.map +1 -1
  52. package/package.json +2 -1
  53. package/slate.md +83 -0
@@ -150,6 +150,76 @@
150
150
  };
151
151
  }();
152
152
 
153
+ var toConsumableArray = function (arr) {
154
+ if (Array.isArray(arr)) {
155
+ for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
156
+
157
+ return arr2;
158
+ } else {
159
+ return Array.from(arr);
160
+ }
161
+ };
162
+
163
+ var ACCESS_HEADER_NAME = {
164
+ accessToken: 'x-access-token',
165
+ publicKey: 'x-user-public-key'
166
+ };
167
+ var AccessToken = function () {
168
+ function AccessToken() {
169
+ classCallCheck(this, AccessToken);
170
+ }
171
+
172
+ createClass(AccessToken, null, [{
173
+ key: 'validateJWT',
174
+ value: function validateJWT(jwt) {
175
+ if (!jwt) return null;
176
+
177
+ var _jwt$split = jwt.split("."),
178
+ _jwt$split2 = slicedToArray(_jwt$split, 3),
179
+ rawHead = _jwt$split2[0],
180
+ rawBody = _jwt$split2[1],
181
+ signature = _jwt$split2[2];
182
+
183
+ if (!rawHead || !rawBody || !signature) return null;
184
+ if (2 + rawHead.length + rawBody.length + signature.length !== jwt.length) return null;
185
+ try {
186
+ var head = JSON.parse(atob(rawHead));
187
+ var body = JSON.parse(atob(rawBody));
188
+ return { head: head, body: body, signature: signature };
189
+ } catch (_a) {
190
+ return null;
191
+ }
192
+ }
193
+ }, {
194
+ key: 'extractData',
195
+ value: function extractData(body) {
196
+ try {
197
+ return JSON.parse(atob(body.meta));
198
+ } catch (_a) {
199
+ return null;
200
+ }
201
+ }
202
+ }, {
203
+ key: 'extractMeta',
204
+ value: function extractMeta(body) {
205
+ try {
206
+ var _JSON$parse = JSON.parse(atob(body.meta)),
207
+ meta = _JSON$parse.meta;
208
+
209
+ return meta;
210
+ } catch (_a) {
211
+ return null;
212
+ }
213
+ }
214
+ }, {
215
+ key: 'getAccessHeaderNameByToken',
216
+ value: function getAccessHeaderNameByToken(token) {
217
+ return !!AccessToken.validateJWT(token) ? ACCESS_HEADER_NAME.accessToken : ACCESS_HEADER_NAME.publicKey;
218
+ }
219
+ }]);
220
+ return AccessToken;
221
+ }();
222
+
153
223
  var ENV = {
154
224
  SANDBOX: 'sandbox',
155
225
  SANDBOX_KOVENA: 'sandbox-kovena',
@@ -437,6 +507,8 @@
437
507
  (function (WALLET_TYPE) {
438
508
  WALLET_TYPE["GOOGLE"] = "google";
439
509
  WALLET_TYPE["APPLE"] = "apple";
510
+ WALLET_TYPE["FLYPAY"] = "flypay";
511
+ WALLET_TYPE["PAYPAL"] = "paypal";
440
512
  })(WALLET_TYPE || (WALLET_TYPE = {}));
441
513
 
442
514
  /**
@@ -629,28 +701,28 @@
629
701
  * console.log(error);
630
702
  * });
631
703
  *
632
- * @param {string} publicKey - Customer public key which provided for each client
704
+ * @param {string} accessToken - Customer access token or public key which provided for each client
633
705
  * @param {createToken~requestCallback} cb - The callback that handles the success response.
634
706
  * @param {createToken~requestCallback} errorCb - The callback that handles the failed response.
635
707
  */
636
708
 
637
709
  }, {
638
710
  key: 'createToken',
639
- value: function createToken(publicKey, cb) {
711
+ value: function createToken(accessToken, cb) {
640
712
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
641
713
 
642
- this.send(publicKey, function (data, status) {
714
+ this.send(accessToken, function (data, status) {
643
715
  if (status >= 200 && status < 300) return cb(data.resource.data.configuration_token);
644
716
  if (typeof data.error === "undefined" || typeof data.error.message === "undefined") errorCb('unknown error');else errorCb(data.error.message);
645
717
  });
646
718
  }
647
719
  }, {
648
720
  key: 'send',
649
- value: function send(publicKey, cb) {
721
+ value: function send(accessToken, cb) {
650
722
  var request = new XMLHttpRequest();
651
723
  request.open('POST', this.getUrl(), true);
652
724
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
653
- request.setRequestHeader('x-user-public-key', publicKey);
725
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
654
726
  request.send(JSON.stringify(this.getConfigs()));
655
727
  request.onload = function () {
656
728
  var res = {};
@@ -672,7 +744,7 @@
672
744
  }
673
745
  }], [{
674
746
  key: 'createEachToken',
675
- value: function createEachToken(publicKey, configs, cb) {
747
+ value: function createEachToken(accessToken, configs, cb) {
676
748
  var errorCb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function (errors) {};
677
749
 
678
750
  var tokens = new Array(configs.length);
@@ -680,7 +752,7 @@
680
752
  var counter = 0;
681
753
 
682
754
  var _loop = function _loop(index) {
683
- if (configs.hasOwnProperty(index)) configs[index].createToken(publicKey, function (token) {
755
+ if (configs.hasOwnProperty(index)) configs[index].createToken(accessToken, function (token) {
684
756
  tokens[index] = token;
685
757
  counter++;
686
758
  if (configs.length === counter) Configuration.finishCreatingEachToken(tokens, errors, cb, errorCb);
@@ -897,30 +969,34 @@
897
969
  * Class MultiWidget include method for for creating iframe url
898
970
  * @constructor
899
971
  *
900
- * @param {string} publicKey - PayDock users public key
972
+ * @param {string} accessToken - PayDock users access token or public key
901
973
  * @param {(Configuration | string | Configuration[] | string[])} conf - exemplar[s] Configuration class OR configuration token
902
974
  *
903
975
  * @example
904
- * var widget = new MultiWidget('publicKey','configurationToken'); // With a pre-created configuration token
976
+ * var widget = new MultiWidget('accessToken','configurationToken'); // With a pre-created configuration token
905
977
  *
906
- * var widget = new MultiWidget('publicKey',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
978
+ * var widget = new MultiWidget('accessToken',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
907
979
  *
908
- * var widget = new MultiWidget('publicKey', new Configuration('gatewayId')); With Configuration
980
+ * var widget = new MultiWidget('accessToken', new Configuration('gatewayId')); With Configuration
909
981
  *
910
- * var widget = new MultiWidget('publicKey',[ With Configurations
982
+ * var widget = new MultiWidget('accessToken',[ With Configurations
911
983
  * Configuration('gatewayId'),
912
984
  * Configuration('gatewayId', 'bank_account')
913
985
  * ]);
914
986
  **/
915
987
  var MultiWidget = function () {
916
- function MultiWidget(publicKey, conf) {
988
+ function MultiWidget(accessToken, conf) {
917
989
  classCallCheck(this, MultiWidget);
918
990
 
919
991
  this.configs = [];
920
992
  this.configTokens = [];
921
993
  this.link = new Link(WIDGET_LINK);
922
- this.link.setParams({ public_key: publicKey });
923
- this.publicKey = publicKey;
994
+ if (!!AccessToken.validateJWT(accessToken)) {
995
+ this.link.setParams({ token: accessToken });
996
+ } else {
997
+ this.link.setParams({ public_key: accessToken });
998
+ }
999
+ this.accessToken = accessToken;
924
1000
  if (!conf || Array.isArray(conf) && !conf.length) throw Error('configuration token is required');
925
1001
  if (typeof conf === 'string') this.configTokens.push(conf);else if (conf instanceof Configuration) this.configs.push(conf);else if (Array.isArray(conf) && typeof conf[0] === 'string') this.configTokens = conf;else if (Array.isArray(conf) && conf[0] instanceof Configuration) this.configs = conf;else throw Error('Unsupported type of configuration token');
926
1002
  }
@@ -1295,7 +1371,7 @@
1295
1371
  this.link.setParams({ configuration_tokens: this.configTokens.join(',') });
1296
1372
  return cb(this.link.getUrl());
1297
1373
  }
1298
- Configuration.createEachToken(this.publicKey, this.configs, function (tokens) {
1374
+ Configuration.createEachToken(this.accessToken, this.configs, function (tokens) {
1299
1375
  _this2.link.concatParams({ configuration_tokens: tokens.join(',') });
1300
1376
  return cb(_this2.link.getUrl());
1301
1377
  }, function (errors) {
@@ -5043,10 +5119,7 @@
5043
5119
  var _this3 = this;
5044
5120
 
5045
5121
  this.event.on(FLYPAY_EVENT.UNAVAILABLE, widgetId, function (_data) {
5046
- return _this3.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, {
5047
- event: WALLET_EVENT.UNAVAILABLE,
5048
- data: null
5049
- });
5122
+ return _this3.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, null);
5050
5123
  });
5051
5124
  this.event.on(FLYPAY_EVENT.START_LOADING, widgetId, function (_data) {
5052
5125
  return _this3.background.initControl();
@@ -5131,7 +5204,7 @@
5131
5204
 
5132
5205
  if (!window.Promise) {
5133
5206
  // Given that this library does not rely in any polyfill for promises, and this integration depends on them, we early return if Promises are not supported for the browser (like I.E. 11).
5134
- this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { event: WALLET_EVENT.UNAVAILABLE, data: null });
5207
+ this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, null);
5135
5208
  return;
5136
5209
  }
5137
5210
  var buttonId = container.getElement().id || '';
@@ -5178,7 +5251,7 @@
5178
5251
  // We're already handling errors and notifying Merchants at "wallet-buttons.ts"
5179
5252
  } })).render("#" + buttonId);
5180
5253
  } else {
5181
- _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { event: WALLET_EVENT.UNAVAILABLE, data: null });
5254
+ _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, null);
5182
5255
  }
5183
5256
  };
5184
5257
  document.head.appendChild(paypalScript);
@@ -5220,7 +5293,7 @@
5220
5293
  label: data.selected_shipping_option.label,
5221
5294
  amount: data.selected_shipping_option.amount.value,
5222
5295
  currency: data.selected_shipping_option.amount.currency_code,
5223
- type: ((_a = data.selected_shipping_option) === null || _a === void 0 ? void 0 : _a.type) || ''
5296
+ type: (_a = data.selected_shipping_option) === null || _a === void 0 ? void 0 : _a.type
5224
5297
  }
5225
5298
  });
5226
5299
  }
@@ -5468,7 +5541,7 @@
5468
5541
  }, {
5469
5542
  key: "mount",
5470
5543
  value: function mount(container, availability) {
5471
- if (!availability || !availability.apple_pay && !availability.google_pay) return this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { event: WALLET_EVENT.UNAVAILABLE, data: null });
5544
+ if (!availability || !availability.apple_pay && !availability.google_pay) return this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, null);
5472
5545
  this.createWalletButton().mount(container.getElement());
5473
5546
  }
5474
5547
  }, {
@@ -5477,7 +5550,7 @@
5477
5550
  var _this4 = this;
5478
5551
 
5479
5552
  this.paymentRequest.on("paymentmethod", function (event) {
5480
- var _a;
5553
+ var _a, _b;
5481
5554
  var _event$paymentMethod = event.paymentMethod,
5482
5555
  id = _event$paymentMethod.id,
5483
5556
  card = _event$paymentMethod.card,
@@ -5492,8 +5565,9 @@
5492
5565
  payer_email: event.payerEmail,
5493
5566
  payer_phone: event.payerPhone,
5494
5567
  payment_source: {
5568
+ wallet_type: _this4.getWalletType((_a = card === null || card === void 0 ? void 0 : card.wallet) === null || _a === void 0 ? void 0 : _a.type),
5495
5569
  card_name: name,
5496
- type: (_a = card === null || card === void 0 ? void 0 : card.wallet) === null || _a === void 0 ? void 0 : _a.type,
5570
+ type: (_b = card === null || card === void 0 ? void 0 : card.wallet) === null || _b === void 0 ? void 0 : _b.type,
5497
5571
  card_scheme: card === null || card === void 0 ? void 0 : card.brand,
5498
5572
  card_number_last4: card === null || card === void 0 ? void 0 : card.last4,
5499
5573
  expire_month: card === null || card === void 0 ? void 0 : card.exp_month,
@@ -5518,6 +5592,12 @@
5518
5592
  });
5519
5593
  });
5520
5594
  }
5595
+ }, {
5596
+ key: "getWalletType",
5597
+ value: function getWalletType(type) {
5598
+ if (!type) return null;
5599
+ return type === 'google_pay' ? WALLET_TYPE.GOOGLE : WALLET_TYPE.APPLE;
5600
+ }
5521
5601
  }]);
5522
5602
  return StripeWalletService;
5523
5603
  }(WalletService);
@@ -5532,6 +5612,7 @@
5532
5612
 
5533
5613
  _this.gatewayName = gatewayName;
5534
5614
  _this.eventEmitter = eventEmitter;
5615
+ _this.latestShippingData = {};
5535
5616
  _this.onValidateMerchant = function (event) {
5536
5617
  _this.getMerchantSession().then(function (merchantSession) {
5537
5618
  _this.paymentSession.completeMerchantValidation(merchantSession);
@@ -5540,14 +5621,18 @@
5540
5621
  });
5541
5622
  };
5542
5623
  _this.onPaymentAuthorized = function (event) {
5624
+ var _a;
5543
5625
  var _event$payment = event.payment,
5544
5626
  token = _event$payment.token,
5545
5627
  billingContact = _event$payment.billingContact,
5546
5628
  shippingContact = _event$payment.shippingContact;
5547
5629
 
5630
+ _this.latestShippingData.shippingContact = shippingContact;
5631
+ var shippingOptionMethod = (_a = _this.selectedShippingOption) === null || _a === void 0 ? void 0 : _a.type;
5548
5632
  _this.eventEmitter.emit(WALLET_EVENT.PAYMENT_METHOD_SELECTED, {
5549
5633
  data: _extends({ customer: {
5550
5634
  payment_source: {
5635
+ wallet_type: WALLET_TYPE.APPLE,
5551
5636
  card_name: token.paymentMethod.displayName,
5552
5637
  type: token.paymentMethod.type,
5553
5638
  card_scheme: token.paymentMethod.network,
@@ -5560,22 +5645,12 @@
5560
5645
  ref_token: token.paymentData ? JSON.stringify(token.paymentData) : ''
5561
5646
  }
5562
5647
  } }, _this.meta.request_shipping && shippingContact && {
5563
- shipping: {
5564
- method: _this.selectedShippingMethodId,
5565
- options: _this.meta.shipping_options,
5566
- address_line1: shippingContact.addressLines[0],
5567
- address_line2: shippingContact.addressLines[1],
5568
- address_country: shippingContact.countryCode,
5569
- address_city: shippingContact.locality,
5570
- address_postcode: shippingContact.postalCode,
5571
- address_state: shippingContact.administrativeArea,
5572
- contact: {
5648
+ shipping: _extends(_extends(_extends({}, shippingOptionMethod && { method: shippingOptionMethod }), _this.hasShippingOptions() && { options: _this.meta.shipping_options }), { address_line1: shippingContact.addressLines[0], address_line2: shippingContact.addressLines[1], address_country: shippingContact.countryCode, address_city: shippingContact.locality, address_postcode: shippingContact.postalCode, address_state: shippingContact.administrativeArea, contact: {
5573
5649
  first_name: shippingContact.givenName,
5574
5650
  last_name: shippingContact.familyName,
5575
5651
  email: shippingContact.emailAddress,
5576
5652
  phone: shippingContact.phoneNumber
5577
- }
5578
- }
5653
+ } })
5579
5654
  }),
5580
5655
  onSuccess: function onSuccess() {
5581
5656
  return _this.paymentSession.completePayment(ApplePaySession.STATUS_SUCCESS);
@@ -5586,19 +5661,16 @@
5586
5661
  });
5587
5662
  };
5588
5663
  _this.onShippingContactSelected = function (event) {
5589
- var parsedCallbackData = _this.parseUpdateData(event.shippingContact);
5664
+ _this.latestShippingData.shippingContact = event.shippingContact;
5665
+ var parsedCallbackData = _this.parseUpdateData(_this.latestShippingData);
5590
5666
  _this.eventEmitter.emit(WALLET_EVENT.UPDATE, parsedCallbackData);
5591
- var update = _extends({ newTotal: {
5592
- label: _this.meta.amount_label,
5593
- amount: _this.meta.amount.toString(),
5594
- type: "final"
5595
- } }, _this.meta.request_shipping && _this.meta.shipping_options && {
5596
- newShippingMethods: _this.formatShippingOptions(_this.meta.shipping_options)
5667
+ return new Promise(function (res, rej) {
5668
+ _this.latestShippingChangePromiseResolve = res;
5669
+ _this.latestShippingChangePromiseReject = rej;
5597
5670
  });
5598
- _this.paymentSession.completeShippingContactSelection(update);
5599
5671
  };
5600
5672
  _this.onShippingMethodSelected = function (event) {
5601
- _this.selectedShippingMethodId = event.shippingMethod.identifier;
5673
+ _this.latestShippingData.shippingMethod = event.shippingMethod;
5602
5674
  var update = {
5603
5675
  newTotal: {
5604
5676
  label: _this.meta.amount_label,
@@ -5609,16 +5681,22 @@
5609
5681
  _this.paymentSession.completeShippingMethodSelection(update);
5610
5682
  };
5611
5683
  _this.parseUpdateData = function (data) {
5684
+ var _a, _b, _c, _d, _e, _f, _g, _h;
5612
5685
  // From Apple docs (https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypayment/1916097-shippingcontact):
5613
5686
  // Before the user authorizes the transaction with Touch ID, Face ID, or passcode, you receive redacted address information
5614
- return {
5615
- shipping: {
5616
- address_city: data.locality,
5617
- address_state: data.administrativeArea,
5618
- address_postcode: data.postalCode,
5619
- address_country: data.countryCode
5687
+ return _extends({ shipping: {
5688
+ address_city: (_a = data === null || data === void 0 ? void 0 : data.shippingContact) === null || _a === void 0 ? void 0 : _a.locality,
5689
+ address_state: (_b = data === null || data === void 0 ? void 0 : data.shippingContact) === null || _b === void 0 ? void 0 : _b.administrativeArea,
5690
+ address_postcode: (_c = data === null || data === void 0 ? void 0 : data.shippingContact) === null || _c === void 0 ? void 0 : _c.postalCode,
5691
+ address_country: (_d = data === null || data === void 0 ? void 0 : data.shippingContact) === null || _d === void 0 ? void 0 : _d.countryCode
5692
+ } }, (data === null || data === void 0 ? void 0 : data.shippingMethod) && {
5693
+ selected_shipping_option: {
5694
+ id: (_e = data === null || data === void 0 ? void 0 : data.shippingMethod) === null || _e === void 0 ? void 0 : _e.identifier,
5695
+ label: (_f = data === null || data === void 0 ? void 0 : data.shippingMethod) === null || _f === void 0 ? void 0 : _f.label,
5696
+ detail: (_g = data === null || data === void 0 ? void 0 : data.shippingMethod) === null || _g === void 0 ? void 0 : _g.detail,
5697
+ amount: (_h = data === null || data === void 0 ? void 0 : data.shippingMethod) === null || _h === void 0 ? void 0 : _h.amount
5620
5698
  }
5621
- };
5699
+ });
5622
5700
  };
5623
5701
  _this.formatShippingOptions = function (shipping_options) {
5624
5702
  return shipping_options.map(function (o) {
@@ -5645,6 +5723,18 @@
5645
5723
  var _a, _b, _c;
5646
5724
  return ((_c = (_b = (_a = this.meta) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b[WALLET_TYPE.APPLE]) === null || _c === void 0 ? void 0 : _c.merchant) || '';
5647
5725
  }
5726
+ }, {
5727
+ key: "isShippingRequired",
5728
+ value: function isShippingRequired() {
5729
+ var _a;
5730
+ return (_a = this.meta) === null || _a === void 0 ? void 0 : _a.request_shipping;
5731
+ }
5732
+ }, {
5733
+ key: "hasShippingOptions",
5734
+ value: function hasShippingOptions() {
5735
+ var _a, _b;
5736
+ return ((_a = this.meta) === null || _a === void 0 ? void 0 : _a.request_shipping) && !!((_b = this.meta) === null || _b === void 0 ? void 0 : _b.shipping_options);
5737
+ }
5648
5738
  }, {
5649
5739
  key: "load",
5650
5740
  value: function load(container) {
@@ -5652,17 +5742,20 @@
5652
5742
 
5653
5743
  if (!window.Promise) {
5654
5744
  // Given that this library does not rely in any polyfill for promises, and this integration depends on them, we early return if Promises are not supported for the browser (like I.E. 11).
5655
- this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { event: WALLET_EVENT.UNAVAILABLE, data: { wallet: WALLET_TYPE.APPLE } });
5745
+ this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { wallet: WALLET_TYPE.APPLE });
5656
5746
  return;
5657
5747
  }
5658
5748
  return this.checkAvailability().then(function (available) {
5659
5749
  var _a;
5660
5750
  if (!available) {
5661
- _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { event: WALLET_EVENT.UNAVAILABLE, data: { wallet: WALLET_TYPE.APPLE } });
5751
+ _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { wallet: WALLET_TYPE.APPLE });
5662
5752
  return;
5663
5753
  }
5664
5754
  // Store default shipping option
5665
- if (_this2.meta.request_shipping && _this2.meta.shipping_options) _this2.selectedShippingMethodId = (_a = _this2.meta.shipping_options[0]) === null || _a === void 0 ? void 0 : _a.id;
5755
+ if (_this2.isShippingRequired() && _this2.hasShippingOptions()) {
5756
+ _this2.selectedShippingOption = (_a = _this2.meta) === null || _a === void 0 ? void 0 : _a.shipping_options[0];
5757
+ _this2.latestShippingData.shippingMethod = _this2.formatShippingOptions([_this2.selectedShippingOption])[0];
5758
+ }
5666
5759
  _this2.mount(container);
5667
5760
  }).catch(function (err) {
5668
5761
  return console.error("Error checking ApplePay availability", err);
@@ -5671,9 +5764,25 @@
5671
5764
  }, {
5672
5765
  key: "update",
5673
5766
  value: function update(data) {
5674
- var _a, _b;
5675
- if ((_a = data === null || data === void 0 ? void 0 : data.body) === null || _a === void 0 ? void 0 : _a.amount) this.meta.amount = data.body.amount;
5676
- if ((_b = data === null || data === void 0 ? void 0 : data.body) === null || _b === void 0 ? void 0 : _b.shipping_options) this.meta.shipping_options = data.body.shipping_options;
5767
+ var _a, _b, _c;
5768
+ if (!this.latestShippingChangePromiseResolve || !this.latestShippingChangePromiseReject) return;
5769
+ if (!data.success || !data.body) return this.latestShippingChangePromiseReject(); // TODO: check how to handle Error messages from Merchant at update() callback response
5770
+ var newAmount = (_a = data === null || data === void 0 ? void 0 : data.body) === null || _a === void 0 ? void 0 : _a.amount;
5771
+ var newShippingOptions = (_b = data === null || data === void 0 ? void 0 : data.body) === null || _b === void 0 ? void 0 : _b.shipping_options;
5772
+ if (newAmount) this.meta.amount = newAmount;
5773
+ if (newShippingOptions) {
5774
+ this.meta.shipping_options = newShippingOptions;
5775
+ this.selectedShippingOption = newShippingOptions ? newShippingOptions[0] : undefined;
5776
+ }
5777
+ var update = _extends({ newTotal: {
5778
+ label: (_c = this.meta) === null || _c === void 0 ? void 0 : _c.amount_label,
5779
+ amount: this.meta.amount.toString(),
5780
+ type: "final"
5781
+ } }, this.isShippingRequired() && this.hasShippingOptions() && {
5782
+ newShippingMethods: this.formatShippingOptions(this.meta.shipping_options)
5783
+ });
5784
+ this.paymentSession.completeShippingContactSelection(update);
5785
+ this.latestShippingChangePromiseResolve({});
5677
5786
  }
5678
5787
  }, {
5679
5788
  key: "checkAvailability",
@@ -5723,9 +5832,9 @@
5723
5832
  // https://developer.apple.com/documentation/apple_pay_on_the_web/applepaypaymentrequest
5724
5833
  if (this.meta.raw_data_initialization) {
5725
5834
  this.meta.raw_data_initialization.total.amount = this.meta.amount.toString();
5726
- if (this.meta.request_shipping && this.meta.shipping_options) this.meta.raw_data_initialization.shippingMethods = this.formatShippingOptions(this.meta.shipping_options);
5835
+ if (this.isShippingRequired() && this.hasShippingOptions()) this.meta.raw_data_initialization.shippingMethods = this.formatShippingOptions(this.meta.shipping_options);
5727
5836
  }
5728
- return this.meta.raw_data_initialization ? this.meta.raw_data_initialization : _extends(_extends({ countryCode: this.meta.country.toUpperCase(), currencyCode: this.meta.currency.toUpperCase(), merchantCapabilities: ["supports3DS", "supportsCredit", "supportsDebit"], supportedNetworks: ["visa", "masterCard", "amex", "discover"], requiredBillingContactFields: ["name", "postalAddress"] }, this.meta.request_shipping && _extends({ requiredShippingContactFields: ["postalAddress", "name", "phone", "email"] }, this.meta.shipping_options && {
5837
+ return this.meta.raw_data_initialization ? this.meta.raw_data_initialization : _extends(_extends({ countryCode: this.meta.country.toUpperCase(), currencyCode: this.meta.currency.toUpperCase(), merchantCapabilities: ["supports3DS", "supportsCredit", "supportsDebit"], supportedNetworks: ["visa", "masterCard", "amex", "discover"], requiredBillingContactFields: ["name", "postalAddress"] }, this.isShippingRequired() && _extends({ requiredShippingContactFields: ["postalAddress", "name", "phone", "email"] }, this.hasShippingOptions() && {
5729
5838
  shippingMethods: this.formatShippingOptions(this.meta.shipping_options)
5730
5839
  })), { total: {
5731
5840
  label: this.meta.amount_label,
@@ -5740,7 +5849,7 @@
5740
5849
 
5741
5850
  return new Promise(function (resolve, reject) {
5742
5851
  return _this5.eventEmitter.emit(WALLET_EVENT.CALLBACK, {
5743
- data: _extends({ request_type: "CREATE_SESSION", wallet_type: WALLET_TYPE.APPLE, session_id: window.location.hostname }, _this5.meta.request_shipping && { request_shipping: _this5.meta.request_shipping }),
5852
+ data: _extends({ request_type: "CREATE_SESSION", wallet_type: WALLET_TYPE.APPLE, session_id: window.location.hostname }, _this5.isShippingRequired() && { request_shipping: _this5.meta.request_shipping }),
5744
5853
  onSuccess: function onSuccess(res) {
5745
5854
  return resolve(res);
5746
5855
  },
@@ -5760,6 +5869,283 @@
5760
5869
  return AppleWalletService;
5761
5870
  }(WalletService);
5762
5871
 
5872
+ var GoogleWalletService = function (_WalletService) {
5873
+ inherits(GoogleWalletService, _WalletService);
5874
+
5875
+ function GoogleWalletService(publicKey, meta, gatewayName, eventEmitter) {
5876
+ classCallCheck(this, GoogleWalletService);
5877
+
5878
+ var _this = possibleConstructorReturn(this, (GoogleWalletService.__proto__ || Object.getPrototypeOf(GoogleWalletService)).call(this, publicKey, meta));
5879
+
5880
+ _this.gatewayName = gatewayName;
5881
+ _this.eventEmitter = eventEmitter;
5882
+ _this.parseUpdateData = function (data) {
5883
+ var _a, _b, _c, _d, _e, _f;
5884
+ var shippingOption = (_b = (_a = _this.meta) === null || _a === void 0 ? void 0 : _a.shipping_options) === null || _b === void 0 ? void 0 : _b.find(function (o) {
5885
+ var _a;return o.id === ((_a = data === null || data === void 0 ? void 0 : data.shippingOptionData) === null || _a === void 0 ? void 0 : _a.id);
5886
+ });
5887
+ return _extends({ shipping: {
5888
+ address_city: (_c = data.shippingAddress) === null || _c === void 0 ? void 0 : _c.locality,
5889
+ address_state: (_d = data.shippingAddress) === null || _d === void 0 ? void 0 : _d.administrativeArea,
5890
+ address_postcode: (_e = data === null || data === void 0 ? void 0 : data.shippingAddress) === null || _e === void 0 ? void 0 : _e.postalCode,
5891
+ address_country: (_f = data === null || data === void 0 ? void 0 : data.shippingAddress) === null || _f === void 0 ? void 0 : _f.countryCode
5892
+ } }, shippingOption && {
5893
+ selected_shipping_option: {
5894
+ id: shippingOption === null || shippingOption === void 0 ? void 0 : shippingOption.id,
5895
+ label: shippingOption === null || shippingOption === void 0 ? void 0 : shippingOption.label,
5896
+ detail: shippingOption === null || shippingOption === void 0 ? void 0 : shippingOption.detail,
5897
+ type: shippingOption === null || shippingOption === void 0 ? void 0 : shippingOption.type
5898
+ }
5899
+ });
5900
+ };
5901
+ _this.formatShippingOptions = function (shipping_options) {
5902
+ return shipping_options.map(function (option) {
5903
+ return {
5904
+ id: option.id,
5905
+ label: option.label,
5906
+ description: (option === null || option === void 0 ? void 0 : option.detail) || ''
5907
+ };
5908
+ });
5909
+ };
5910
+ _this.eventEmitter = eventEmitter;
5911
+ return _this;
5912
+ }
5913
+
5914
+ createClass(GoogleWalletService, [{
5915
+ key: "getGatewayName",
5916
+ value: function getGatewayName() {
5917
+ return this.gatewayName;
5918
+ }
5919
+ }, {
5920
+ key: "getMerchantId",
5921
+ value: function getMerchantId() {
5922
+ var _a, _b, _c;
5923
+ return (_c = (_b = (_a = this.meta) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b[WALLET_TYPE.GOOGLE]) === null || _c === void 0 ? void 0 : _c.merchant;
5924
+ }
5925
+ }, {
5926
+ key: "isShippingRequired",
5927
+ value: function isShippingRequired() {
5928
+ return this.meta.request_shipping;
5929
+ }
5930
+ }, {
5931
+ key: "hasShippingOptions",
5932
+ value: function hasShippingOptions() {
5933
+ return this.meta.request_shipping && !!this.meta.shipping_options;
5934
+ }
5935
+ }, {
5936
+ key: "load",
5937
+ value: function load(container) {
5938
+ var _this2 = this;
5939
+
5940
+ if (!window.Promise) {
5941
+ // Given that this library does not rely in any polyfill for promises, and this integration depends on them, we early return if Promises are not supported for the browser (like I.E. 11).
5942
+ this.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { wallet: WALLET_TYPE.GOOGLE });
5943
+ return;
5944
+ }
5945
+ return new Promise(function (resolve, reject) {
5946
+ var googlePayJs = document.createElement("script");
5947
+ googlePayJs.type = "text/javascript";
5948
+ googlePayJs.src = "https://pay.google.com/gp/p/js/pay.js";
5949
+ googlePayJs.async = true;
5950
+ googlePayJs.onload = function () {
5951
+ var _a, _b, _c;
5952
+ if (!window.google) {
5953
+ _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { wallet: WALLET_TYPE.GOOGLE });
5954
+ reject();
5955
+ return;
5956
+ }
5957
+ // Store default shipping option
5958
+ if (_this2.isShippingRequired() && _this2.hasShippingOptions()) {
5959
+ _this2.selectedShippingOption = (_a = _this2.meta) === null || _a === void 0 ? void 0 : _a.shipping_options[0];
5960
+ }
5961
+ _this2.paymentsClient = new google.payments.api.PaymentsClient(_extends({ merchantInfo: _extends(_extends({}, ((_b = _this2.meta) === null || _b === void 0 ? void 0 : _b.merchant_name) ? { merchantName: (_c = _this2.meta) === null || _c === void 0 ? void 0 : _c.merchant_name } : {}), { merchantId: _this2.getMerchantId() }), paymentDataCallbacks: _extends({ onPaymentAuthorized: function onPaymentAuthorized(paymentData) {
5962
+ return _this2.onPaymentAuthorized(paymentData);
5963
+ } }, _this2.isShippingRequired() && {
5964
+ onPaymentDataChanged: function onPaymentDataChanged(intermediatePaymentData) {
5965
+ return _this2.onPaymentDataChanged(intermediatePaymentData);
5966
+ }
5967
+ }) }, _this2.env !== ENV.PROD ? { environment: "TEST" } : { environment: "PRODUCTION" }));
5968
+ _this2.checkAvailability().then(function (available) {
5969
+ if (!available) {
5970
+ _this2.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, { wallet: WALLET_TYPE.GOOGLE });
5971
+ reject();
5972
+ return;
5973
+ }
5974
+ _this2.mount(container);
5975
+ resolve();
5976
+ });
5977
+ };
5978
+ document.head.appendChild(googlePayJs);
5979
+ });
5980
+ }
5981
+ }, {
5982
+ key: "update",
5983
+ value: function update(data) {
5984
+ var _a, _b, _c, _d;
5985
+ if (!this.latestShippingChangePromiseResolve || !this.latestShippingChangePromiseReject) return;
5986
+ if (!data.success) return this.latestShippingChangePromiseReject(); // TODO: check how to handle Error messages from Merchant at update() callback response
5987
+ var newAmount = ((_a = data === null || data === void 0 ? void 0 : data.body) === null || _a === void 0 ? void 0 : _a.amount) || this.meta.amount;
5988
+ var newShippingOptions = ((_b = data === null || data === void 0 ? void 0 : data.body) === null || _b === void 0 ? void 0 : _b.shipping_options) || this.meta.shipping_options;
5989
+ if (newAmount) this.meta.amount = newAmount;
5990
+ if (newShippingOptions) {
5991
+ this.meta.shipping_options = newShippingOptions;
5992
+ this.selectedShippingOption = newShippingOptions ? newShippingOptions[0] : undefined;
5993
+ }
5994
+ var paymentDataRequestUpdate = _extends({ newTransactionInfo: {
5995
+ totalPriceStatus: "FINAL",
5996
+ totalPriceLabel: this.meta.amount_label,
5997
+ totalPrice: (_c = this.meta.amount) === null || _c === void 0 ? void 0 : _c.toString(),
5998
+ currencyCode: this.meta.currency.toUpperCase(),
5999
+ countryCode: this.meta.country.toUpperCase()
6000
+ } }, this.isShippingRequired() && this.hasShippingOptions() && {
6001
+ newShippingOptionParameters: {
6002
+ defaultSelectedOptionId: (_d = this.selectedShippingOption) === null || _d === void 0 ? void 0 : _d.id,
6003
+ shippingOptions: this.formatShippingOptions(this.meta.shipping_options)
6004
+ }
6005
+ });
6006
+ this.latestShippingChangePromiseResolve(paymentDataRequestUpdate);
6007
+ }
6008
+ }, {
6009
+ key: "checkAvailability",
6010
+ value: function checkAvailability() {
6011
+ return this.paymentsClient.isReadyToPay(this.createRequest()).then(function (response) {
6012
+ return !!response.result;
6013
+ }).catch(function (err) {
6014
+ console.error("Error checking GooglePay availability", err);
6015
+ return false;
6016
+ });
6017
+ }
6018
+ }, {
6019
+ key: "mount",
6020
+ value: function mount(container) {
6021
+ var _this3 = this;
6022
+
6023
+ container.getElement().appendChild(this.paymentsClient.createButton({
6024
+ buttonSizeMode: "fill",
6025
+ onClick: function onClick() {
6026
+ return _this3.loadPaymentData();
6027
+ }
6028
+ }));
6029
+ }
6030
+ }, {
6031
+ key: "loadPaymentData",
6032
+ value: function loadPaymentData() {
6033
+ this.paymentsClient.loadPaymentData(this.createPaymentDataRequest())
6034
+ // .then((paymentData) => {
6035
+ // // if using gateway tokenization, pass this token without modification
6036
+ // // this.paymentToken = paymentData.paymentMethodData.tokenizationData.token;
6037
+ // })
6038
+ .catch(function () {
6039
+ console.error('Error while loading payment data');
6040
+ });
6041
+ }
6042
+ }, {
6043
+ key: "onPaymentAuthorized",
6044
+ value: function onPaymentAuthorized(paymentData) {
6045
+ var _this4 = this;
6046
+
6047
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6048
+ var billingAddressLine1 = (_c = (_b = (_a = paymentData.paymentMethodData) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.billingAddress) === null || _c === void 0 ? void 0 : _c.address1;
6049
+ var billingAddressLine2 = (_f = (_e = (_d = paymentData.paymentMethodData) === null || _d === void 0 ? void 0 : _d.info) === null || _e === void 0 ? void 0 : _e.billingAddress) === null || _f === void 0 ? void 0 : _f.address2;
6050
+ var shippingAddressLine1 = (_g = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _g === void 0 ? void 0 : _g.address1;
6051
+ var shippingAddressLine2 = (_h = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _h === void 0 ? void 0 : _h.address2;
6052
+ var shippingOptionMethod = (_j = this.selectedShippingOption) === null || _j === void 0 ? void 0 : _j.type;
6053
+ return new Promise(function (resolve) {
6054
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
6055
+ return _this4.eventEmitter.emit(WALLET_EVENT.PAYMENT_METHOD_SELECTED, {
6056
+ data: _extends({ customer: {
6057
+ payment_source: _extends(_extends(_extends(_extends({ wallet_type: WALLET_TYPE.GOOGLE, card_name: (_a = paymentData.paymentMethodData) === null || _a === void 0 ? void 0 : _a.description, type: paymentData.paymentMethodData.type, card_scheme: (_c = (_b = paymentData.paymentMethodData) === null || _b === void 0 ? void 0 : _b.info) === null || _c === void 0 ? void 0 : _c.cardNetwork }, billingAddressLine1 && { address_line1: billingAddressLine1 }), billingAddressLine2 && { address_line2: billingAddressLine2 }), billingAddressLine2 && { address_line2: billingAddressLine2 }), { address_country: (_f = (_e = (_d = paymentData.paymentMethodData) === null || _d === void 0 ? void 0 : _d.info) === null || _e === void 0 ? void 0 : _e.billingAddress) === null || _f === void 0 ? void 0 : _f.countryCode, address_city: (_j = (_h = (_g = paymentData.paymentMethodData) === null || _g === void 0 ? void 0 : _g.info) === null || _h === void 0 ? void 0 : _h.billingAddress) === null || _j === void 0 ? void 0 : _j.locality, address_postcode: (_m = (_l = (_k = paymentData.paymentMethodData) === null || _k === void 0 ? void 0 : _k.info) === null || _l === void 0 ? void 0 : _l.billingAddress) === null || _m === void 0 ? void 0 : _m.postalCode, address_state: (_q = (_p = (_o = paymentData.paymentMethodData) === null || _o === void 0 ? void 0 : _o.info) === null || _p === void 0 ? void 0 : _p.billingAddress) === null || _q === void 0 ? void 0 : _q.administrativeArea, ref_token: paymentData.paymentMethodData.tokenizationData.token })
6058
+ } }, _this4.isShippingRequired() && {
6059
+ shipping: _extends(_extends(_extends(_extends(_extends({}, shippingOptionMethod && { method: shippingOptionMethod }), _this4.hasShippingOptions() && { options: _this4.meta.shipping_options }), shippingAddressLine1 && { address_line1: shippingAddressLine1 }), shippingAddressLine2 && { address_line2: shippingAddressLine2 }), { address_country: (_r = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _r === void 0 ? void 0 : _r.countryCode, address_city: (_s = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _s === void 0 ? void 0 : _s.locality, address_postcode: (_t = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _t === void 0 ? void 0 : _t.postalCode, address_state: (_u = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _u === void 0 ? void 0 : _u.administrativeArea, contact: {
6060
+ first_name: (_v = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _v === void 0 ? void 0 : _v.name,
6061
+ email: paymentData === null || paymentData === void 0 ? void 0 : paymentData.email,
6062
+ phone: (_w = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _w === void 0 ? void 0 : _w.phoneNumber
6063
+ } })
6064
+ }),
6065
+ onSuccess: function onSuccess() {
6066
+ return resolve({ transactionState: 'SUCCESS' });
6067
+ },
6068
+ onError: function onError(message) {
6069
+ return resolve({
6070
+ transactionState: 'ERROR',
6071
+ error: {
6072
+ intent: 'PAYMENT_AUTHORIZATION',
6073
+ message: message,
6074
+ reason: 'PAYMENT_DATA_INVALID'
6075
+ }
6076
+ });
6077
+ }
6078
+ });
6079
+ });
6080
+ }
6081
+ }, {
6082
+ key: "onPaymentDataChanged",
6083
+ value: function onPaymentDataChanged(intermediatePaymentData) {
6084
+ var _this5 = this;
6085
+
6086
+ if (!this.isShippingRequired()) return;
6087
+ var parsedUpdateData = this.parseUpdateData(intermediatePaymentData);
6088
+ this.eventEmitter.emit(WALLET_EVENT.UPDATE, parsedUpdateData);
6089
+ return new Promise(function (res, rej) {
6090
+ _this5.latestShippingChangePromiseResolve = res;
6091
+ _this5.latestShippingChangePromiseReject = rej;
6092
+ });
6093
+ }
6094
+ }, {
6095
+ key: "createRequest",
6096
+ value: function createRequest() {
6097
+ return {
6098
+ apiVersion: 2,
6099
+ apiVersionMinor: 0,
6100
+ allowedPaymentMethods: [this.createCardData()]
6101
+ };
6102
+ }
6103
+ }, {
6104
+ key: "createPaymentDataRequest",
6105
+ value: function createPaymentDataRequest() {
6106
+ var _a, _b, _c, _d;
6107
+ // Store default shipping option
6108
+ if (this.isShippingRequired() && this.hasShippingOptions()) {
6109
+ this.selectedShippingOption = (_a = this.meta) === null || _a === void 0 ? void 0 : _a.shipping_options[0];
6110
+ }
6111
+ var gateway = 'paydock';
6112
+ var gatewayMerchantId = this.getMerchantId();
6113
+ return _extends({ apiVersion: 2, apiVersionMinor: 0, allowedPaymentMethods: [_extends(_extends({}, this.createCardData()), { tokenizationSpecification: {
6114
+ type: "PAYMENT_GATEWAY",
6115
+ parameters: {
6116
+ gateway: gateway,
6117
+ gatewayMerchantId: gatewayMerchantId
6118
+ }
6119
+ } })], transactionInfo: {
6120
+ totalPriceStatus: "FINAL",
6121
+ totalPriceLabel: this.meta.amount_label,
6122
+ totalPrice: this.meta.amount.toString(),
6123
+ currencyCode: this.meta.currency.toUpperCase(),
6124
+ countryCode: this.meta.country.toUpperCase()
6125
+ }, merchantInfo: _extends(_extends({}, ((_b = this.meta) === null || _b === void 0 ? void 0 : _b.merchant_name) ? { merchantName: (_c = this.meta) === null || _c === void 0 ? void 0 : _c.merchant_name } : {}), { merchantId: gatewayMerchantId }), callbackIntents: ["PAYMENT_AUTHORIZATION"].concat(toConsumableArray(this.isShippingRequired() ? ["SHIPPING_ADDRESS"] : []), toConsumableArray(this.hasShippingOptions() ? ["SHIPPING_OPTION"] : [])) }, this.isShippingRequired() && _extends({ shippingAddressRequired: true }, this.hasShippingOptions() && {
6126
+ shippingOptionRequired: true,
6127
+ shippingOptionParameters: {
6128
+ defaultSelectedOptionId: (_d = this.selectedShippingOption) === null || _d === void 0 ? void 0 : _d.id,
6129
+ shippingOptions: this.formatShippingOptions(this.meta.shipping_options)
6130
+ }
6131
+ }));
6132
+ }
6133
+ }, {
6134
+ key: "createCardData",
6135
+ value: function createCardData() {
6136
+ return {
6137
+ // TODO: Add raw_data_initialization as in ApplePay
6138
+ type: "CARD",
6139
+ parameters: {
6140
+ allowedAuthMethods: ["PAN_ONLY", "CRYPTOGRAM_3DS"],
6141
+ allowedCardNetworks: ["AMEX", "DISCOVER", "INTERAC", "JCB", "MASTERCARD", "VISA"]
6142
+ }
6143
+ };
6144
+ }
6145
+ }]);
6146
+ return GoogleWalletService;
6147
+ }(WalletService);
6148
+
5763
6149
  var MastercardWalletService = function (_WalletService) {
5764
6150
  inherits(MastercardWalletService, _WalletService);
5765
6151
 
@@ -5771,8 +6157,12 @@
5771
6157
  createClass(MastercardWalletService, [{
5772
6158
  key: "initializeChildWallets",
5773
6159
  value: function initializeChildWallets() {
6160
+ var _a, _b, _c, _d, _e, _f;
5774
6161
  this.childWallets = [];
5775
- if (!this.meta.wallets || this.meta.wallets.includes(WALLET_TYPE.APPLE)) this.childWallets.push(new AppleWalletService(this.publicKey, this.meta, this.getGatewayName(), this.eventEmitter));
6162
+ var hasAppleCredentials = !!((_c = (_b = (_a = this.meta) === null || _a === void 0 ? void 0 : _a.credentials) === null || _b === void 0 ? void 0 : _b.apple) === null || _c === void 0 ? void 0 : _c.merchant);
6163
+ var hasGoogleCredentials = !!((_f = (_e = (_d = this.meta) === null || _d === void 0 ? void 0 : _d.credentials) === null || _e === void 0 ? void 0 : _e.google) === null || _f === void 0 ? void 0 : _f.merchant);
6164
+ if (hasAppleCredentials && (!this.meta.wallets || this.meta.wallets.includes(WALLET_TYPE.APPLE))) this.childWallets.push(new AppleWalletService(this.publicKey, this.meta, this.getGatewayName(), this.eventEmitter));
6165
+ if (hasGoogleCredentials && (!this.meta.wallets || this.meta.wallets.includes(WALLET_TYPE.GOOGLE))) this.childWallets.push(new GoogleWalletService(this.publicKey, this.meta, this.getGatewayName(), this.eventEmitter));
5776
6166
  }
5777
6167
  }, {
5778
6168
  key: "getGatewayName",
@@ -5790,46 +6180,6 @@
5790
6180
  return MastercardWalletService;
5791
6181
  }(WalletService);
5792
6182
 
5793
- var AccessToken = function () {
5794
- function AccessToken() {
5795
- classCallCheck(this, AccessToken);
5796
- }
5797
-
5798
- createClass(AccessToken, null, [{
5799
- key: "validateJWT",
5800
- value: function validateJWT(jwt) {
5801
- var _jwt$split = jwt.split("."),
5802
- _jwt$split2 = slicedToArray(_jwt$split, 3),
5803
- rawHead = _jwt$split2[0],
5804
- rawBody = _jwt$split2[1],
5805
- signature = _jwt$split2[2];
5806
-
5807
- if (!rawHead || !rawBody || !signature) return null;
5808
- if (2 + rawHead.length + rawBody.length + signature.length !== jwt.length) return null;
5809
- try {
5810
- var head = JSON.parse(atob(rawHead));
5811
- var body = JSON.parse(atob(rawBody));
5812
- return { head: head, body: body, signature: signature };
5813
- } catch (_a) {
5814
- return null;
5815
- }
5816
- }
5817
- }, {
5818
- key: "extractMeta",
5819
- value: function extractMeta(body) {
5820
- try {
5821
- var _JSON$parse = JSON.parse(atob(body.meta)),
5822
- meta = _JSON$parse.meta;
5823
-
5824
- return meta;
5825
- } catch (_a) {
5826
- return null;
5827
- }
5828
- }
5829
- }]);
5830
- return AccessToken;
5831
- }();
5832
-
5833
6183
  var API_AUTH_TYPE;
5834
6184
  (function (API_AUTH_TYPE) {
5835
6185
  API_AUTH_TYPE[API_AUTH_TYPE["PUBLIC_KEY"] = 0] = "PUBLIC_KEY";
@@ -5948,6 +6298,8 @@
5948
6298
 
5949
6299
  var WALLET_CAPTURE_LINK = '/v1/charges/wallet/capture';
5950
6300
  var WALLET_CALLBACK_LINK = '/v1/charges/wallet/callback';
6301
+ var STANDALONE_3DS_PROCESS_LINK = '/v1/charges/standalone-3ds/process';
6302
+ var STANDALONE_3DS_HANDLE_LINK = '/v1/charges/standalone-3ds/handle';
5951
6303
  var ApiChargeInternal = function () {
5952
6304
  function ApiChargeInternal(api) {
5953
6305
  classCallCheck(this, ApiChargeInternal);
@@ -5965,6 +6317,16 @@
5965
6317
  value: function walletCallback(payload) {
5966
6318
  return this.api.getClientPromise('POST', WALLET_CALLBACK_LINK).send(payload);
5967
6319
  }
6320
+ }, {
6321
+ key: 'standalone3dsProcess',
6322
+ value: function standalone3dsProcess(payload) {
6323
+ return this.api.getClientPromise('POST', STANDALONE_3DS_PROCESS_LINK).send(payload);
6324
+ }
6325
+ }, {
6326
+ key: 'standalone3dsHandle',
6327
+ value: function standalone3dsHandle() {
6328
+ return this.api.getClientPromise('GET', STANDALONE_3DS_HANDLE_LINK).send(undefined);
6329
+ }
5968
6330
  }]);
5969
6331
  return ApiChargeInternal;
5970
6332
  }();
@@ -6008,30 +6370,51 @@
6008
6370
  * @interface IWalletMeta
6009
6371
  *
6010
6372
  * @type {object}
6011
- * @param {string} [amount_label] Label shown next to the total amount to be paid. Required for [Stripe, ApplePay]. N/A for [FlyPay, PayPal].
6012
- * @param {string} [country] Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay]. N/A for [FlyPay, PayPal].
6373
+ * @param {string} [amount_label] Label shown next to the total amount to be paid. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal].
6374
+ * @param {string} [country] Country of the user. 2 letter ISO code format. Required for [Stripe, ApplePay, GooglePay]. N/A for [FlyPay, PayPal].
6013
6375
  * @param {string} [pay_later] Used to enable Pay Later feature in PayPal Smart Checkout WalletButton integration when available. Optional for [PayPal]. N/A for other wallets.
6014
6376
  * @param {boolean} [request_payer_name] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6015
6377
  * @param {boolean} [request_payer_email] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6016
6378
  * @param {boolean} [request_payer_phone] Used mainly for fraud purposes - recommended set to true. Optional for [Stripe]. N/A for other wallets.
6017
- * @param {boolean} [request_shipping] Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay]. N/A for [Stripe].
6018
- * @param {Array.<IShippingOption>} [shipping_options] Used to provide available shipping options. Optional for [ApplePay]. N/A for the other wallets.
6379
+ * @param {boolean} [request_shipping] Used to request or not shipping address in the Wallet checkout, being able to handle amount changes via the `update` event. Optional for [FlyPay, PayPal, ApplePay, GooglePay]. N/A for [Stripe].
6380
+ * @param {IApplePayShippingOption[] | IPayPalShippingOption[]} [shipping_options] Used to provide available shipping options.(To use shipping_options the request_shipping flag should be true). Optional for [ApplePay]. N/A for the other wallets.
6381
+ * @param {string} [merchant_name] Merchant Name used for GooglePay integration via MPGS. Required for [GooglePay]. N/A for other wallets.
6019
6382
  * @param {object} [raw_data_initialization] Used to provide values to initialize wallet with raw data. Optional for [ApplePay]. N/A for the other wallets.
6020
6383
  * @param {object} [style] Used to style PayPal buttons, check possible values at https://developer.paypal.com/docs/business/checkout/reference/style-guide. Also used at ApplePay to select button type. Optional for [PayPal, ApplePay]. N/A for [Stripe, FlyPay].
6021
6384
  * @param {object} [style.button_type] Used to select ApplePay button type (e.g: 'buy','donate', etc), check possible values at https://developer.apple.com/documentation/apple_pay_on_the_web/displaying_apple_pay_buttons_using_css. Optional for [ApplePay]. N/A for other wallets.
6022
- * @param {array} [wallets] By default if this is not sent or empty, we will try to show either Apple Pay or Google Pay buttons. This can be limited sending the following array in this field: ['apple','google]. Optional for [Stripe]. N/A for other wallets.
6385
+ * @param {array} [wallets] By default if this is not sent or empty, we will try to show either Apple Pay or Google Pay buttons. This can be limited sending the following array in this field: ['apple','google]. Optional for [Stripe, ApplePay, GooglePay]. N/A for other wallets.
6023
6386
  */
6024
6387
  /**
6025
- * Interface of Shipping Options.
6026
- * @interface IShippingOption
6388
+ * Interface of Shipping Options for ApplePay
6389
+ * @interface IApplePayShippingOption
6027
6390
  *
6028
6391
  * @type {object}
6029
6392
  * @param {string} [id] Identifier of the Shipping Option. Required.
6030
6393
  * @param {string} [label] Identifier of the Shipping Option. Required.
6031
6394
  * @param {string} [amount] Amount of the Shipping Option. Required.
6395
+ * @param {string} [detail] Details of the Shipping Option. Required.
6396
+ * @param {string} [type] Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional.
6397
+ */
6398
+ /**
6399
+ * Interface of Shipping Options for GooglePay
6400
+ * @interface IGooglePayShippingOption
6401
+ *
6402
+ * @type {object}
6403
+ * @param {string} [id] Identifier of the Shipping Option. Required.
6404
+ * @param {string} [label] Identifier of the Shipping Option. Required.
6032
6405
  * @param {string} [detail] Details of the Shipping Option. Optional.
6033
- * @param {string} [currency] Currency of the Shipping Option. Optional.
6034
- * @param {string} [type] Type of the Shipping Option. Optional.
6406
+ * @param {string} [type] Type of the Shipping Option. Values can be 'ELECTRONIC', 'GROUND', 'NOT_SHIPPED', 'OVERNIGHT', 'PICKUP', 'PRIORITY', 'SAME_DAY'. Optional.
6407
+ */
6408
+ /**
6409
+ * Interface of Shipping Options for PayPal
6410
+ * @interface IPayPalShippingOption
6411
+ *
6412
+ * @type {object}
6413
+ * @param {string} [id] Identifier of the Shipping Option. Required.
6414
+ * @param {string} [label] Identifier of the Shipping Option. Required.
6415
+ * @param {string} [amount] Amount of the Shipping Option. Required.
6416
+ * @param {string} [currency] Currency of the Shipping Option. Required.
6417
+ * @param {string} [type] Type of the Shipping Option. Values can be 'SHIPPING' or 'PICKUP'. Required.
6035
6418
  */
6036
6419
  /**
6037
6420
  * Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay and Apple Pay via Stripe, Flypay, Paypal)
@@ -6094,13 +6477,13 @@
6094
6477
  this.setupServiceCallbacks();
6095
6478
  this.service.load(this.container);
6096
6479
  } catch (err) {
6097
- this.eventEmitter.emit(EVENT$2.UNAVAILABLE, { event: EVENT$2.UNAVAILABLE, data: null });
6480
+ this.eventEmitter.emit(EVENT$2.UNAVAILABLE, null);
6098
6481
  throw err;
6099
6482
  }
6100
6483
  }
6101
6484
  /**
6102
6485
  * Triggers the update process of the wallet, if available.
6103
- * Currently supported by Flypay, Paypal and ApplePay via MPGS Wallets.
6486
+ * Currently supported by Flypay, Paypal and ApplePay/GooglePay via MPGS Wallets.
6104
6487
  *
6105
6488
  * @example
6106
6489
  * var button = new WalletButtons(
@@ -6224,6 +6607,7 @@
6224
6607
  }
6225
6608
  /**
6226
6609
  * User to subscribe to the no button available event. This method is used after loading when the button is not available.
6610
+ * For MPGS, since can have more than one wallet button configured (ApplePay/GooglePay) you will receive a body (({ wallet: WALLET_TYPE.GOOGLE }) or ({ wallet: WALLET_TYPE.APPLE })) indicating which button is unavailable
6227
6611
  * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
6228
6612
  *
6229
6613
  * @example
@@ -6234,6 +6618,9 @@
6234
6618
  * @example
6235
6619
  * button.onUnavailable().then(() => console.log('No wallet buttons available'));
6236
6620
  *
6621
+ * @example
6622
+ * button.onUnavailable(function (data) {console.log('data.wallet :: ', data.wallet)});
6623
+ *
6237
6624
  * @param {listener} [handler] - Function to be called when no button is available.
6238
6625
  */
6239
6626
 
@@ -6375,8 +6762,8 @@
6375
6762
  value: function setupUnavailableCallback() {
6376
6763
  var _this7 = this;
6377
6764
 
6378
- this.service.on(WALLET_EVENT.UNAVAILABLE, function () {
6379
- return _this7.eventEmitter.emit(EVENT$2.UNAVAILABLE, { event: EVENT$2.UNAVAILABLE, data: null });
6765
+ this.service.on(WALLET_EVENT.UNAVAILABLE, function (eventData) {
6766
+ return _this7.eventEmitter.emit(EVENT$2.UNAVAILABLE, { event: EVENT$2.UNAVAILABLE, data: eventData });
6380
6767
  });
6381
6768
  }
6382
6769
  }, {
@@ -6826,6 +7213,231 @@
6826
7213
  return HtmlPaymentSourceWidget;
6827
7214
  }(PaymentSourceWidget);
6828
7215
 
7216
+ var hiddenStyle = {
7217
+ visibility: "hidden",
7218
+ border: "0",
7219
+ width: "0",
7220
+ height: "0"
7221
+ };
7222
+ var PROCESS_STANDALONE_3DS_STATUS;
7223
+ (function (PROCESS_STANDALONE_3DS_STATUS) {
7224
+ PROCESS_STANDALONE_3DS_STATUS["SUCCESS"] = "success";
7225
+ PROCESS_STANDALONE_3DS_STATUS["ERROR"] = "error";
7226
+ PROCESS_STANDALONE_3DS_STATUS["PENDING"] = "pending";
7227
+ })(PROCESS_STANDALONE_3DS_STATUS || (PROCESS_STANDALONE_3DS_STATUS = {}));
7228
+ var GPAYMENTS_EVENT = {
7229
+ AUTH_SUCCESS: 'chargeAuthSuccess',
7230
+ AUTH_ERROR: 'chargeAuthReject',
7231
+ DECOUPLED: 'chargeAuthDecoupled',
7232
+ CHALLENGE: 'chargeAuthChallenge',
7233
+ ERROR: 'error'
7234
+ };
7235
+ var GPaymentsService = function () {
7236
+ function GPaymentsService(container, api, eventEmitter) {
7237
+ classCallCheck(this, GPaymentsService);
7238
+
7239
+ this.container = container;
7240
+ this.api = api;
7241
+ this.eventEmitter = eventEmitter;
7242
+ this.resultRead = false;
7243
+ this.iFrameEvent = new IFrameEvent(window);
7244
+ }
7245
+
7246
+ createClass(GPaymentsService, [{
7247
+ key: "load",
7248
+ value: function load(_ref, title) {
7249
+ var initialization_url = _ref.initialization_url,
7250
+ secondary_url = _ref.secondary_url,
7251
+ charge_3ds_id = _ref.charge_3ds_id;
7252
+
7253
+ try {
7254
+ this.setupIFrameEvents(charge_3ds_id);
7255
+ this.initializeIFrames(initialization_url, secondary_url, title);
7256
+ } catch (err) {
7257
+ this.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, this.parseError(err, charge_3ds_id));
7258
+ }
7259
+ }
7260
+ }, {
7261
+ key: "initializeIFrames",
7262
+ value: function initializeIFrames(initializationUrl, secondaryUrl, title) {
7263
+ var hideAuthorization = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
7264
+
7265
+ var divAuthorization = document.createElement("div");
7266
+ divAuthorization.setAttribute("id", "paydock_authorization_iframe");
7267
+ this.container.getElement().appendChild(divAuthorization);
7268
+ this.browserAndChallengeContainer = new Container("#paydock_authorization_iframe");
7269
+ this.iFrameAuthorization = new IFrame(this.browserAndChallengeContainer);
7270
+ this.iFrameAuthorization.load(initializationUrl, { title: title });
7271
+ var divSecondaryURL = document.createElement("div");
7272
+ divSecondaryURL.setAttribute("id", "paydock_secondary_iframe");
7273
+ this.container.getElement().appendChild(divSecondaryURL);
7274
+ this.monitoringContainer = new Container("#paydock_secondary_iframe");
7275
+ this.iFrameSecondaryUrl = new IFrame(this.monitoringContainer);
7276
+ this.iFrameSecondaryUrl.load(secondaryUrl, { title: title });
7277
+ this.hideIframes(hideAuthorization);
7278
+ }
7279
+ }, {
7280
+ key: "hideIframes",
7281
+ value: function hideIframes() {
7282
+ var hideAuthorization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7283
+
7284
+ for (var prop in hiddenStyle) {
7285
+ if (!hiddenStyle.hasOwnProperty(prop)) continue;
7286
+ if (hideAuthorization) this.iFrameAuthorization.setStyle(prop, hiddenStyle[prop]);
7287
+ this.iFrameSecondaryUrl.setStyle(prop, hiddenStyle[prop]);
7288
+ }
7289
+ }
7290
+ }, {
7291
+ key: "setupIFrameEvents",
7292
+ value: function setupIFrameEvents(widgetId) {
7293
+ var _this = this;
7294
+
7295
+ this.iFrameEvent.on(EVENT.CHARGE_AUTH, widgetId, function (data) {
7296
+ if (data.status === "MethodSkipped" /* SKIPPED */) _this.performAuthentication(data);
7297
+ });
7298
+ this.iFrameEvent.on(EVENT.CHARGE_AUTH_SUCCESS, widgetId, function (data) {
7299
+ _this.processResult(data.charge_3ds_id);
7300
+ });
7301
+ }
7302
+ }, {
7303
+ key: "parseResultData",
7304
+ value: function parseResultData(_ref2, charge3dsId) {
7305
+ var status = _ref2.status;
7306
+
7307
+ return {
7308
+ status: status,
7309
+ charge_3ds_id: charge3dsId
7310
+ };
7311
+ }
7312
+ }, {
7313
+ key: "parseHandleResponse",
7314
+ value: function parseHandleResponse(_ref3, charge3dsId) {
7315
+ var status = _ref3.status,
7316
+ result = _ref3.result;
7317
+
7318
+ return {
7319
+ status: status,
7320
+ charge_3ds_id: charge3dsId,
7321
+ result: {
7322
+ description: result === null || result === void 0 ? void 0 : result.description
7323
+ }
7324
+ };
7325
+ }
7326
+ }, {
7327
+ key: "parseError",
7328
+ value: function parseError(data, charge3dsId) {
7329
+ return { charge_3ds_id: charge3dsId, error: data };
7330
+ }
7331
+ }, {
7332
+ key: "processResult",
7333
+ value: function processResult(charge3dsId) {
7334
+ var _this2 = this;
7335
+
7336
+ if (this.resultRead) return;
7337
+ this.resultRead = true;
7338
+ this.api.charge().standalone3dsHandle().then(function (result) {
7339
+ _this2.iFrameAuthorization.remove();
7340
+ _this2.iFrameSecondaryUrl.remove();
7341
+ if (result.status === PROCESS_STANDALONE_3DS_STATUS.SUCCESS) _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this2.parseResultData(result, charge3dsId));else _this2.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this2.parseResultData(result, charge3dsId));
7342
+ }, function (err) {
7343
+ _this2.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this2.parseError(err, charge3dsId));
7344
+ });
7345
+ }
7346
+ }, {
7347
+ key: "externalAPI",
7348
+ value: function externalAPI(method, url) {
7349
+ var request = new XMLHttpRequest();
7350
+ request.open(method, url, true);
7351
+ return new Promise(function (resolve, reject) {
7352
+ request.onload = function () {
7353
+ try {
7354
+ var body = JSON.parse(request.responseText);
7355
+ resolve(body);
7356
+ } catch (error) {
7357
+ reject(error);
7358
+ }
7359
+ };
7360
+ request.send();
7361
+ });
7362
+ }
7363
+ }, {
7364
+ key: "doPolling",
7365
+ value: function doPolling(url, charge3dsId) {
7366
+ var _this3 = this;
7367
+
7368
+ this.externalAPI("GET", url).then(function (data) {
7369
+ if (!data.event || data.event === "AuthResultNotReady") setTimeout(function () {
7370
+ _this3.doPolling(url, charge3dsId);
7371
+ }, 2000);else if (data.event === 'AuthResultReady') _this3.processResult(charge3dsId);else throw new Error("Event not supported");
7372
+ }).catch(function (err) {
7373
+ return _this3.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this3.parseError(err, charge3dsId));
7374
+ });
7375
+ }
7376
+ }, {
7377
+ key: "performAuthentication",
7378
+ value: function performAuthentication(_ref4) {
7379
+ var _this4 = this;
7380
+
7381
+ var charge_3ds_id = _ref4.charge_3ds_id;
7382
+
7383
+ this.iFrameAuthorization.remove();
7384
+ this.iFrameSecondaryUrl.remove();
7385
+ this.api.charge().standalone3dsProcess({ charge_3ds_id: charge_3ds_id }).then(function (authenticationResult) {
7386
+ var _a, _b;
7387
+ if (authenticationResult.status === "success" /* SUCCESS */) _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_SUCCESS, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));else if (authenticationResult.status === "pending" /* PENDING */) {
7388
+ if ((_a = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _a === void 0 ? void 0 : _a.challenge) {
7389
+ _this4.eventEmitter.emit(GPAYMENTS_EVENT.CHALLENGE, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7390
+ _this4.initializeIFrames(authenticationResult.result.challenge_url, 'authenticationResult.result.secondary_url', 'Authentication Challenge', false);
7391
+ _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
7392
+ } else if ((_b = authenticationResult === null || authenticationResult === void 0 ? void 0 : authenticationResult.result) === null || _b === void 0 ? void 0 : _b.decoupled_challenge) {
7393
+ _this4.eventEmitter.emit(GPAYMENTS_EVENT.DECOUPLED, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7394
+ _this4.doPolling(authenticationResult.result.secondary_url, charge_3ds_id);
7395
+ }
7396
+ } else return _this4.eventEmitter.emit(GPAYMENTS_EVENT.AUTH_ERROR, _this4.parseHandleResponse(authenticationResult, charge_3ds_id));
7397
+ }, function (err) {
7398
+ _this4.eventEmitter.emit(GPAYMENTS_EVENT.ERROR, _this4.parseError(err, charge_3ds_id));
7399
+ });
7400
+ }
7401
+ }]);
7402
+ return GPaymentsService;
7403
+ }();
7404
+
7405
+ var STANDALONE_3DS_GATEWAYS = {
7406
+ GPAYMENTS: "GPayments"
7407
+ };
7408
+ var Standalone3dsService = function () {
7409
+ function Standalone3dsService(container, eventEmitter) {
7410
+ classCallCheck(this, Standalone3dsService);
7411
+
7412
+ this.env = ENV.SANDBOX;
7413
+ this.container = container;
7414
+ this.eventEmitter = eventEmitter;
7415
+ }
7416
+
7417
+ createClass(Standalone3dsService, [{
7418
+ key: "load",
7419
+ value: function load(token, options) {
7420
+ var parsedToken = AccessToken.validateJWT(token);
7421
+ if (!parsedToken) throw new Error("Invalid charge token");
7422
+ var tokenData = AccessToken.extractData(parsedToken.body);
7423
+ var api = new ApiInternal(token, API_AUTH_TYPE.TOKEN);
7424
+ api.setEnv(this.env, this.alias);
7425
+ switch (tokenData.service_type) {
7426
+ case STANDALONE_3DS_GATEWAYS.GPAYMENTS:
7427
+ new GPaymentsService(this.container, api, this.eventEmitter).load(tokenData, options.title);
7428
+ break;
7429
+ }
7430
+ }
7431
+ }, {
7432
+ key: "setEnv",
7433
+ value: function setEnv(env, alias) {
7434
+ this.env = env;
7435
+ this.alias = alias;
7436
+ }
7437
+ }]);
7438
+ return Standalone3dsService;
7439
+ }();
7440
+
6829
7441
  /**
6830
7442
  * List of available token's content formats
6831
7443
  * @enum TOKEN_FORMAT
@@ -6837,6 +7449,7 @@
6837
7449
  (function (TOKEN_FORMAT) {
6838
7450
  TOKEN_FORMAT["HTML"] = "html";
6839
7451
  TOKEN_FORMAT["URL"] = "url";
7452
+ TOKEN_FORMAT["STANDALONE_3DS"] = "standalone_3ds";
6840
7453
  })(TOKEN_FORMAT || (TOKEN_FORMAT = {}));
6841
7454
  /**
6842
7455
  * List of available event's name
@@ -6849,6 +7462,17 @@
6849
7462
  * @param {string} ADDITIONAL_DATA_REJECT=additionalDataCollectReject
6850
7463
  * @param {string} CHARGE_AUTH=chargeAuth
6851
7464
  */
7465
+ /**
7466
+ * List of available event's name for Standalone 3ds flow
7467
+ * @const STANDALONE_3DS_EVENT
7468
+ *
7469
+ * @type {object}
7470
+ * @param {string} CHARGE_AUTH_SUCCESS=chargeAuthSuccess
7471
+ * @param {string} CHARGE_AUTH_REJECT=chargeAuthReject
7472
+ * @param {string} CHARGE_AUTH_DECOUPLED=chargeAuthDecoupled
7473
+ * @param {string} CHARGE_AUTH_CHALLENGE=chargeAuthChallenge
7474
+ * @param {string} ERROR=error
7475
+ */
6852
7476
  /**
6853
7477
  * Class Canvas3ds include method for working on html
6854
7478
  * @constructor
@@ -6870,6 +7494,8 @@
6870
7494
  this.link.setParams({ ref_id: this.token.charge_3ds_id });
6871
7495
  this.container = new Container(selector);
6872
7496
  this.iFrame = new IFrame(this.container);
7497
+ this.eventEmitter = new EventEmitter();
7498
+ this.standalone3dsService = new Standalone3dsService(this.container, this.eventEmitter);
6873
7499
  this.event = new IFrameEvent(window);
6874
7500
  }
6875
7501
 
@@ -6881,7 +7507,7 @@
6881
7507
  *
6882
7508
  */
6883
7509
  value: function load() {
6884
- if (this.token.format === TOKEN_FORMAT.HTML) this.iFrame.loadFromHtml(this.token.content, { title: '3d secure authentication' });else if (this.token.format === TOKEN_FORMAT.URL) this.iFrame.load(this.token.content, { title: '3d secure authentication' });else console.error('Token contain unsupported payload');
7510
+ if (this.token.format === TOKEN_FORMAT.HTML) this.iFrame.loadFromHtml(this.token.content, { title: '3d secure authentication' });else if (this.token.format === TOKEN_FORMAT.URL) this.iFrame.load(this.token.content, { title: '3d secure authentication' });else if (this.token.format === TOKEN_FORMAT.STANDALONE_3DS) this.standalone3dsService.load(this.token.content, { title: '3d secure authentication' });else console.error('Token contain unsupported payload');
6885
7511
  }
6886
7512
  /**
6887
7513
  * Current method can change environment. By default environment = sandbox.
@@ -6897,6 +7523,7 @@
6897
7523
  key: 'setEnv',
6898
7524
  value: function setEnv(env, alias) {
6899
7525
  this.link.setEnv(env, alias);
7526
+ this.standalone3dsService.setEnv(env, alias);
6900
7527
  for (var index in this.configs) {
6901
7528
  if (!this.configs.hasOwnProperty(index)) continue;
6902
7529
  this.configs[index].setEnv(env, alias);
@@ -6919,7 +7546,7 @@
6919
7546
  * widget.on('chargeAuthReject').then(function (data) {
6920
7547
  * console.log(data);
6921
7548
  * });
6922
- * @param {string} eventName - Available event names [EVENT]{@link EVENT}
7549
+ * @param {string} eventName - Available event names [EVENT]{@link EVENT} [STANDALONE_3DS_EVENT]{@link STANDALONE_3DS_EVENT}
6923
7550
  * @param {listener} [cb]
6924
7551
  * @return {Promise<IEventData> | void}
6925
7552
  */
@@ -6929,12 +7556,21 @@
6929
7556
  value: function on(eventName, cb) {
6930
7557
  var _this = this;
6931
7558
 
6932
- if (typeof cb === 'function') return this.event.on(eventName, this.link.getParams().ref_id, cb);
6933
- return new Promise(function (resolve) {
6934
- return _this.event.on(eventName, _this.link.getParams().ref_id, function (res) {
6935
- return resolve(res);
7559
+ if (this.token.format === TOKEN_FORMAT.STANDALONE_3DS) {
7560
+ if (typeof cb === 'function') return this.eventEmitter.subscribe(eventName, cb);
7561
+ return new Promise(function (resolve) {
7562
+ return _this.eventEmitter.subscribe(eventName, function (res) {
7563
+ return resolve(res);
7564
+ });
6936
7565
  });
6937
- });
7566
+ } else {
7567
+ if (typeof cb === 'function') return this.event.on(eventName, this.link.getParams().ref_id, cb);
7568
+ return new Promise(function (resolve) {
7569
+ return _this.event.on(eventName, _this.link.getParams().ref_id, function (res) {
7570
+ return resolve(res);
7571
+ });
7572
+ });
7573
+ }
6938
7574
  }
6939
7575
  /**
6940
7576
  * Using this method you can hide widget after load