@paydock/client-sdk 1.84.10 → 1.86.5-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.
package/README.md CHANGED
@@ -5477,7 +5477,7 @@ Also, for **ApplePay via MPGS** you can initialize the `ApplePayPaymentRequest`
5477
5477
 
5478
5478
  <dl>
5479
5479
  <dt><a href="#WalletButtons">WalletButtons</a></dt>
5480
- <dd><p>Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)</p>
5480
+ <dd><p>Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal, Afterpay)</p>
5481
5481
  </dd>
5482
5482
  </dl>
5483
5483
 
@@ -5578,7 +5578,7 @@ Interface of Shipping Options for PayPal
5578
5578
  <a name="WalletButtons" id="WalletButtons" href="#WalletButtons">&nbsp;</a>
5579
5579
 
5580
5580
  ## WalletButtons
5581
- Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)
5581
+ Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal, Afterpay)
5582
5582
 
5583
5583
  **Kind**: global class
5584
5584
 
@@ -1643,7 +1643,9 @@
1643
1643
  CHARGE_AUTH_CANCELLED: 'chargeAuthCancelled',
1644
1644
  ADDITIONAL_DATA_SUCCESS: 'additionalDataCollectSuccess',
1645
1645
  ADDITIONAL_DATA_REJECT: 'additionalDataCollectReject',
1646
- CHARGE_AUTH: 'chargeAuth'
1646
+ CHARGE_AUTH: 'chargeAuth',
1647
+ DISPATCH_SUCCESS: 'dispatchSuccess',
1648
+ DISPATCH_ERROR: 'dispatchError'
1647
1649
  };
1648
1650
  var IFrameEvent = function () {
1649
1651
  function IFrameEvent(subject) {
@@ -1685,6 +1687,11 @@
1685
1687
  }
1686
1688
  }
1687
1689
  }
1690
+ }, {
1691
+ key: 'clear',
1692
+ value: function clear() {
1693
+ this.listeners = [];
1694
+ }
1688
1695
  }, {
1689
1696
  key: 'subscribe',
1690
1697
  value: function subscribe(subject, listener) {
@@ -4485,17 +4492,18 @@
4485
4492
  };
4486
4493
  this.env = new Env(WIDGET_URL);
4487
4494
  this.defaultPayload.source = messageSource;
4495
+ this.iframeEvent = new IFrameEvent(window);
4488
4496
  }
4489
4497
 
