@paydock/client-sdk 1.10.78-beta → 1.10.82-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
@@ -3740,7 +3740,7 @@ Class CheckoutButton transform usual button into checkout
3740
3740
  **Kind**: global class
3741
3741
 
3742
3742
  * [CheckoutButton](#cb_CheckoutButton)
3743
- * [new exports.CheckoutButton(selector, publicKey, [gatewayId], [type])](#cb_new_CheckoutButton_new)
3743
+ * [new exports.CheckoutButton(selector, aceessToken, [gatewayId], [type])](#cb_new_CheckoutButton_new)
3744
3744
  * [.on(eventName, cb)](#cb_CheckoutButton+on)
3745
3745
  * [.close()](#cb_CheckoutButton+close)
3746
3746
  * [.onFinishInsert(selector, dataType)](#cb_CheckoutButton+onFinishInsert)
@@ -3752,19 +3752,19 @@ Class CheckoutButton transform usual button into checkout
3752
3752
 
3753
3753
  <a name="cb_new_CheckoutButton_new" id="cb_new_CheckoutButton_new"></a>
3754
3754
 
3755
- ### new exports.CheckoutButton(selector, publicKey, [gatewayId], [type])
3755
+ ### new exports.CheckoutButton(selector, aceessToken, [gatewayId], [type])
3756
3756
 
3757
3757
  | Param | Type | Default | Description |
3758
3758
  | --- | --- | --- | --- |
3759
3759
  | selector | <code>string</code> | | Selector of html element. |
3760
- | publicKey | <code>string</code> | | PayDock users public key |
3760
+ | aceessToken | <code>string</code> | | PayDock access token or users public key |
3761
3761
  | [gatewayId] | <code>string</code> | <code>&quot;default&quot;</code> | PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway |
3762
3762
  | [type] | <code>string</code> | <code>&quot;PaypalClassic&quot;</code> | Type of gateway (PaypalClassic, Zipmoney) |
3763
3763
 
3764
3764
  **Example**
3765
3765
 
3766
3766
  ```javascript
3767
- var widget = new CheckoutButton('#button', 'publicKey','gatewayId');
3767
+ var widget = new CheckoutButton('#button', 'aceessToken','gatewayId');
3768
3768
  ```
3769
3769
  <a name="cb_CheckoutButton+on" id="cb_CheckoutButton+on"></a>
3770
3770
 
@@ -4181,7 +4181,7 @@ Class AfterpayCheckoutButton is wrapper of CheckoutButton transform usual button
4181
4181
  **Extends**: [<code>CheckoutButton</code>](#cb_CheckoutButton)
4182
4182
 
4183
4183
  * [AfterpayCheckoutButton](#cb_AfterpayCheckoutButton) ⇐ [<code>CheckoutButton</code>](#cb_CheckoutButton)
4184
- * [new exports.AfterpayCheckoutButton(selector, publicKey, [gatewayId])](#cb_new_AfterpayCheckoutButton_new)
4184
+ * [new exports.AfterpayCheckoutButton(selector, accessToken, [gatewayId])](#cb_new_AfterpayCheckoutButton_new)
4185
4185
  * [.on(eventName, cb)](#cb_CheckoutButton+on)
4186
4186
  * [.close()](#cb_CheckoutButton+close)
4187
4187
  * [.onFinishInsert(selector, dataType)](#cb_CheckoutButton+onFinishInsert)
@@ -4193,18 +4193,18 @@ Class AfterpayCheckoutButton is wrapper of CheckoutButton transform usual button
4193
4193
 
4194
4194
  <a name="cb_new_AfterpayCheckoutButton_new" id="cb_new_AfterpayCheckoutButton_new"></a>
4195
4195
 
4196
- ### new exports.AfterpayCheckoutButton(selector, publicKey, [gatewayId])
4196
+ ### new exports.AfterpayCheckoutButton(selector, accessToken, [gatewayId])
4197
4197
 
4198
4198
  | Param | Type | Default | Description |
4199
4199
  | --- | --- | --- | --- |
4200
4200
  | selector | <code>string</code> | | Selector of html element. |
4201
- | publicKey | <code>string</code> | | PayDock users public key |
4201
+ | accessToken | <code>string</code> | | PayDock access-token or users public key |
4202
4202
  | [gatewayId] | <code>string</code> | <code>&quot;default&quot;</code> | PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway |
4203
4203
 
4204
4204
  **Example**
4205
4205
 
4206
4206
  ```javascript
4207
- var widget = new AfterpayCheckoutButton('#button', 'publicKey','gatewayId');
4207
+ var widget = new AfterpayCheckoutButton('#button', 'access-token','gatewayId');
4208
4208
  ```
4209
4209
  <a name="cb_CheckoutButton+on" id="cb_CheckoutButton+on"></a>
4210
4210
 
package/api.js ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/api';
@@ -2377,7 +2377,7 @@
2377
2377
  }
2378
2378
  }, {
2379
2379
  key: 'create',
2380
- value: function create(publicKey, data, cb, errorCb) {
2380
+ value: function create(accessToken, data, cb, errorCb) {
2381
2381
  var _this = this;
2382
2382
 
2383
2383
  var request = new XMLHttpRequest();
@@ -2386,12 +2386,12 @@
2386
2386
  };
2387
2387
  request.open('POST', this.getUrl(), true);
2388
2388
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
2389
- request.setRequestHeader('x-user-public-key', publicKey);
2389
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
2390
2390
  request.send(JSON.stringify(data));
2391
2391
  }
2392
2392
  }, {
2393
2393
  key: 'get',
2394
- value: function get(publicKey, cb, errorCb) {
2394
+ value: function get(accessToken, cb, errorCb) {
2395
2395
  var _this2 = this;
2396
2396
 
2397
2397
  var request = new XMLHttpRequest();
@@ -2400,7 +2400,7 @@
2400
2400
  };
2401
2401
  request.open('GET', this.getUrl(), true);
2402
2402
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
2403
- request.setRequestHeader('x-user-public-key', publicKey);
2403
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
2404
2404
  request.send();
2405
2405
  }
2406
2406
  }, {
@@ -2493,10 +2493,10 @@
2493
2493
  }
2494
2494
  }, {
2495
2495
  key: 'send',
2496
- value: function send(publicKey, cb) {
2496
+ value: function send(accessToken, cb) {
2497
2497
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
2498
2498
 
2499
- this.get(publicKey, function (data, status) {
2499
+ this.get(accessToken, function (data, status) {
2500
2500
  cb(data);
2501
2501
  }, function (err, status) {
2502
2502
  if (typeof err.message === "undefined") errorCb(status + ': unknown error');else errorCb(err.message);
@@ -2818,10 +2818,10 @@
2818
2818
  }
2819
2819
  }, {
2820
2820
  key: 'send',
2821
- value: function send(publicKey, cb) {
2821
+ value: function send(accessToken, cb) {
2822
2822
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
2823
2823
 
2824
- this.create(publicKey, this.getConfigs(), function (data, status) {
2824
+ this.create(accessToken, this.getConfigs(), function (data, status) {
2825
2825
  return cb(data);
2826
2826
  }, function (err, status) {
2827
2827
  if (typeof err.message === "undefined") errorCb('unknown error');else errorCb(err.message);
@@ -4467,21 +4467,21 @@
4467
4467
  * @constructor
4468
4468
  *
4469
4469
  * @param {string} selector - Selector of html element.
4470
- * @param {string} publicKey - PayDock users public key
4470
+ * @param {string} aceessToken - PayDock access token or users public key
4471
4471
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
4472
4472
  * @param {string} [type=PaypalClassic] - Type of gateway (PaypalClassic, Zipmoney)
4473
4473
  * @example
4474
- * var widget = new CheckoutButton('#button', 'publicKey','gatewayId');
4474
+ * var widget = new CheckoutButton('#button', 'aceessToken','gatewayId');
4475
4475
  **/
4476
4476
  var CheckoutButton = function () {
4477
- function CheckoutButton(selector, publicKey) {
4477
+ function CheckoutButton(selector, aceessToken) {
4478
4478
  var _this = this;
4479
4479
 
4480
4480
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
4481
4481
  var gatewayType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : GATEWAY_TYPE.PAYPAL;
4482
4482
  classCallCheck(this, CheckoutButton);
4483
4483
 
4484
- this.publicKey = publicKey;
4484
+ this.aceessToken = aceessToken;
4485
4485
  this.gatewayId = gatewayId;
4486
4486
  this.gatewayType = gatewayType;
4487
4487
  this.details = null;
@@ -4492,13 +4492,13 @@
4492
4492
  this.background = new Background();
4493
4493
  switch (gatewayType) {
4494
4494
  case GATEWAY_TYPE.PAYPAL:
4495
- this.runner = new PaypalRunner(publicKey);
4495
+ this.runner = new PaypalRunner(aceessToken);
4496
4496
  break;
4497
4497
  case GATEWAY_TYPE.AFTERPAY:
4498
- this.runner = new AfterpayRunner(publicKey);
4498
+ this.runner = new AfterpayRunner(aceessToken);
4499
4499
  break;
4500
4500
  case GATEWAY_TYPE.ZIPMONEY:
4501
- this.runner = new ZipmoneyRunner(publicKey);
4501
+ this.runner = new ZipmoneyRunner(aceessToken);
4502
4502
  break;
4503
4503
  }
4504
4504
  this.initCheckout();
@@ -4520,7 +4520,7 @@
4520
4520
  var externalCheckout = new Builder(_this2.gatewayId, _this2.runner.getSuccessRedirectUri(), _this2.runner.getErrorRedirectUri());
4521
4521
  externalCheckout.setMeta(_this2.meta);
4522
4522
  externalCheckout.setEnv(_this2.env);
4523
- externalCheckout.send(_this2.publicKey, function (checkout) {
4523
+ externalCheckout.send(_this2.aceessToken, function (checkout) {
4524
4524
  _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.POPUP_REDIRECT, {});
4525
4525
  _this2.runner.next(checkout);
4526
4526
  }, function (error, code) {
@@ -4571,7 +4571,7 @@
4571
4571
 
4572
4572
  var checker = new Checker(token);
4573
4573
  checker.setEnv(this.env);
4574
- checker.send(this.publicKey, function (details) {
4574
+ checker.send(this.aceessToken, function (details) {
4575
4575
  _this4.details = details;
4576
4576
  cb();
4577
4577
  }, function () {
@@ -4586,7 +4586,7 @@
4586
4586
 
4587
4587
  var paymentSourceToken = new Builder$1(this.gatewayId, token, TYPE.CHECKOUT_TOKEN);
4588
4588
  paymentSourceToken.setEnv(this.env);
4589
- paymentSourceToken.send(this.publicKey, function (token) {
4589
+ paymentSourceToken.send(this.aceessToken, function (token) {
4590
4590
  _this5.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.FINISH, {
4591
4591
  payment_source_token: token,
4592
4592
  checkout_email: _this5.details.checkout_email,
@@ -4794,21 +4794,21 @@
4794
4794
  * @constructor
4795
4795
  *
4796
4796
  * @param {string} selector - Selector of html element.
4797
- * @param {string} publicKey - PayDock users public key
4797
+ * @param {string} accessToken - PayDock access-token or users public key
4798
4798
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
4799
4799
  * @example
4800
- * var widget = new AfterpayCheckoutButton('#button', 'publicKey','gatewayId');
4800
+ * var widget = new AfterpayCheckoutButton('#button', 'access-token','gatewayId');
4801
4801
  **/
4802
4802
  var AfterpayCheckoutButton = function (_CheckoutButton) {
4803
4803
  inherits(AfterpayCheckoutButton, _CheckoutButton);
4804
4804
 
4805
- function AfterpayCheckoutButton(selector, publicKey) {
4805
+ function AfterpayCheckoutButton(selector, accessToken) {
4806
4806
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
4807
4807
  classCallCheck(this, AfterpayCheckoutButton);
4808
4808
 
4809
- var _this = possibleConstructorReturn(this, (AfterpayCheckoutButton.__proto__ || Object.getPrototypeOf(AfterpayCheckoutButton)).call(this, selector, publicKey, gatewayId, GATEWAY_TYPE.AFTERPAY));
4809
+ var _this = possibleConstructorReturn(this, (AfterpayCheckoutButton.__proto__ || Object.getPrototypeOf(AfterpayCheckoutButton)).call(this, selector, accessToken, gatewayId, GATEWAY_TYPE.AFTERPAY));
4810
4810
 
4811
- _this.publicKey = publicKey;
4811
+ _this.accessToken = accessToken;
4812
4812
  _this.gatewayId = gatewayId;
4813
4813
  return _this;
4814
4814
  }
@@ -6234,7 +6234,7 @@
6234
6234
  classCallCheck(this, ApiBase);
6235
6235
 
6236
6236
  this.auth = auth;
6237
- this.authType = authType || API_AUTH_TYPE.PUBLIC_KEY;
6237
+ this.authType = authType || this.setAuthType();
6238
6238
  this.env = new Env([{ env: ENV.SANDBOX, url: 'https://api-sandbox.' }, { env: ENV.PROD, url: 'https://api.' }, { env: ENV.STAGING, url: 'https://apista.' }, { env: ENV.STAGING_2, url: 'https://apista-2.' }, { env: ENV.STAGING_3, url: 'https://apista-3.' }, { env: ENV.STAGING_4, url: 'https://apista-4.' }, { env: ENV.STAGING_5, url: 'https://apista-5.' }]);
6239
6239
  }
6240
6240
  /**
@@ -6249,13 +6249,18 @@
6249
6249
 
6250
6250
 
6251
6251
  createClass(ApiBase, [{
6252
- key: "setEnv",
6252
+ key: 'setEnv',
6253
6253
  value: function setEnv(env, alias) {
6254
6254
  this.env.setEnv(env, alias);
6255
6255
  return this;
6256
6256
  }
6257
6257
  }, {
6258
- key: "getClient",
6258
+ key: 'setAuthType',
6259
+ value: function setAuthType() {
6260
+ return this.authType = !!AccessToken.validateJWT(this.auth) ? API_AUTH_TYPE.TOKEN : API_AUTH_TYPE.PUBLIC_KEY;
6261
+ }
6262
+ }, {
6263
+ key: 'getClient',
6259
6264
  value: function getClient(method, link) {
6260
6265
  var _this = this;
6261
6266
 
@@ -6274,7 +6279,7 @@
6274
6279
  };
6275
6280
  }
6276
6281
  }, {
6277
- key: "getClientPromise",
6282
+ key: 'getClientPromise',
6278
6283
  value: function getClientPromise(method, link) {
6279
6284
  var _this2 = this;
6280
6285
 
@@ -6297,7 +6302,7 @@
6297
6302
  };
6298
6303
  }
6299
6304
  }, {
6300
- key: "parser",
6305
+ key: 'parser',
6301
6306
  value: function parser(_ref, cb, errorCb) {
6302
6307
  var text = _ref.text,
6303
6308
  status = _ref.status;
@@ -6308,7 +6313,7 @@
6308
6313
  } catch (e) {}
6309
6314
  }
6310
6315
  }, {
6311
- key: "parserPromise",
6316
+ key: 'parserPromise',
6312
6317
  value: function parserPromise(_ref2) {
6313
6318
  var text = _ref2.text,
6314
6319
  status = _ref2.status;
@@ -6321,7 +6326,7 @@
6321
6326
  }
6322
6327
  }
6323
6328
  }, {
6324
- key: "setAuthHeader",
6329
+ key: 'setAuthHeader',
6325
6330
  value: function setAuthHeader(request) {
6326
6331
  switch (this.authType) {
6327
6332
  case API_AUTH_TYPE.PUBLIC_KEY: