@paydock/client-sdk 1.10.79-beta → 1.10.83-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/README.md +19 -19
  2. package/bundles/widget.umd.js +118 -98
  3. package/bundles/widget.umd.min.js +1 -1
  4. package/lib/api/api-base.d.ts +1 -0
  5. package/lib/api/api-base.js +5 -1
  6. package/lib/api/api-base.js.map +1 -1
  7. package/lib/checkout-button/afterpay-checkout-button.d.ts +4 -4
  8. package/lib/checkout-button/afterpay-checkout-button.js +5 -5
  9. package/lib/checkout-button/afterpay-checkout-button.js.map +1 -1
  10. package/lib/checkout-button/checkout-button.d.ts +4 -4
  11. package/lib/checkout-button/checkout-button.js +10 -10
  12. package/lib/checkout-button/checkout-button.js.map +1 -1
  13. package/lib/checkout-button/zipmoney.runner.js +2 -1
  14. package/lib/checkout-button/zipmoney.runner.js.map +1 -1
  15. package/lib/components/http-core.d.ts +2 -2
  16. package/lib/components/http-core.js +5 -4
  17. package/lib/components/http-core.js.map +1 -1
  18. package/lib/components/param.d.ts +2 -0
  19. package/lib/components/param.js.map +1 -1
  20. package/lib/external-checkout/checker.d.ts +1 -1
  21. package/lib/external-checkout/checker.js +2 -2
  22. package/lib/external-checkout/checker.js.map +1 -1
  23. package/lib/helper/access-token.d.ts +5 -0
  24. package/lib/helper/access-token.js +9 -0
  25. package/lib/helper/access-token.js.map +1 -1
  26. package/lib/payment-source/builder.d.ts +1 -1
  27. package/lib/payment-source/builder.js +2 -2
  28. package/lib/payment-source/builder.js.map +1 -1
  29. package/lib/payment-source-widget/payment-source-widget.d.ts +1 -1
  30. package/lib/payment-source-widget/payment-source-widget.js +3 -2
  31. package/lib/payment-source-widget/payment-source-widget.js.map +1 -1
  32. package/lib/widget/configuration.d.ts +3 -3
  33. package/lib/widget/configuration.js +8 -7
  34. package/lib/widget/configuration.js.map +1 -1
  35. package/lib/widget/multi-widget.d.ts +10 -10
  36. package/lib/widget/multi-widget.js +15 -9
  37. package/lib/widget/multi-widget.js.map +1 -1
  38. package/package.json +2 -2
  39. package/slate.md +1 -1