4490
4498
  createClass(StorageDispatcher, [{
4491
4499
  key: 'create',
4492
- value: function create() {
4493
- var reset = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
4494
-
4495
- if (this.dispatcherFrame && !reset) return this.dispatcherFrame;
4500
+ value: function create(onLoadCallback) {
4501
+ this.onLoadCallback = onLoadCallback;
4496
4502
  if (this.dispatcherFrame) this.destroy();
4503
+ this.widgetId = Uuid.generate();
4504
+ this.setupIframeEventListeners();
4497
4505
  var iFrame = document.createElement('iframe');
4498
- iFrame.setAttribute('src', this.env.getConf().url + STORAGE_DISPATCHER_URI);
4506
+ iFrame.setAttribute('src', this.env.getConf().url + STORAGE_DISPATCHER_URI + ('?widgetId=' + this.widgetId));
4499
4507
  iFrame.setAttribute('id', STORAGE_DISPATCHER_ID);
4500
4508
  iFrame.style.display = 'none';
4501
4509
  document.body.appendChild(iFrame);
@@ -4508,13 +4516,16 @@
4508
4516
  value: function destroy() {
4509
4517
  if (this.dispatcherFrame && this.dispatcherFrame.parentNode) {
4510
4518
  this.dispatcherFrame.parentNode.removeChild(this.dispatcherFrame);
4511
- this.dispatcherFrame = undefined;
4512
4519
  }
4520
+ this.iframeEvent.clear();
4521
+ this.widgetId = undefined;
4522
+ this.dispatcherFrame = undefined;
4513
4523
  }
4514
4524
  }, {
4515
4525
  key: 'push',
4516
- value: function push(payload) {
4526
+ value: function push(payload, pushCallbacks) {
4517
4527
  var _a;
4528
+ this.pushCallbacks = pushCallbacks;
4518
4529
  if (!this.dispatcherFrame) {
4519
4530
  console.error(LOG_PREFIX$1 + ' dispatcher is not initialized.');
4520
4531
  return;
@@ -4526,7 +4537,26 @@
4526
4537
  key: 'setEnv',
4527
4538
  value: function setEnv(env, alias) {
4528
4539
  this.env.setEnv(env, alias);
4529
- this.create(true);
4540
+ this.create(this.onLoadCallback);
4541
+ }
4542
+ }, {
4543
+ key: 'setupIframeEventListeners',
4544
+ value: function setupIframeEventListeners() {
4545
+ var _this = this;
4546
+
4547
+ if (!this.widgetId) return;
4548
+ this.iframeEvent.on(EVENT.AFTER_LOAD, this.widgetId, function (_event) {
4549
+ var _a;
4550
+ (_a = _this.onLoadCallback) === null || _a === void 0 ? void 0 : _a.call(_this);
4551
+ });
4552
+ this.iframeEvent.on(EVENT.DISPATCH_SUCCESS, this.widgetId, function (_event) {
4553
+ var _a, _b;
4554
+ (_b = (_a = _this.pushCallbacks) === null || _a === void 0 ? void 0 : _a.onSuccess) === null || _b === void 0 ? void 0 : _b.call(_a);
4555
+ });
4556
+ this.iframeEvent.on(EVENT.DISPATCH_ERROR, this.widgetId, function (_event) {
4557
+ var _a, _b;
4558
+ (_b = (_a = _this.pushCallbacks) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a);
4559
+ });
4530
4560
  }
4531
4561
  }]);
4532
4562
  return StorageDispatcher;
@@ -4552,18 +4582,27 @@
4552
4582
  }, {
4553
4583
  key: 'next',
4554
4584
  value: function next(checkout, params) {
4555
- this.storageDispatcher.create();
4556
- var widgetSessionData = {
4557
- merchant_redirect_url: this.getRedirectUrl(),
4558
- checkout_token: checkout.token,
4559
- public_key: params.public_key,
4560
- gateway_id: params.gateway_id
4561
- };
4562
- this.storageDispatcher.push({ intent: StorageDataIntent.WIDGET_SESSION, data: widgetSessionData });
4563
- var checkoutUri = this.getCheckoutUri(checkout.link);
4564
- Zip.Checkout.init({
4565
- checkoutUri: checkoutUri,
4566
- redirect: true
4585
+ var _this2 = this;
4586
+
4587
+ this.storageDispatcher.create(function () {
4588
+ var widgetSessionData = {
4589
+ merchant_redirect_url: _this2.getRedirectUrl(),
4590
+ checkout_token: checkout.token,
4591
+ public_key: params.public_key,
4592
+ gateway_id: params.gateway_id
4593
+ };
4594
+ _this2.storageDispatcher.push({ intent: StorageDataIntent.WIDGET_SESSION, data: widgetSessionData }, {
4595
+ onSuccess: function onSuccess() {
4596
+ var checkoutUri = _this2.getCheckoutUri(checkout.link);
4597
+ Zip.Checkout.init({
4598
+ checkoutUri: checkoutUri,
4599
+ redirect: true
4600
+ });
4601
+ },
4602
+ onError: function onError() {
4603
+ console.error('Error initializing Zip Checkout');
4604
+ }
4605
+ });
4567
4606
  });
4568
4607
  }
4569
4608
  // for backward compatibility
@@ -6504,25 +6543,28 @@
6504
6543
  value: function onPaymentAuthorized(paymentData) {
6505
6544
  var _this4 = this;
6506
6545
 
6507
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
6546
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
6508
6547
  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;
6509
6548
  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;
6510
6549
  var shippingAddressLine1 = (_g = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _g === void 0 ? void 0 : _g.address1;
6511
6550
  var shippingAddressLine2 = (_h = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _h === void 0 ? void 0 : _h.address2;
6512
6551
  var shippingOptionMethod = (_j = this.selectedShippingOption) === null || _j === void 0 ? void 0 : _j.type;
6552
+ var shippingAddressCountry = (_k = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _k === void 0 ? void 0 : _k.countryCode;
6553
+ var shippingAddressCity = (_l = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _l === void 0 ? void 0 : _l.locality;
6554
+ var shippingAddressPostCode = (_m = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _m === void 0 ? void 0 : _m.postalCode;
6555
+ var shippingAddressState = (_o = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _o === void 0 ? void 0 : _o.administrativeArea;
6556
+ var shippingContactFirstName = (_p = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _p === void 0 ? void 0 : _p.name;
6557
+ var shippingContactEmail = paymentData === null || paymentData === void 0 ? void 0 : paymentData.email;
6558
+ var shippingContactPhone = (_q = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _q === void 0 ? void 0 : _q.phoneNumber;
6513
6559
  return new Promise(function (resolve) {
6514
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
6560
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
6515
6561
  return _this4.eventEmitter.emit(WALLET_EVENT.PAYMENT_METHOD_SELECTED, {
6516
6562
  data: _extends({ customer: {
6517
6563
  payment_source: _extends(_extends(_extends(_extends({ wallet_type: WALLET_TYPE.GOOGLE,
6518
6564
  // card_name: paymentData.shippingAddress?.name, // TODO: Do we want to use this value? Point 2 at https://paydock.atlassian.net/browse/P2-7209?focusedCommentId=60202
6519
6565
  type: paymentData.paymentMethodData.type, card_scheme: (_b = (_a = paymentData.paymentMethodData) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.cardNetwork }, billingAddressLine1 && { address_line1: billingAddressLine1 }), billingAddressLine2 && { address_line2: billingAddressLine2 }), billingAddressLine2 && { address_line2: billingAddressLine2 }), { address_country: (_e = (_d = (_c = paymentData.paymentMethodData) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.billingAddress) === null || _e === void 0 ? void 0 : _e.countryCode, address_city: (_h = (_g = (_f = paymentData.paymentMethodData) === null || _f === void 0 ? void 0 : _f.info) === null || _g === void 0 ? void 0 : _g.billingAddress) === null || _h === void 0 ? void 0 : _h.locality, address_postcode: (_l = (_k = (_j = paymentData.paymentMethodData) === null || _j === void 0 ? void 0 : _j.info) === null || _k === void 0 ? void 0 : _k.billingAddress) === null || _l === void 0 ? void 0 : _l.postalCode, address_state: (_p = (_o = (_m = paymentData.paymentMethodData) === null || _m === void 0 ? void 0 : _m.info) === null || _o === void 0 ? void 0 : _o.billingAddress) === null || _p === void 0 ? void 0 : _p.administrativeArea, ref_token: paymentData.paymentMethodData.tokenizationData.token })
6520
6566
  } }, _this4.isShippingRequired() && {
6521
- 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: (_q = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _q === void 0 ? void 0 : _q.countryCode, address_city: (_r = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _r === void 0 ? void 0 : _r.locality, address_postcode: (_s = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _s === void 0 ? void 0 : _s.postalCode, address_state: (_t = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _t === void 0 ? void 0 : _t.administrativeArea, contact: {
6522
- first_name: (_u = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _u === void 0 ? void 0 : _u.name,
6523
- email: paymentData === null || paymentData === void 0 ? void 0 : paymentData.email,
6524
- phone: (_v = paymentData === null || paymentData === void 0 ? void 0 : paymentData.shippingAddress) === null || _v === void 0 ? void 0 : _v.phoneNumber
6525
- } })
6567
+ shipping: _extends(_extends(_extends(_extends(_extends(_extends(_extends(_extends(_extends({}, shippingOptionMethod && { method: shippingOptionMethod }), _this4.hasShippingOptions() && { options: _this4.meta.shipping_options }), shippingAddressLine1 && { address_line1: shippingAddressLine1 }), shippingAddressLine2 && { address_line2: shippingAddressLine2 }), shippingAddressCountry && { address_country: shippingAddressCountry }), shippingAddressCity && { address_city: shippingAddressCity }), shippingAddressPostCode && { address_postcode: shippingAddressPostCode }), shippingAddressState && { address_state: shippingAddressState }), { contact: _extends(_extends(_extends({}, shippingContactFirstName && { first_name: shippingContactFirstName }), shippingContactEmail && { email: shippingContactEmail }), shippingContactPhone && { phone: shippingContactPhone }) })
6526
6568
  }),
6527
6569
  onSuccess: function onSuccess() {
6528
6570
  return resolve({ transactionState: 'SUCCESS' });
@@ -6868,8 +6910,11 @@
6868
6910
  createClass(AfterPayWalletService, [{
6869
6911
  key: 'load',
6870
6912
  value: function load(container) {
6871
- this.storageDispatcher.create();
6872
- this.mount(container);
6913
+ var _this2 = this;
6914
+
6915
+ this.storageDispatcher.create(function () {
6916
+ return _this2.mount(container);
6917
+ });
6873
6918
  }
6874
6919
  }, {
6875
6920
  key: 'setEnv',
@@ -6881,14 +6926,14 @@
6881
6926
  }, {
6882
6927
  key: 'mount',
6883
6928
  value: function mount(container) {
6884
- var _this2 = this;
6929
+ var _this3 = this;
6885
6930
 
6886
6931
  var _a, _b, _c, _d;
6887
6932
  var customStyles = {};
6888
6933
  if (((_a = this.meta) === null || _a === void 0 ? void 0 : _a.style) && _typeof((_b = this.meta) === null || _b === void 0 ? void 0 : _b.style) === 'object') customStyles = JSON.parse(JSON.stringify(((_c = this.meta) === null || _c === void 0 ? void 0 : _c.style['afterpay']) || ((_d = this.meta) === null || _d === void 0 ? void 0 : _d.style)));
6889
6934
  var afterpayButton = this.getButton(customStyles);
6890
6935
  afterpayButton.onclick = function () {
6891
- return _this2.onAfterPayButtonClicked();
6936
+ return _this3.onAfterPayButtonClicked();
6892
6937
  };
6893
6938
  var buttonWalletStyle = this.getButtonStyle(customStyles);
6894
6939
  container.getElement().appendChild(afterpayButton);
@@ -6897,40 +6942,46 @@
6897
6942
  }, {
6898
6943
  key: 'onAfterPayButtonClicked',
6899
6944
  value: function onAfterPayButtonClicked() {
6900
- var _this3 = this;
6945
+ var _this4 = this;
6901
6946
 
6902
- this.storageDispatcher.push({ intent: StorageDataIntent.WIDGET_SESSION, data: { token: this.token } });
6903
- return new Promise(function () {
6904
- var _a, _b;
6905
- var afterpayJS = document.createElement('script');
6906
- var countryCode = (_a = _this3.meta) === null || _a === void 0 ? void 0 : _a.country;
6907
- afterpayJS.type = 'text/javascript';
6908
- afterpayJS.src = ((_b = _this3.meta) === null || _b === void 0 ? void 0 : _b.gateway_mode) === 'live' ? 'https://portal.afterpay.com/afterpay.js' : 'https://portal.sandbox.afterpay.com/afterpay.js';
6909
- afterpayJS.async = true;
6910
- afterpayJS.defer = true;
6911
- afterpayJS.onload = function () {
6912
- window.AfterPay.initialize({ countryCode: countryCode });
6913
- _this3.getCheckoutSession().then(function (response) {
6914
- window.AfterPay.redirect({
6915
- token: response.ref_token
6947
+ var _a, _b;
6948
+ var afterpayJS = document.createElement('script');
6949
+ var countryCode = (_a = this.meta) === null || _a === void 0 ? void 0 : _a.country;
6950
+ afterpayJS.type = 'text/javascript';
6951
+ afterpayJS.src = ((_b = this.meta) === null || _b === void 0 ? void 0 : _b.gateway_mode) === 'live' ? 'https://portal.afterpay.com/afterpay.js' : 'https://portal.sandbox.afterpay.com/afterpay.js';
6952
+ afterpayJS.async = true;
6953
+ afterpayJS.defer = true;
6954
+ afterpayJS.onload = function () {
6955
+ window.AfterPay.initialize({ countryCode: countryCode });
6956
+ _this4.storageDispatcher.push({ intent: StorageDataIntent.WIDGET_SESSION, data: { token: _this4.token } }, {
6957
+ onSuccess: function onSuccess() {
6958
+ _this4.getCheckoutSession().then(function (response) {
6959
+ window.AfterPay.redirect({
6960
+ token: response.ref_token
6961
+ });
6962
+ }).catch(function (err) {
6963
+ window.AfterPay.close();
6964
+ _this4.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, {
6965
+ err: err
6966
+ });
6916
6967
  });
6917
- }).catch(function (err) {
6968
+ },
6969
+ onError: function onError() {
6970
+ console.error('Error initializing Afterpay wallet');
6918
6971
  window.AfterPay.close();
6919
- _this3.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, {
6920
- err: err
6921
- });
6922
- });
6923
- };
6924
- document.head.appendChild(afterpayJS);
6925
- });
6972
+ _this4.eventEmitter.emit(WALLET_EVENT.UNAVAILABLE, {});
6973
+ }
6974
+ });
6975
+ };
6976
+ document.head.appendChild(afterpayJS);
6926
6977
  }
6927
6978
  }, {
6928
6979
  key: 'getCheckoutSession',
6929
6980
  value: function getCheckoutSession() {
6930
- var _this4 = this;
6981
+ var _this5 = this;
6931
6982
 
6932
6983
  return new Promise(function (resolve, reject) {
6933
- return _this4.eventEmitter.emit(WALLET_EVENT.CALLBACK, {
6984
+ return _this5.eventEmitter.emit(WALLET_EVENT.CALLBACK, {
6934
6985
  data: {
6935
6986
  request_type: 'CREATE_SESSION',
6936
6987
  wallet_type: WALLET_TYPE.AFTERPAY
@@ -7057,7 +7108,7 @@
7057
7108
  * @param {string} [type] Type of the Shipping Option. Values can be 'SHIPPING' or 'PICKUP'. Required.
7058
7109
  */
7059
7110
  /**
7060
- * Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal)
7111
+ * Class WalletButtons to work with different E-Wallets within html (currently supports Apple Pay, Google Pay, Google Pay™ and Apple Pay via Stripe, Flypay, Paypal, Afterpay)
7061
7112
  * @constructor
7062
7113
  *
7063
7114
  * @example