@paydock/client-sdk 1.115.0 → 1.116.2

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 +531 -40
  2. package/bundles/index.cjs +515 -87
  3. package/bundles/index.cjs.d.ts +214 -1
  4. package/bundles/index.mjs +514 -88
  5. package/bundles/index.mjs.d.ts +214 -1
  6. package/bundles/types/api/api-charge-internal.d.ts +1 -0
  7. package/bundles/types/api/api-charge-internal.d.ts.map +1 -1
  8. package/bundles/types/checkout/instructions/v1/instruction.generic.show_message.d.ts.map +1 -1
  9. package/bundles/types/checkout/layout-widgets/payment-methods.d.ts +0 -1
  10. package/bundles/types/checkout/layout-widgets/payment-methods.d.ts.map +1 -1
  11. package/bundles/types/index-cba.d.ts +2 -0
  12. package/bundles/types/index-cba.d.ts.map +1 -1
  13. package/bundles/types/index.d.ts +2 -0
  14. package/bundles/types/index.d.ts.map +1 -1
  15. package/bundles/types/paypal-data-collector/index.d.ts +23 -0
  16. package/bundles/types/paypal-data-collector/index.d.ts.map +1 -0
  17. package/bundles/types/paypal-data-collector/paypal-data-collector.d.ts +58 -0
  18. package/bundles/types/paypal-data-collector/paypal-data-collector.d.ts.map +1 -0
  19. package/bundles/types/paypal-data-collector/paypal-data-collector.interfaces.d.ts +21 -0
  20. package/bundles/types/paypal-data-collector/paypal-data-collector.interfaces.d.ts.map +1 -0
  21. package/bundles/types/paypal-data-collector/paypal-data-collector.service.d.ts +17 -0
  22. package/bundles/types/paypal-data-collector/paypal-data-collector.service.d.ts.map +1 -0
  23. package/bundles/types/paypal-save-payment-source/index.d.ts +61 -0
  24. package/bundles/types/paypal-save-payment-source/index.d.ts.map +1 -0
  25. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.d.ts +85 -0
  26. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.d.ts.map +1 -0
  27. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.interfaces.d.ts +84 -0
  28. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.interfaces.d.ts.map +1 -0
  29. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.service.d.ts +36 -0
  30. package/bundles/types/paypal-save-payment-source/paypal-save-payment-source.service.d.ts.map +1 -0
  31. package/bundles/types/secure-remote-commerce/index.d.ts +0 -1
  32. package/bundles/types/secure-remote-commerce/index.d.ts.map +1 -1
  33. package/bundles/types/secure-remote-commerce/interfaces.d.ts +1 -5
  34. package/bundles/types/secure-remote-commerce/interfaces.d.ts.map +1 -1
  35. package/bundles/types/secure-remote-commerce/providers/mastercard-src/mastercard-src.d.ts.map +1 -1
  36. package/bundles/types/wallet-buttons-express/base.wallet-button-express.d.ts.map +1 -1
  37. package/bundles/types/wallet-buttons-express/interfaces/wallet-capture-request.interface.d.ts +1 -0
  38. package/bundles/types/wallet-buttons-express/interfaces/wallet-capture-request.interface.d.ts.map +1 -1
  39. package/bundles/types/wallet-buttons-express/services/apple-pay/apple-pay.wallet-button-express.d.ts.map +1 -1
  40. package/bundles/types/wallet-buttons-express/services/paypal/paypal.wallet-button-express.d.ts.map +1 -1
  41. package/bundles/widget.umd.js +515 -87
  42. package/bundles/widget.umd.js.d.ts +214 -1
  43. package/bundles/widget.umd.js.min.d.ts +214 -1
  44. package/bundles/widget.umd.min.js +7 -7
  45. package/docs/click-to-pay-examples.md +0 -36
  46. package/docs/click-to-pay.md +0 -3
  47. package/docs/paypal-data-collector-examples.md +58 -0
  48. package/docs/paypal-data-collector.md +149 -0
  49. package/docs/paypal-save-payment-source-examples.md +63 -0
  50. package/docs/paypal-save-payment-source.md +256 -0
  51. package/docs/wallet-buttons-express-examples.md +1 -1
  52. package/package.json +1 -1
  53. package/slate.md +0 -36
package/bundles/index.mjs CHANGED
@@ -889,7 +889,7 @@ SDK.headerKeys = Object.freeze({
889
889
  version: 'x-sdk-version',
890
890
  type: 'x-sdk-type'
891
891
  });
892
- SDK._version = 'v1.115.0';
892
+ SDK._version = 'v1.116.2';
893
893
 