package/README.md CHANGED
@@ -8,7 +8,7 @@ The SDK supports methods for customization of widget by your needs (styling, for
8
8
 
9
9
  ## Other information
10
10
 
11
- To work with the widget you will need public_key ([see Authentication](https://docs.paydock.com/#authentication))
11
+ To work with the widget you will need public_key or access_token ([see Authentication](https://docs.paydock.com/#authentication))
12
12
 
13
13
  Also you will need added gateway ([see API Reference by gateway](https://docs.paydock.com/#gateways))
14
14
 
@@ -1901,7 +1901,7 @@ Class Configuration include methods for creating configuration token
1901
1901
  * [.setMeta(object)](#w_Configuration+setMeta)
1902
1902
  * [.setEnv(env, [alias])](#w_Configuration+setEnv)
1903
1903
  * [.setLabel(label)](#w_Configuration+setLabel)
1904
- * [.createToken(publicKey, cb, errorCb)](#w_Configuration+createToken)
1904
+ * [.createToken(accessToken, cb, errorCb)](#w_Configuration+createToken)
1905
1905
 
1906
1906
  <a name="w_new_Configuration_new" id="w_new_Configuration_new"></a>
1907
1907
 
@@ -2041,14 +2041,14 @@ config.setLabel('custom label');
2041
2041
  ```
2042
2042
  <a name="w_Configuration+createToken" id="w_Configuration+createToken"></a>
2043
2043
 
2044
- ### configuration.createToken(publicKey, cb, errorCb)
2044
+ ### configuration.createToken(accessToken, cb, errorCb)
2045
2045
  createToken - method which exactly create payment one time token
2046
2046
 
2047
2047
  **Kind**: instance method of [<code>Configuration</code>](#w_Configuration)
2048
2048
 
2049
2049
  | Param | Type | Description |
2050
2050
  | --- | --- | --- |
2051
- | publicKey | <code>string</code> | Customer public key which provided for each client |
2051
+ | accessToken | <code>string</code> | Customer access token or public key which provided for each client |
2052
2052
  | cb | <code>createToken~requestCallback</code> | The callback that handles the success response. |
2053
2053
  | errorCb | <code>createToken~requestCallback</code> | The callback that handles the failed response. |
2054
2054
 
@@ -2070,7 +2070,7 @@ Class MultiWidget include method for for creating iframe url
2070
2070
  **Kind**: global class
2071
2071
 
2072
2072
  * [MultiWidget](#w_MultiWidget)
2073
- * [new exports.MultiWidget(publicKey, conf)](#w_new_MultiWidget_new)
2073
+ * [new exports.MultiWidget(accessToken, conf)](#w_new_MultiWidget_new)
2074
2074
  * [.setStyles(fields)](#w_MultiWidget+setStyles)
2075
2075
  * [.usePhoneCountryMask([options])](#w_MultiWidget+usePhoneCountryMask)
2076
2076
  * [.setTexts(fields)](#w_MultiWidget+setTexts)
@@ -2090,23 +2090,23 @@ Class MultiWidget include method for for creating iframe url
2090
2090
 
2091
2091
  <a name="w_new_MultiWidget_new" id="w_new_MultiWidget_new"></a>
2092
2092
 
2093
- ### new exports.MultiWidget(publicKey, conf)
2093
+ ### new exports.MultiWidget(accessToken, conf)
2094
2094
 
2095
2095
  | Param | Type | Description |
2096
2096
  | --- | --- | --- |
2097
- | publicKey | <code>string</code> | PayDock users public key |
2097
+ | accessToken | <code>string</code> | PayDock users access token or public key |
2098
2098
  | conf | [<code>Configuration</code>](#w_Configuration) \| <code>string</code> \| [<code>Array.&lt;Configuration&gt;</code>](#w_Configuration) \| <code>Array.&lt;string&gt;</code> | exemplar[s] Configuration class OR configuration token |
2099
2099
 
2100
2100
  **Example**
2101
2101
 
2102
2102
  ```javascript
2103
- var widget = new MultiWidget('publicKey','configurationToken'); // With a pre-created configuration token
2103
+ var widget = new MultiWidget('accessToken','configurationToken'); // With a pre-created configuration token
2104
2104
 
2105
- var widget = new MultiWidget('publicKey',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
2105
+ var widget = new MultiWidget('accessToken',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
2106
2106
 
2107
- var widget = new MultiWidget('publicKey', new Configuration('gatewayId')); With Configuration
2107
+ var widget = new MultiWidget('accessToken', new Configuration('gatewayId')); With Configuration
2108
2108
 
2109
- var widget = new MultiWidget('publicKey',[ With Configurations
2109
+ var widget = new MultiWidget('accessToken',[ With Configurations
2110
2110
  Configuration('gatewayId'),
2111
2111
  Configuration('gatewayId', 'bank_account')
2112
2112
  ]);
@@ -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
 
@@ -160,6 +160,66 @@
160
160
  }
161
161
  };
162
162
 
163
+ var ACCESS_HEADER_NAME = {
164
+ accessToken: 'x-access-token',
165
+ publicKey: 'x-user-public-key'
166
+ };
167
+ var AccessToken = function () {
168
+ function AccessToken() {
169
+ classCallCheck(this, AccessToken);
170
+ }
171
+
172
+ createClass(AccessToken, null, [{
173
+ key: 'validateJWT',
174
+ value: function validateJWT(jwt) {
175
+ if (!jwt) return null;
176
+
177
+ var _jwt$split = jwt.split("."),
178
+ _jwt$split2 = slicedToArray(_jwt$split, 3),
179
+ rawHead = _jwt$split2[0],
180
+ rawBody = _jwt$split2[1],
181
+ signature = _jwt$split2[2];
182
+
183
+ if (!rawHead || !rawBody || !signature) return null;
184
+ if (2 + rawHead.length + rawBody.length + signature.length !== jwt.length) return null;
185
+ try {
186
+ var head = JSON.parse(atob(rawHead));
187
+ var body = JSON.parse(atob(rawBody));
188
+ return { head: head, body: body, signature: signature };
189
+ } catch (_a) {
190
+ return null;
191
+ }
192
+ }
193
+ }, {
194
+ key: 'extractData',
195
+ value: function extractData(body) {
196
+ try {
197
+ return JSON.parse(atob(body.meta));
198
+ } catch (_a) {
199
+ return null;
200
+ }
201
+ }
202
+ }, {
203
+ key: 'extractMeta',
204
+ value: function extractMeta(body) {
205
+ try {
206
+ var _JSON$parse = JSON.parse(atob(body.meta)),
207
+ meta = _JSON$parse.meta;
208
+
209
+ return meta;
210
+ } catch (_a) {
211
+ return null;
212
+ }
213
+ }
214
+ }, {
215
+ key: 'getAccessHeaderNameByToken',
216
+ value: function getAccessHeaderNameByToken(token) {
217
+ return !!AccessToken.validateJWT(token) ? ACCESS_HEADER_NAME.accessToken : ACCESS_HEADER_NAME.publicKey;
218
+ }
219
+ }]);
220
+ return AccessToken;
221
+ }();
222
+
163
223
  var ENV = {
164
224
  SANDBOX: 'sandbox',
165
225
  SANDBOX_KOVENA: 'sandbox-kovena',
@@ -641,28 +701,28 @@
641
701
  * console.log(error);
642
702
  * });
643
703
  *
644
- * @param {string} publicKey - Customer public key which provided for each client
704
+ * @param {string} accessToken - Customer access token or public key which provided for each client
645
705
  * @param {createToken~requestCallback} cb - The callback that handles the success response.
646
706
  * @param {createToken~requestCallback} errorCb - The callback that handles the failed response.
647
707
  */
648
708
 
649
709
  }, {
650
710
  key: 'createToken',
651
- value: function createToken(publicKey, cb) {
711
+ value: function createToken(accessToken, cb) {
652
712
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
653
713
 
654
- this.send(publicKey, function (data, status) {
714
+ this.send(accessToken, function (data, status) {
655
715
  if (status >= 200 && status < 300) return cb(data.resource.data.configuration_token);
656
716
  if (typeof data.error === "undefined" || typeof data.error.message === "undefined") errorCb('unknown error');else errorCb(data.error.message);
657
717
  });
658
718
  }
659
719
  }, {
660
720
  key: 'send',
661
- value: function send(publicKey, cb) {
721
+ value: function send(accessToken, cb) {
662
722
  var request = new XMLHttpRequest();
663
723
  request.open('POST', this.getUrl(), true);
664
724
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
665
- request.setRequestHeader('x-user-public-key', publicKey);
725
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
666
726
  request.send(JSON.stringify(this.getConfigs()));
667
727
  request.onload = function () {
668
728
  var res = {};
@@ -684,7 +744,7 @@
684
744
  }
685
745
  }], [{
686
746
  key: 'createEachToken',
687
- value: function createEachToken(publicKey, configs, cb) {
747
+ value: function createEachToken(accessToken, configs, cb) {
688
748
  var errorCb = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function (errors) {};
689
749
 
690
750
  var tokens = new Array(configs.length);
@@ -692,7 +752,7 @@
692
752
  var counter = 0;
693
753
 
694
754
  var _loop = function _loop(index) {
695
- if (configs.hasOwnProperty(index)) configs[index].createToken(publicKey, function (token) {
755
+ if (configs.hasOwnProperty(index)) configs[index].createToken(accessToken, function (token) {
696
756
  tokens[index] = token;
697
757
  counter++;
698
758
  if (configs.length === counter) Configuration.finishCreatingEachToken(tokens, errors, cb, errorCb);
@@ -909,30 +969,34 @@
909
969
  * Class MultiWidget include method for for creating iframe url
910
970
  * @constructor
911
971
  *
912
- * @param {string} publicKey - PayDock users public key
972
+ * @param {string} accessToken - PayDock users access token or public key
913
973
  * @param {(Configuration | string | Configuration[] | string[])} conf - exemplar[s] Configuration class OR configuration token
914
974
  *
915
975
  * @example
916
- * var widget = new MultiWidget('publicKey','configurationToken'); // With a pre-created configuration token
976
+ * var widget = new MultiWidget('accessToken','configurationToken'); // With a pre-created configuration token
917
977
  *
918
- * var widget = new MultiWidget('publicKey',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
978
+ * var widget = new MultiWidget('accessToken',['configurationToken', 'configurationToken2']); // With pre-created configuration tokens
919
979
  *
920
- * var widget = new MultiWidget('publicKey', new Configuration('gatewayId')); With Configuration
980
+ * var widget = new MultiWidget('accessToken', new Configuration('gatewayId')); With Configuration
921
981
  *
922
- * var widget = new MultiWidget('publicKey',[ With Configurations
982
+ * var widget = new MultiWidget('accessToken',[ With Configurations
923
983
  * Configuration('gatewayId'),
924
984
  * Configuration('gatewayId', 'bank_account')
925
985
  * ]);
926
986
  **/
927
987
  var MultiWidget = function () {
928
- function MultiWidget(publicKey, conf) {
988
+ function MultiWidget(accessToken, conf) {
929
989
  classCallCheck(this, MultiWidget);
930
990
 
931
991
  this.configs = [];
932
992
  this.configTokens = [];
933
993
  this.link = new Link(WIDGET_LINK);
934
- this.link.setParams({ public_key: publicKey });
935
- this.publicKey = publicKey;
994
+ if (!!AccessToken.validateJWT(accessToken)) {
995
+ this.link.setParams({ token: accessToken });
996
+ } else {
997
+ this.link.setParams({ public_key: accessToken });
998
+ }
999
+ this.accessToken = accessToken;
936
1000
  if (!conf || Array.isArray(conf) && !conf.length) throw Error('configuration token is required');
937
1001
  if (typeof conf === 'string') this.configTokens.push(conf);else if (conf instanceof Configuration) this.configs.push(conf);else if (Array.isArray(conf) && typeof conf[0] === 'string') this.configTokens = conf;else if (Array.isArray(conf) && conf[0] instanceof Configuration) this.configs = conf;else throw Error('Unsupported type of configuration token');
938
1002
  }
@@ -1307,7 +1371,7 @@
1307
1371
  this.link.setParams({ configuration_tokens: this.configTokens.join(',') });
1308
1372
  return cb(this.link.getUrl());
1309
1373
  }
1310
- Configuration.createEachToken(this.publicKey, this.configs, function (tokens) {
1374
+ Configuration.createEachToken(this.accessToken, this.configs, function (tokens) {
1311
1375
  _this2.link.concatParams({ configuration_tokens: tokens.join(',') });
1312
1376
  return cb(_this2.link.getUrl());
1313
1377
  }, function (errors) {
@@ -2313,7 +2377,7 @@
2313
2377
  }
2314
2378
  }, {
2315
2379
  key: 'create',
2316
- value: function create(publicKey, data, cb, errorCb) {
2380
+ value: function create(accessToken, data, cb, errorCb) {
2317
2381
  var _this = this;
2318
2382
 
2319
2383
  var request = new XMLHttpRequest();
@@ -2322,12 +2386,12 @@
2322
2386
  };
2323
2387
  request.open('POST', this.getUrl(), true);
2324
2388
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
2325
- request.setRequestHeader('x-user-public-key', publicKey);
2389
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
2326
2390
  request.send(JSON.stringify(data));
2327
2391
  }
2328
2392
  }, {
2329
2393
  key: 'get',
2330
- value: function get(publicKey, cb, errorCb) {
2394
+ value: function get(accessToken, cb, errorCb) {
2331
2395
  var _this2 = this;
2332
2396
 
2333
2397
  var request = new XMLHttpRequest();
@@ -2336,7 +2400,7 @@
2336
2400
  };
2337
2401
  request.open('GET', this.getUrl(), true);
2338
2402
  request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
2339
- request.setRequestHeader('x-user-public-key', publicKey);
2403
+ request.setRequestHeader(AccessToken.getAccessHeaderNameByToken(accessToken), accessToken);
2340
2404
  request.send();
2341
2405
  }
2342
2406
  }, {
@@ -2429,10 +2493,10 @@
2429
2493
  }
2430
2494
  }, {
2431
2495
  key: 'send',
2432
- value: function send(publicKey, cb) {
2496
+ value: function send(accessToken, cb) {
2433
2497
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
2434
2498
 
2435
- this.get(publicKey, function (data, status) {
2499
+ this.get(accessToken, function (data, status) {
2436
2500
  cb(data);
2437
2501
  }, function (err, status) {
2438
2502
  if (typeof err.message === "undefined") errorCb(status + ': unknown error');else errorCb(err.message);
@@ -2754,10 +2818,10 @@
2754
2818
  }
2755
2819
  }, {
2756
2820
  key: 'send',
2757
- value: function send(publicKey, cb) {
2821
+ value: function send(accessToken, cb) {
2758
2822
  var errorCb = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (err) {};
2759
2823
 
2760
- this.create(publicKey, this.getConfigs(), function (data, status) {
2824
+ this.create(accessToken, this.getConfigs(), function (data, status) {
2761
2825
  return cb(data);
2762
2826
  }, function (err, status) {
2763
2827
  if (typeof err.message === "undefined") errorCb('unknown error');else errorCb(err.message);
@@ -3917,7 +3981,7 @@
3917
3981
  this.background.clear();
3918
3982
  this.checkout = checkoutData;
3919
3983
  var checkoutLink = String(ECHO_LINK);
3920
- checkoutLink = Url.extendSearchParams(checkoutLink, 'public_key', this.publicKey);
3984
+ checkoutLink = Url.extendSearchParams(checkoutLink, AccessToken.validateJWT(this.publicKey) ? 'access_token' : 'public_key', this.publicKey);
3921
3985
  checkoutLink = Url.extendSearchParams(checkoutLink, 'json_body', encodeURIComponent(JSON.stringify({
3922
3986
  redirect_uri: this.checkout.link
3923
3987
  })));
@@ -4403,21 +4467,21 @@
4403
4467
  * @constructor
4404
4468
  *
4405
4469
  * @param {string} selector - Selector of html element.
4406
- * @param {string} publicKey - PayDock users public key
4470
+ * @param {string} aceessToken - PayDock access token or users public key
4407
4471
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
4408
4472
  * @param {string} [type=PaypalClassic] - Type of gateway (PaypalClassic, Zipmoney)
4409
4473
  * @example
4410
- * var widget = new CheckoutButton('#button', 'publicKey','gatewayId');
4474
+ * var widget = new CheckoutButton('#button', 'aceessToken','gatewayId');
4411
4475
  **/
4412
4476
  var CheckoutButton = function () {
4413
- function CheckoutButton(selector, publicKey) {
4477
+ function CheckoutButton(selector, aceessToken) {
4414
4478
  var _this = this;
4415
4479
 
4416
4480
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
4417
4481
  var gatewayType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : GATEWAY_TYPE.PAYPAL;
4418
4482
  classCallCheck(this, CheckoutButton);
4419
4483
 
4420
- this.publicKey = publicKey;
4484
+ this.aceessToken = aceessToken;
4421
4485
  this.gatewayId = gatewayId;
4422
4486
  this.gatewayType = gatewayType;
4423
4487
  this.details = null;
@@ -4428,13 +4492,13 @@
4428
4492
  this.background = new Background();
4429
4493
  switch (gatewayType) {
4430
4494
  case GATEWAY_TYPE.PAYPAL:
4431
- this.runner = new PaypalRunner(publicKey);
4495
+ this.runner = new PaypalRunner(aceessToken);
4432
4496
  break;
4433
4497
  case GATEWAY_TYPE.AFTERPAY:
4434
- this.runner = new AfterpayRunner(publicKey);
4498
+ this.runner = new AfterpayRunner(aceessToken);
4435
4499
  break;
4436
4500
  case GATEWAY_TYPE.ZIPMONEY:
4437
- this.runner = new ZipmoneyRunner(publicKey);
4501
+ this.runner = new ZipmoneyRunner(aceessToken);
4438
4502
  break;
4439
4503
  }
4440
4504
  this.initCheckout();
@@ -4456,7 +4520,7 @@
4456
4520
  var externalCheckout = new Builder(_this2.gatewayId, _this2.runner.getSuccessRedirectUri(), _this2.runner.getErrorRedirectUri());
4457
4521
  externalCheckout.setMeta(_this2.meta);
4458
4522
  externalCheckout.setEnv(_this2.env);
4459
- externalCheckout.send(_this2.publicKey, function (checkout) {
4523
+ externalCheckout.send(_this2.aceessToken, function (checkout) {
4460
4524
  _this2.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.POPUP_REDIRECT, {});
4461
4525
  _this2.runner.next(checkout);
4462
4526
  }, function (error, code) {
@@ -4507,7 +4571,7 @@
4507
4571
 
4508
4572
  var checker = new Checker(token);
4509
4573
  checker.setEnv(this.env);
4510
- checker.send(this.publicKey, function (details) {
4574
+ checker.send(this.aceessToken, function (details) {
4511
4575
  _this4.details = details;
4512
4576
  cb();
4513
4577
  }, function () {
@@ -4522,7 +4586,7 @@
4522
4586
 
4523
4587
  var paymentSourceToken = new Builder$1(this.gatewayId, token, TYPE.CHECKOUT_TOKEN);
4524
4588
  paymentSourceToken.setEnv(this.env);
4525
- paymentSourceToken.send(this.publicKey, function (token) {
4589
+ paymentSourceToken.send(this.aceessToken, function (token) {
4526
4590
  _this5.eventEmitter.emit(CHECKOUT_BUTTON_EVENT.FINISH, {
4527
4591
  payment_source_token: token,
4528
4592
  checkout_email: _this5.details.checkout_email,
@@ -4730,21 +4794,21 @@
4730
4794
  * @constructor
4731
4795
  *
4732
4796
  * @param {string} selector - Selector of html element.
4733
- * @param {string} publicKey - PayDock users public key
4797
+ * @param {string} accessToken - PayDock access-token or users public key
4734
4798
  * @param {string} [gatewayId=default] - PayDock's gatewayId. By default or if put 'default', it will use the selected default gateway
4735
4799
  * @example
4736
- * var widget = new AfterpayCheckoutButton('#button', 'publicKey','gatewayId');
4800
+ * var widget = new AfterpayCheckoutButton('#button', 'access-token','gatewayId');
4737
4801
  **/
4738
4802
  var AfterpayCheckoutButton = function (_CheckoutButton) {
4739
4803
  inherits(AfterpayCheckoutButton, _CheckoutButton);
4740
4804
 
4741
- function AfterpayCheckoutButton(selector, publicKey) {
4805
+ function AfterpayCheckoutButton(selector, accessToken) {
4742
4806
  var gatewayId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'default';
4743
4807
  classCallCheck(this, AfterpayCheckoutButton);
4744
4808
 
4745
- 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));
4746
4810
 
4747
- _this.publicKey = publicKey;
4811
+ _this.accessToken = accessToken;
4748
4812
  _this.gatewayId = gatewayId;
4749
4813
  return _this;
4750
4814
  }
@@ -6160,55 +6224,6 @@
6160
6224
  return MastercardWalletService;
6161
6225
  }(WalletService);
6162
6226
 
6163
- var AccessToken = function () {
6164
- function AccessToken() {
6165
- classCallCheck(this, AccessToken);
6166
- }
6167
-
6168
- createClass(AccessToken, null, [{
6169
- key: "validateJWT",
6170
- value: function validateJWT(jwt) {
6171
- var _jwt$split = jwt.split("."),
6172
- _jwt$split2 = slicedToArray(_jwt$split, 3),
6173
- rawHead = _jwt$split2[0],
6174
- rawBody = _jwt$split2[1],
6175
- signature = _jwt$split2[2];
6176
-
6177
- if (!rawHead || !rawBody || !signature) return null;
6178
- if (2 + rawHead.length + rawBody.length + signature.length !== jwt.length) return null;
6179
- try {
6180
- var head = JSON.parse(atob(rawHead));
6181
- var body = JSON.parse(atob(rawBody));
6182
- return { head: head, body: body, signature: signature };
6183
- } catch (_a) {
6184
- return null;
6185
- }
6186
- }
6187
- }, {
6188
- key: "extractData",
6189
- value: function extractData(body) {
6190
- try {
6191
- return JSON.parse(atob(body.meta));
6192
- } catch (_a) {
6193
- return null;
6194
- }
6195
- }
6196
- }, {
6197
- key: "extractMeta",
6198
- value: function extractMeta(body) {
6199
- try {
6200
- var _JSON$parse = JSON.parse(atob(body.meta)),
6201
- meta = _JSON$parse.meta;
6202
-
6203
- return meta;
6204
- } catch (_a) {
6205
- return null;
6206
- }
6207
- }
6208
- }]);
6209
- return AccessToken;
6210
- }();
6211
-
6212
6227
  var API_AUTH_TYPE;
6213
6228
  (function (API_AUTH_TYPE) {
6214
6229
  API_AUTH_TYPE[API_AUTH_TYPE["PUBLIC_KEY"] = 0] = "PUBLIC_KEY";
@@ -6219,7 +6234,7 @@
6219
6234
  classCallCheck(this, ApiBase);
6220
6235
 
6221
6236
  this.auth = auth;
6222
- this.authType = authType || API_AUTH_TYPE.PUBLIC_KEY;
6237
+ this.authType = authType || this.setAuthType();
6223
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.' }]);
6224
6239
  }
6225
6240
  /**
@@ -6234,13 +6249,18 @@
6234
6249
 
6235
6250
 
6236
6251
  createClass(ApiBase, [{
6237
- key: "setEnv",
6252
+ key: 'setEnv',
6238
6253
  value: function setEnv(env, alias) {
6239
6254
  this.env.setEnv(env, alias);
6240
6255
  return this;
6241
6256
  }
6242
6257
  }, {
6243
- 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',
6244
6264
  value: function getClient(method, link) {
6245
6265
  var _this = this;
6246
6266
 
@@ -6259,7 +6279,7 @@
6259
6279
  };
6260
6280
  }
6261
6281
  }, {
6262
- key: "getClientPromise",
6282
+ key: 'getClientPromise',
6263
6283
  value: function getClientPromise(method, link) {
6264
6284
  var _this2 = this;
6265
6285
 
@@ -6282,7 +6302,7 @@
6282
6302
  };
6283
6303
  }
6284
6304
  }, {
6285
- key: "parser",
6305
+ key: 'parser',
6286
6306
  value: function parser(_ref, cb, errorCb) {
6287
6307
  var text = _ref.text,
6288
6308
  status = _ref.status;
@@ -6293,7 +6313,7 @@
6293
6313
  } catch (e) {}
6294
6314
  }
6295
6315
  }, {
6296
- key: "parserPromise",
6316
+ key: 'parserPromise',
6297
6317
  value: function parserPromise(_ref2) {
6298
6318
  var text = _ref2.text,
6299
6319
  status = _ref2.status;
@@ -6306,7 +6326,7 @@
6306
6326
  }
6307
6327
  }
6308
6328
  }, {
6309
- key: "setAuthHeader",
6329
+ key: 'setAuthHeader',
6310
6330
  value: function setAuthHeader(request) {
6311
6331
  switch (this.authType) {
6312
6332
  case API_AUTH_TYPE.PUBLIC_KEY:
@@ -6895,13 +6915,13 @@
6895
6915
  * var widget = new PaymentSourceWidget('publicKey', customerReference, true);
6896
6916
  **/
6897
6917
  var PaymentSourceWidget = function () {
6898
- function PaymentSourceWidget(publicKey, queryToken) {
6918
+ function PaymentSourceWidget(accessToken, queryToken) {
6899
6919
  classCallCheck(this, PaymentSourceWidget);
6900
6920
 
6901
6921
  this.configs = [];
6902
6922
  this.configTokens = [];
6903
6923
  this.link = new Link(PAYMENT_SOURCE_LINK);
6904
- this.link.setParams({ public_key: publicKey, query_token: queryToken });
6924
+ this.link.setParams(_extends({ query_token: queryToken }, AccessToken.validateJWT(accessToken) ? { access_token: accessToken } : { public_key: accessToken }));
6905
6925
  }
6906
6926
  /**
6907
6927
  * Object contain styles for widget