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