894
894
  /******************************************************************************
895
895
  Copyright (c) Microsoft Corporation.
@@ -9105,8 +9105,6 @@ var HtmlPaymentSourceWidget = /*#__PURE__*/function (_PaymentSourceWidget) {
9105
9105
  * @param {string} CHECKOUT_POPUP_CLOSE=checkoutPopupClose Event sent when Click To Pay checkout flow is closed, regardless of embedded or windowed mode.
9106
9106
  * @param {string} CHECKOUT_COMPLETED=checkoutCompleted Event sent on successful checkout by customer. Check [data](#EventDataCheckoutCompletedData) for more information.
9107
9107
  * @param {string} CHECKOUT_ERROR=checkoutError Event sent on error checkout by customer. Check [data](#EventData) for more information.
9108
- * @param {string} RECOGNITION_TOKEN_REQUESTED=recognitionTokenRequested Event sent when a recognition token was found on the mastercard SDK response.
9109
- * @param {string} RECOGNITION_TOKEN_DROPPED=recognitionTokenDropped Event sent when a recognition token needs to be dropped for user be no longer remembered.
9110
9108
  */
9111
9109
  var EVENT$3;
9112
9110
  (function (EVENT) {
@@ -9116,8 +9114,6 @@ var EVENT$3;
9116
9114
  EVENT["CHECKOUT_ERROR"] = "checkoutError";
9117
9115
  EVENT["CHECKOUT_POPUP_OPEN"] = "checkoutPopupOpen";
9118
9116
  EVENT["CHECKOUT_POPUP_CLOSE"] = "checkoutPopupClose";
9119
- EVENT["RECOGNITION_TOKEN_REQUESTED"] = "recognitionTokenRequested";
9120
- EVENT["RECOGNITION_TOKEN_DROPPED"] = "recognitionTokenDropped";
9121
9117
  })(EVENT$3 || (EVENT$3 = {}));
9122
9118
  /**
9123
9119
  * List of available event data types
@@ -9194,13 +9190,6 @@ var ClickToPaySRC = /*#__PURE__*/function () {
9194
9190
  var data = _ref5.data;
9195
9191
  _this.eventEmitter.emit(EVENT$3.CHECKOUT_ERROR, data);
9196
9192
  });
9197
- this.iFrameEvent.on(EVENT$3.RECOGNITION_TOKEN_REQUESTED, widgetId, function (_ref6) {
9198
- var data = _ref6.data;
9199
- _this.eventEmitter.emit(EVENT$3.RECOGNITION_TOKEN_REQUESTED, data);
9200
- });
9201
- this.iFrameEvent.on(EVENT$3.RECOGNITION_TOKEN_DROPPED, widgetId, function () {
9202
- _this.eventEmitter.emit(EVENT$3.RECOGNITION_TOKEN_DROPPED);
9203
- });
9204
9193
  if (this.autoResize) this.useAutoResize(true);
9205
9194
  }
9206
9195
  }, {
@@ -9248,8 +9237,8 @@ var ClickToPaySRC = /*#__PURE__*/function () {
9248
9237
  this.autoResize = true;
9249
9238
  var params = this.link.getParams();
9250
9239
  if (!(params === null || params === void 0 ? void 0 : params.widget_id)) return;
9251
- this.iFrameEvent.on('resize', params.widget_id, function (_ref7) {
9252
- var data = _ref7.data;
9240
+ this.iFrameEvent.on('resize', params.widget_id, function (_ref6) {
9241
+ var data = _ref6.data;
9253
9242
  var _a, _b;
9254
9243
  var iframeElement = _this3.iFrame.getElement();
9255
9244
  if (iframeElement) {
@@ -14699,7 +14688,7 @@ var PaymentMethods = /*#__PURE__*/function () {
14699
14688
  _iterator.s();
14700
14689
  case 4:
14701
14690
  if ((_step = _iterator.n()).done) {
14702
- _context.next = 18;
14691
+ _context.next = 11;
14703
14692
  break;
14704
14693
  }
14705
14694
  method = _step.value;
@@ -14707,46 +14696,30 @@ var PaymentMethods = /*#__PURE__*/function () {
14707
14696
  _context.next = 8;
14708
14697
  break;
14709
14698
  }
14710
- return _context.abrupt("continue", 16);
14699
+ return _context.abrupt("continue", 9);
14711
14700
  case 8:
14712
- _context.t0 = method === PAYMENTS_METHODS.GOOGLE_PAY;
14713
- if (!_context.t0) {
14714
- _context.next = 13;
14715
- break;
14716
- }
14717
- _context.next = 12;
14718
- return this.isGooglePaySupported();
14719
- case 12:
14720
- _context.t0 = !_context.sent;
14721
- case 13:
14722
- if (!_context.t0) {
14723
- _context.next = 15;
14724
- break;
14725
- }
14726
- return _context.abrupt("continue", 16);
14727
- case 15:
14728
14701
  paymentMethodsAllowed.push(PAYMENT_METHOD[method]);
14729
- case 16:
14702
+ case 9:
14730
14703
  _context.next = 4;
14731
14704
  break;
14732
- case 18:
14733
- _context.next = 23;
14705
+ case 11:
14706
+ _context.next = 16;
14734
14707
  break;
14735
- case 20:
14736
- _context.prev = 20;
14737
- _context.t1 = _context["catch"](2);
14738
- _iterator.e(_context.t1);
14739
- case 23:
14740
- _context.prev = 23;
14708
+ case 13:
14709
+ _context.prev = 13;
14710
+ _context.t0 = _context["catch"](2);
14711
+ _iterator.e(_context.t0);
14712
+ case 16:
14713
+ _context.prev = 16;
14741
14714
  _iterator.f();
14742
- return _context.finish(23);
14743
- case 26:
14715
+ return _context.finish(16);
14716
+ case 19:
14744
14717
  resolve(paymentMethodsAllowed.join(' '));
14745
- case 27:
14718
+ case 20:
14746
14719
  case "end":
14747
14720
  return _context.stop();
14748
14721
  }
14749
- }, _callee, this, [[2, 20, 23, 26]]);
14722
+ }, _callee, this, [[2, 13, 16, 19]]);
14750
14723
  }));
14751
14724
  });
14752
14725
  initState.then(function (content) {
@@ -14812,45 +14785,6 @@ var PaymentMethods = /*#__PURE__*/function () {
14812
14785
  value: function isApplePaySupported() {
14813
14786
  return window.ApplePaySession && ApplePaySession.canMakePayments();
14814
14787
  }
14815
- }, {
14816
- key: "isGooglePaySupported",
14817
- value: function isGooglePaySupported() {
14818
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
14819
- var paymentRequest;
14820
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
14821
- while (1) switch (_context2.prev = _context2.next) {
14822
- case 0:
14823
- _context2.prev = 0;
14824
- if (window.PaymentRequest) {
14825
- _context2.next = 3;
14826
- break;
14827
- }
14828
- return _context2.abrupt("return", false);
14829
- case 3:
14830
- paymentRequest = new PaymentRequest([{
14831
- supportedMethods: 'https://google.com/pay'
14832
- }], {
14833
- total: {
14834
- label: 'Test',
14835
- amount: {
14836
- currency: 'USD',
14837
- value: '0.00'
14838
- }
14839
- }
14840
- });
14841
- return _context2.abrupt("return", paymentRequest.canMakePayment());
14842
- case 7:
14843
- _context2.prev = 7;
14844
- _context2.t0 = _context2["catch"](0);
14845
- console.error('Error google pay check support:');
14846
- return _context2.abrupt("return", false);
14847
- case 11:
14848
- case "end":
14849
- return _context2.stop();
14850
- }
14851
- }, _callee2, null, [[0, 7]]);
14852
- }));
14853
- }
14854
14788
  }, {
14855
14789
  key: "setStylesToStandaloneWidget",
14856
14790
  value: function setStylesToStandaloneWidget() {
@@ -14985,8 +14919,8 @@ var InstructionGenericShowMessage = /*#__PURE__*/function (_InstructionHandler)
14985
14919
  }, {
14986
14920
  key: "destroy",
14987
14921
  value: function destroy() {
14988
- clearTimeout(this.timeoutId);
14989
14922
  // TODO: Adjust when implementing the failure payment flow
14923
+ // clearTimeout(this.timeoutId);
14990
14924
  // document.querySelector(this.formSelector).innerHTML = '';
14991
14925
  }
14992
14926
  }]);
@@ -16046,7 +15980,8 @@ var ApplePayWalletButtonExpress = /*#__PURE__*/function (_BaseWalletButton) {
16046
15980
  address_city: billingContact === null || billingContact === void 0 ? void 0 : billingContact.locality,
16047
15981
  address_postcode: billingContact === null || billingContact === void 0 ? void 0 : billingContact.postalCode,
16048
15982
  address_state: billingContact === null || billingContact === void 0 ? void 0 : billingContact.administrativeArea,
16049
- ref_token: token.paymentData ? JSON.stringify(token.paymentData) : ''
15983
+ ref_token: token.paymentData ? JSON.stringify(token.paymentData) : '',
15984
+ wallet_express: true
16050
15985
  }
16051
15986
  }
16052
15987
  }).then(function () {
@@ -16329,7 +16264,8 @@ var PaypalWalletButtonExpress = /*#__PURE__*/function (_BaseWalletButton) {
16329
16264
  payment_method_id: data.orderID,
16330
16265
  customer: {
16331
16266
  payment_source: {
16332
- external_payer_id: data.payerID
16267
+ external_payer_id: data.payerID,
16268
+ wallet_express: true
16333
16269
  }
16334
16270
  }
16335
16271
  })["finally"](function () {
@@ -16349,6 +16285,496 @@ var PaypalWalletButtonExpress = /*#__PURE__*/function (_BaseWalletButton) {
16349
16285
  }]);
16350
16286
  }(BaseWalletButton);
16351
16287
 
16288
+ var PAYPAL_DATA_COLLECTOR_EVENTS;
16289
+ (function (PAYPAL_DATA_COLLECTOR_EVENTS) {
16290
+ PAYPAL_DATA_COLLECTOR_EVENTS["ON_ERROR"] = "ON_ERROR";
16291
+ })(PAYPAL_DATA_COLLECTOR_EVENTS || (PAYPAL_DATA_COLLECTOR_EVENTS = {}));
16292
+ var ErrorCodes$1;
16293
+ (function (ErrorCodes) {
16294
+ ErrorCodes["PROMISE_NOT_ENABLED"] = "promise_not_enabled";
16295
+ ErrorCodes["SCRIPT_ERROR"] = "script_error";
16296
+ })(ErrorCodes$1 || (ErrorCodes$1 = {}));
16297
+
16298
+ var PayPalDataCollectorService = /*#__PURE__*/function () {
16299
+ function PayPalDataCollectorService(eventEmitter, flowId, config) {
16300
+ _classCallCheck(this, PayPalDataCollectorService);
16301
+ this.eventEmitter = eventEmitter;
16302
+ this.flowId = flowId;
16303
+ this.config = config;
16304
+ }
16305
+ return _createClass(PayPalDataCollectorService, [{
16306
+ key: "collectDeviceData",
16307
+ value: function collectDeviceData() {
16308
+ if (!window.Promise) {
16309
+ this.eventEmitter.emit(PAYPAL_DATA_COLLECTOR_EVENTS.ON_ERROR, {
16310
+ error_code: ErrorCodes$1.PROMISE_NOT_ENABLED
16311
+ });
16312
+ }
16313
+ this.correlationId = Uuid.generate();
16314
+ return this.appendPaypalSavePaymentSourceComponent();
16315
+ }
16316
+ }, {
16317
+ key: "appendPaypalSavePaymentSourceComponent",
16318
+ value: function appendPaypalSavePaymentSourceComponent() {
16319
+ var _this = this;
16320
+ var paypalScript = document.createElement("script");
16321
+ paypalScript.type = "application/json";
16322
+ paypalScript.setAttribute("fncls", "fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99");
16323
+ var scriptContent = _extends(_extends({
16324
+ f: this.correlationId,
16325
+ s: this.flowId ? this.flowId : Uuid.generate(),
16326
+ cb1: 'paydockPayPalDataCollectorServiceCallbackPostOne',
16327
+ cb2: 'paydockPayPalDataCollectorServiceCallbackPostTwo'
16328
+ }, this.isSandbox && {
16329
+ sandbox: this.isSandbox
16330
+ }), this.config.mouse_movement && {
16331
+ mm: this.config.mouse_movement
16332
+ });
16333
+ paypalScript.textContent = JSON.stringify(scriptContent, null, 4);
16334
+ var fraudnetScript = document.createElement("script");
16335
+ fraudnetScript.type = "text/javascript";
16336
+ fraudnetScript.src = "https://c.paypal.com/da/r/fb.js";
16337
+ fraudnetScript.onerror = function () {
16338
+ return _this.onError();
16339
+ };
16340
+ document.body.appendChild(paypalScript);
16341
+ document.body.appendChild(fraudnetScript);
16342
+ return this.setupCallbacks();
16343
+ }
16344
+ }, {
16345
+ key: "setupCallbacks",
16346
+ value: function setupCallbacks() {
16347
+ var _this2 = this;
16348
+ return new Promise(function (resolve, reject) {
16349
+ var callbackOnePromise = new Promise(function (resolve) {
16350
+ window.paydockPayPalDataCollectorServiceCallbackPostOne = function () {
16351
+ resolve();
16352
+ };
16353
+ });
16354
+ var callbackTwoPromise = new Promise(function (resolve) {
16355
+ window.paydockPayPalDataCollectorServiceCallbackPostTwo = function () {
16356
+ resolve();
16357
+ };
16358
+ });
16359
+ Promise.all([callbackOnePromise, callbackTwoPromise]).then(function () {
16360
+ resolve({
16361
+ correlation_id: _this2.correlationId
16362
+ });
16363
+ })["catch"](reject);
16364
+ });
16365
+ }
16366
+ }, {
16367
+ key: "onError",
16368
+ value: function onError() {
16369
+ this.eventEmitter.emit(PAYPAL_DATA_COLLECTOR_EVENTS.ON_ERROR, {
16370
+ error_code: ErrorCodes$1.SCRIPT_ERROR
16371
+ });
16372
+ }
16373
+ }, {
16374
+ key: "setEnv",
16375
+ value: function setEnv(env) {
16376
+ this.isSandbox = env !== 'live';
16377
+ }
16378
+ }], [{
16379
+ key: "fromConfig",
16380
+ value: function fromConfig(eventEmitter, flowId, config) {
16381
+ return new PayPalDataCollectorService(eventEmitter, flowId, config);
16382
+ }
16383
+ }]);
16384
+ }();
16385
+
16386
+ /**
16387
+ * PayPal Data Collector Widget constructor
16388
+ *
16389
+ * @param {string} flowId - This string identifies the source website of the FraudNet request.
16390
+ * @param {PayPalDataCollectorConfig} config - Extra configuration for the widget.
16391
+ *
16392
+ * @example
16393
+ * var payPalDataCollector = new PayPalDataCollector('FLOW_ID', {});
16394
+ */
16395
+ var PayPalDataCollector = /*#__PURE__*/function () {
16396
+ /** @constructs */ // constructs added for correct parse classes jsdoc2md
16397
+ function PayPalDataCollector(flowId, config) {
16398
+ _classCallCheck(this, PayPalDataCollector);
16399
+ this.eventEmitter = new EventEmitter();
16400
+ this.service = PayPalDataCollectorService.fromConfig(this.eventEmitter, flowId, config);
16401
+ }
16402
+ /**
16403
+ * After configuring the PayPalDataCollector Widget, starts the process and returns
16404
+ * the correlation id used among the requests.
16405
+ *
16406
+ * @returns {Promise<CollectedDeviceData>} Promise when resolved, returnsa an object
16407
+ * that contains the `correlation_id` key.
16408
+ *
16409
+ * @example
16410
+ * const collectedDeviceData = await payPalDataCollectorWidget.collectDeviceData();
16411
+ * console.log(collectedDeviceData.correlation_id)
16412
+ */
16413
+ return _createClass(PayPalDataCollector, [{
16414
+ key: "collectDeviceData",
16415
+ value: function collectDeviceData() {
16416
+ try {
16417
+ return this.service.collectDeviceData();
16418
+ } catch (err) {
16419
+ this.eventEmitter.emit(PAYPAL_DATA_COLLECTOR_EVENTS.ON_ERROR, null);
16420
+ throw err;
16421
+ }
16422
+ }
16423
+ /**
16424
+ * Callback for onError method.
16425
+ *
16426
+ * @callback OnErrorCallback
16427
+ * @param {IOnErrorEventData|null} data
16428
+ */
16429
+ /**
16430
+ * If the process fails, the function passed as parameter will be called.
16431
+ * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
16432
+ *
16433
+ * @example
16434
+ * PayPalDataCollector.onError((eventData) => console.log('Some error occur'));
16435
+ *
16436
+ * @param {OnErrorCallback} [callback] - Function to be called when there is an error in the flow.
16437
+ */
16438
+ }, {
16439
+ key: "onError",
16440
+ value: function onError(callback) {
16441
+ return this.eventEmitter.subscribe(PAYPAL_DATA_COLLECTOR_EVENTS.ON_ERROR, callback);
16442
+ }
16443
+ /**
16444
+ * Current method can change environment. By default environment = test.
16445
+ * This method does not affect Paydock's API calls or environments, is only for PayPal Data Collector
16446
+ * script, in order to know if the script is injected on a live server or is a testing
16447
+ * environment. The available values are `test` and `live`. This should match with the used
16448
+ * `gateway.mode` in Paydock to process the transaction.
16449
+ *
16450
+ * @example
16451
+ * PayPalDataCollector.setEnv('live');
16452
+ * @param {string} env - test, live
16453
+ */
16454
+ }, {
16455
+ key: "setEnv",
16456
+ value: function setEnv(env) {
16457
+ this.service.setEnv(env);
16458
+ }
16459
+ }]);
16460
+ }();
16461
+
16462
+ var PAYPAL_SAVE_PAYMENT_EVENTS = {
16463
+ ON_SUCCESS: 'ON_SUCCESS',
16464
+ ON_ERROR: 'ON_ERROR',
16465
+ ON_CANCEL: 'ON_CANCEL'
16466
+ };
16467
+ var ErrorCodes;
16468
+ (function (ErrorCodes) {
16469
+ ErrorCodes["UNAVAILABLE"] = "unavailable";
16470
+ ErrorCodes["ON_PAYPAL_VAULT_SETUP_TOKEN_ERROR"] = "onPaypalVaultSetupTokenError";
16471
+ ErrorCodes["ON_GET_ID_TOKEN_ERROR"] = "onGetIdTokenError";
16472
+ ErrorCodes["ON_GET_WALLET_CONFIG_ERROR"] = "onGetWalletConfigError";
16473
+ ErrorCodes["ON_GET_SETUP_TOKEN_ERROR"] = "onGetSetupTokenError";
16474
+ ErrorCodes["ON_ONE_TIME_TOKEN_ERROR"] = "onOneTimeTokenError";
16475
+ })(ErrorCodes || (ErrorCodes = {}));
16476
+ var EVENTS;
16477
+ (function (EVENTS) {
16478
+ EVENTS["ON_SUCCESS"] = "ON_SUCCESS";
16479
+ EVENTS["ON_ERROR"] = "ON_ERROR";
16480
+ EVENTS["ON_CANCEL"] = "ON_CANCEL";
16481
+ })(EVENTS || (EVENTS = {}));
16482
+
16483
+ var PAYPAL_OAUTH_TOKEN_ROUTE = '/v1/payment_sources/oauth-tokens';
16484
+ var PAYPAL_SETUP_TOKEN_ROUTE = '/v1/payment_sources/setup-tokens';
16485
+ var PAYPAL_OTT_ROUTE = '/v1/payment_sources/setup-tokens/:setup_token/tokens';
16486
+ var PayPalSavePaymentSourceService = /*#__PURE__*/function () {
16487
+ function PayPalSavePaymentSourceService(publicKey, gatewayId, eventEmitter, config) {
16488
+ _classCallCheck(this, PayPalSavePaymentSourceService);
16489
+ this.publicKey = publicKey;
16490
+ this.gatewayId = gatewayId;
16491
+ this.eventEmitter = eventEmitter;
16492
+ this.config = config;
16493
+ this.api = new ApiInternal(publicKey, this.getApiAuthType(publicKey));
16494
+ }
16495
+ return _createClass(PayPalSavePaymentSourceService, [{
16496
+ key: "getApiAuthType",
16497
+ value: function getApiAuthType(publicKeyOrAccessToken) {
16498
+ if (AccessToken.validateJWT(publicKeyOrAccessToken)) {
16499
+ return API_AUTH_TYPE.TOKEN;
16500
+ }
16501
+ return API_AUTH_TYPE.PUBLIC_KEY;
16502
+ }
16503
+ }, {
16504
+ key: "setEnv",
16505
+ value: function setEnv(env, alias) {
16506
+ this.api.setEnv(env, alias);
16507
+ }
16508
+ }, {
16509
+ key: "load",
16510
+ value: function load(container) {
16511
+ var _this = this;
16512
+ if (!window.Promise) {
16513
+ this.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, {
16514
+ error_code: ErrorCodes.UNAVAILABLE
16515
+ });
16516
+ }
16517
+ Promise.all([this.getWalletConfig(), this.getIdToken()]).then(function () {
16518
+ return _this.renderPaypalSavePaymentSourceComponent(container);
16519
+ })["catch"](function (error) {
16520
+ throw error;
16521
+ });
16522
+ }
16523
+ }, {
16524
+ key: "renderPaypalSavePaymentSourceComponent",
16525
+ value: function renderPaypalSavePaymentSourceComponent(container) {
16526
+ var _this2 = this;
16527
+ var _a;
16528
+ var buttonId = ((_a = container.getElement()) === null || _a === void 0 ? void 0 : _a.id) || '';
16529
+ var paypalScript = document.createElement('script');
16530
+ paypalScript.src = "https://www.paypal.com/sdk/js?client-id=".concat(this.getClientAuthFromWalletConfig());
16531
+ paypalScript.setAttribute('data-user-id-token', this.idToken);
16532
+ paypalScript.async = true;
16533
+ paypalScript.onload = function () {
16534
+ if (window.paypal) {
16535
+ _this2.paypal = window.paypal;
16536
+ var button = _this2.paypal.Buttons(_extends(_extends({
16537
+ createVaultSetupToken: function createVaultSetupToken() {
16538
+ return _this2.getSetupToken(_this2.accessToken);
16539
+ },
16540
+ onApprove: function onApprove(_ref) {
16541
+ var vaultSetupToken = _ref.vaultSetupToken;
16542
+ _this2.onObtainedVaultSetupToken(vaultSetupToken);
16543
+ },
16544
+ onError: function onError(error) {
16545
+ _this2.onErrorVaultSetupToken(error);
16546
+ },
16547
+ onCancel: function onCancel() {
16548
+ _this2.onCancelVaultSetupToken();
16549
+ }
16550
+ }, _this2.config.style && {
16551
+ style: _this2.config.style
16552
+ }), _this2.config.message && {
16553
+ message: _this2.config.message
16554
+ }));
16555
+ if (button.isEligible()) {
16556
+ button.render("#".concat(buttonId));
16557
+ } else {
16558
+ _this2.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, {
16559
+ error_code: ErrorCodes.UNAVAILABLE
16560
+ });
16561
+ }
16562
+ } else {
16563
+ _this2.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, {
16564
+ error_code: ErrorCodes.UNAVAILABLE
16565
+ });
16566
+ }
16567
+ };
16568
+ document.head.appendChild(paypalScript);
16569
+ }
16570
+ }, {
16571
+ key: "getClientAuthFromWalletConfig",
16572
+ value: function getClientAuthFromWalletConfig() {
16573
+ var _a;
16574
+ return ((_a = this.walletConfig) === null || _a === void 0 ? void 0 : _a.credentials).client_auth;
16575
+ }
16576
+ }, {
16577
+ key: "getSetupToken",
16578
+ value: function getSetupToken(accessToken) {
16579
+ var _this3 = this;
16580
+ return this.api.getClientPromise('POST', PAYPAL_SETUP_TOKEN_ROUTE).send({
16581
+ gateway_id: this.gatewayId,
16582
+ token: accessToken
16583
+ }).then(function (responseSetupToken) {
16584
+ return responseSetupToken.setup_token;
16585
+ })["catch"](function (error) {
16586
+ _this3.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, _extends({
16587
+ error_code: ErrorCodes.ON_GET_SETUP_TOKEN_ERROR
16588
+ }, _this3.extractErrorDetails(error)));
16589
+ return Promise.reject(error);
16590
+ });
16591
+ }
16592
+ }, {
16593
+ key: "onObtainedVaultSetupToken",
16594
+ value: function onObtainedVaultSetupToken(vaultSetupToken) {
16595
+ var _this4 = this;
16596
+ return this.api.getClientPromise('POST', PAYPAL_OTT_ROUTE.replace(':setup_token', vaultSetupToken)).send({
16597
+ gateway_id: this.gatewayId
16598
+ }).then(function (responseSetupToken) {
16599
+ _this4.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_SUCCESS, {
16600
+ token: responseSetupToken.token,
16601
+ email: responseSetupToken.email
16602
+ });
16603
+ })["catch"](function () {
16604
+ _this4.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, {
16605
+ error_code: ErrorCodes.ON_ONE_TIME_TOKEN_ERROR
16606
+ });
16607
+ });
16608
+ }
16609
+ }, {
16610
+ key: "onErrorVaultSetupToken",
16611
+ value: function onErrorVaultSetupToken(error) {
16612
+ this.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, _extends({
16613
+ error_code: ErrorCodes.ON_PAYPAL_VAULT_SETUP_TOKEN_ERROR
16614
+ }, this.extractErrorDetails(error)));
16615
+ }
16616
+ }, {
16617
+ key: "onCancelVaultSetupToken",
16618
+ value: function onCancelVaultSetupToken() {
16619
+ this.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_CANCEL);
16620
+ }
16621
+ }, {
16622
+ key: "getIdToken",
16623
+ value: function getIdToken() {
16624
+ var _this5 = this;
16625
+ return this.api.getClientPromise('POST', PAYPAL_OAUTH_TOKEN_ROUTE).send({
16626
+ gateway_id: this.gatewayId
16627
+ }).then(function (data) {
16628
+ _this5.idToken = data.id_token;
16629
+ _this5.accessToken = data.access_token;
16630
+ })["catch"](function (error) {
16631
+ _this5.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, _extends({
16632
+ error_code: ErrorCodes.ON_GET_ID_TOKEN_ERROR
16633
+ }, _this5.extractErrorDetails(error)));
16634
+ });
16635
+ }
16636
+ }, {
16637
+ key: "getWalletConfig",
16638
+ value: function getWalletConfig() {
16639
+ var _this6 = this;
16640
+ return this.api.gateway().getWalletConfig(this.gatewayId).then(function (walletConfigResponse) {
16641
+ _this6.walletConfig = walletConfigResponse;
16642
+ })["catch"](function (error) {
16643
+ _this6.eventEmitter.emit(PAYPAL_SAVE_PAYMENT_EVENTS.ON_ERROR, _extends({
16644
+ error_code: ErrorCodes.ON_GET_WALLET_CONFIG_ERROR
16645
+ }, _this6.extractErrorDetails(error)));
16646
+ });
16647
+ }
16648
+ }, {
16649
+ key: "extractErrorDetails",
16650
+ value: function extractErrorDetails(error) {
16651
+ var _a, _b, _c, _d, _e, _f;
16652
+ var details = (_d = (_c = (_b = (_a = error === null || error === void 0 ? void 0 : error.details) === null || _a === void 0 ? void 0 : _a.messages) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.gateway_specific_description) !== null && _d !== void 0 ? _d : (_f = (_e = error === null || error === void 0 ? void 0 : error.details) === null || _e === void 0 ? void 0 : _e.messages) === null || _f === void 0 ? void 0 : _f[0];
16653
+ var message = error === null || error === void 0 ? void 0 : error.message;
16654
+ return _extends(_extends({}, details && {
16655
+ details: details
16656
+ }), message && {
16657
+ message: message
16658
+ });
16659
+ }
16660
+ }], [{
16661
+ key: "fromConfig",
16662
+ value: function fromConfig(publicKey, gatewayId, eventEmitter, config) {
16663
+ return new PayPalSavePaymentSourceService(publicKey, gatewayId, eventEmitter, config);
16664
+ }
16665
+ }]);
16666
+ }();
16667
+
16668
+ /**
16669
+ * PayPal Save Payment Source Widget constructor
16670
+ *
16671
+ * @param {string} selector - Selector of html element. Container for PayPal Save Payment Source Widget.
16672
+ * @param {string} publicKey - PayDock users public key.
16673
+ * @param {string} gatewayId - PayDock's PayPal gatewayId.
16674
+ * @param {PayPalSavePaymentSourceWidgetConfig} config - Extra configuration for the widget, like styles.
16675
+ *
16676
+ * @example
16677
+ * var payPalSavePaymentSourceWidget = new PayPalSavePaymentSourceWidget('#paypalButton', 'public_key', 'gateway_id');
16678
+ */
16679
+ var PayPalSavePaymentSourceWidget = /*#__PURE__*/function () {
16680
+ /** @constructs */ // constructs added for correct parse classes jsdoc2md
16681
+ function PayPalSavePaymentSourceWidget(selector, publicKey, gatewayId, config) {
16682
+ _classCallCheck(this, PayPalSavePaymentSourceWidget);
16683
+ this.eventEmitter = new EventEmitter();
16684
+ this.container = new Container(selector);
16685
+ this.service = PayPalSavePaymentSourceService.fromConfig(publicKey, gatewayId, this.eventEmitter, config);
16686
+ }
16687
+ /**
16688
+ * The final method after configuring the PayPalSavePaymentSource Widget to
16689
+ * start the load process.
16690
+ */
16691
+ return _createClass(PayPalSavePaymentSourceWidget, [{
16692
+ key: "load",
16693
+ value: function load() {
16694
+ try {
16695
+ this.service.load(this.container);
16696
+ } catch (err) {
16697
+ this.eventEmitter.emit(EVENTS.ON_ERROR, null);
16698
+ throw err;
16699
+ }
16700
+ }
16701
+ /**
16702
+ * Current method can change environment. By default environment = sandbox.
16703
+ * Also we can change domain alias for this environment. By default domain_alias = paydock.com
16704
+ *
16705
+ * @example
16706
+ * payPalSavePaymentSourceWidget.setEnv('production');
16707
+ * @param {string} env - sandbox, production
16708
+ * @param {string} [alias] - Own domain alias
16709
+ */
16710
+ }, {
16711
+ key: "setEnv",
16712
+ value: function setEnv(env, alias) {
16713
+ this.service.setEnv(env, alias);
16714
+ }
16715
+ /**
16716
+ * Callback for onSuccess method.
16717
+ *
16718
+ * @callback OnSuccessCallback
16719
+ * @param {IOnSuccessEventData} data
16720
+ */
16721
+ /**
16722
+ * If the setup token was successfully approved and a OTT was generated, the function passed as parameter will be called.
16723
+ * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
16724
+ *
16725
+ * @example
16726
+ * payPalSavePaymentSourceWidget.onSuccess((eventData) => console.log('One time token and email obtained successfully'));
16727
+ *
16728
+ * @param {OnSuccessCallback} [callback] - Function to be called when the result is successful.
16729
+ */
16730
+ }, {
16731
+ key: "onSuccess",
16732
+ value: function onSuccess(callback) {
16733
+ return this.eventEmitter.subscribe(EVENTS.ON_SUCCESS, callback);
16734
+ }
16735
+ /**
16736
+ * Callback for onError method.
16737
+ *
16738
+ * @callback OnErrorCallback
16739
+ * @param {IOnErrorEventData} data
16740
+ */
16741
+ /**
16742
+ * If in the process for obtaining the setup token fails, the function passed as parameter will be called.
16743
+ * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
16744
+ *
16745
+ * @example
16746
+ * payPalSavePaymentSourceWidget.onError((eventData) => console.log('Some error occurred'));
16747
+ *
16748
+ * @param {OnErrorCallback} [callback] - Function to be called when there is an error in the flow.
16749
+ */
16750
+ }, {
16751
+ key: "onError",
16752
+ value: function onError(callback) {
16753
+ return this.eventEmitter.subscribe(EVENTS.ON_ERROR, callback);
16754
+ }
16755
+ /**
16756
+ * Callback for onCancel method.
16757
+ *
16758
+ * @callback OnCancelCallback
16759
+ * @param {IOnCancelEventData} data
16760
+ */
16761
+ /**
16762
+ * If in the process for obtaining the setup token was cancelled, the function passed as parameter will be called.
16763
+ * Important: Do not perform thread blocking operations in callback such as window.alert() calls.
16764
+ *
16765
+ * @example
16766
+ * payPalSavePaymentSourceWidget.onCancel(() => console.log('Operation cancelled'));
16767
+ *
16768
+ * @param {OnCancelCallback} [callback] - Function to be called when the operation is cancelled.
16769
+ */
16770
+ }, {
16771
+ key: "onCancel",
16772
+ value: function onCancel(callback) {
16773
+ return this.eventEmitter.subscribe(EVENTS.ON_CANCEL, callback);
16774
+ }
16775
+ }]);
16776
+ }();
16777
+
16352
16778
  class Timer {
16353
16779
  constructor(opts, ms) {
16354
16780
  if (!opts.onEnd) throw new Error('onEnd handler is required');
@@ -34455,4 +34881,4 @@ var browser = /*#__PURE__*/Object.freeze({
34455
34881
  strToU8: strToU8
34456
34882
  });
34457
34883
 
34458
- export { AfterpayCheckoutButton, Api, ApplePayWalletButtonExpress, CHECKOUT_BUTTON_EVENT, Canvas3ds, Checkout, ClickToPay, Configuration, ELEMENT, EVENT$4 as EVENT, Builder$1 as ExternalCheckoutBuilder, Checker as ExternalCheckoutChecker, FORM_FIELD, HtmlMultiWidget, HtmlPaymentSourceWidget, HtmlWidget, InstructionDebugger, MultiWidget, PAYMENT_TYPE, PURPOSE, Builder as PaymentSourceBuilder, PaymentSourceWidget, PaypalCheckoutButton, PaypalWalletButtonExpress, STYLABLE_ELEMENT, STYLABLE_ELEMENT_STATE, STYLE$2 as STYLE, SUPPORTED_CARD_TYPES, TEXT, TRIGGER$1 as TRIGGER, TYPE, VAULT_DISPLAY_STYLE, VaultDisplayWidget, WalletButtons, ZipmoneyCheckoutButton };
34884
+ export { AfterpayCheckoutButton, Api, ApplePayWalletButtonExpress, CHECKOUT_BUTTON_EVENT, Canvas3ds, Checkout, ClickToPay, Configuration, ELEMENT, EVENT$4 as EVENT, Builder$1 as ExternalCheckoutBuilder, Checker as ExternalCheckoutChecker, FORM_FIELD, HtmlMultiWidget, HtmlPaymentSourceWidget, HtmlWidget, InstructionDebugger, MultiWidget, PAYMENT_TYPE, PURPOSE, PayPalDataCollector, PayPalSavePaymentSourceWidget, Builder as PaymentSourceBuilder, PaymentSourceWidget, PaypalCheckoutButton, PaypalWalletButtonExpress, STYLABLE_ELEMENT, STYLABLE_ELEMENT_STATE, STYLE$2 as STYLE, SUPPORTED_CARD_TYPES, TEXT, TRIGGER$1 as TRIGGER, TYPE, VAULT_DISPLAY_STYLE, VaultDisplayWidget, WalletButtons, ZipmoneyCheckoutButton };