@paydock/client-sdk 1.10.73-beta → 1.10.74-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
@@ -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
  ]);
@@ -4603,10 +4603,42 @@ After you initialized the 3ds charge via `v1/charges/standalone-3ds` API endpoin
4603
4603
  </html>
4604
4604
  ```
4605
4605
 
4606
- **The chargeAuthSuccess event is executed both for frictionless flow, or for challenge flow after the customer has correctly authenticated with the bank using whatever challenge imposed.**
4607
- **The chargeAuthChallenge event is sent before starting a challenge flow (i.e. opening an IFrame for the customer to complete a challenge with ther bank)**
4608
- **The chargeAuthDecoupled event is sent when the flow is a decoupled challenge, alongside a `data.result.description` field that you must show to the customer, indicating the method the user must use to authenticate. For example this may happen by having the cardholder authenticating directly with their banking app through biometrics. Once the end customer does this, the Canvas3ds will be able to recognize the challenge result is ready and will either produce a chargeAuthSuccess or chargeAuthReject event**
4609
- **The error event is sent if an unexpected issue with the client library occurs. In such scenarios, you should consider the autentication process as interrupted**
4606
+ The chargeAuthSuccess event is executed both for frictionless flow, or for challenge flow after the customer has correctly authenticated with the bank using whatever challenge imposed.
4607
+ The chargeAuthChallenge event is sent before starting a challenge flow (i.e. opening an IFrame for the customer to complete a challenge with ther bank)
4608
+ The chargeAuthDecoupled event is sent when the flow is a decoupled challenge, alongside a `data.result.description` field that you must show to the customer, indicating the method the user must use to authenticate. For example this may happen by having the cardholder authenticating directly with their banking app through biometrics. Once the end customer does this, the Canvas3ds will be able to recognize the challenge result is ready and will either produce a chargeAuthSuccess or chargeAuthReject event
4609
+ The error event is sent if an unexpected issue with the client library occurs. In such scenarios, you should consider the autentication process as interrupted
4610
+
4611
+ ### Event and Values
4612
+
4613
+ | Event Value | Type | Description |
4614
+ | ------------------- | ------------------- | -------------------------------------------------------------- |
4615
+ | chargeAuthSuccess | <code>object</code> | Instance of [ChargeEventResponse](#cb_chargeEventResponse) |
4616
+ | chargeAuthReject | <code>object</code> | Instance of [ChargeEventResponse](#cb_chargeEventResponse) |
4617
+ | chargeAuthChallenge | <code>object</code> | Instance of [ChargeEventResponse](#cb_chargeEventResponse) |
4618
+ | chargeAuthDecoupled | <code>object</code> | Instance of [ChargeEventResponse](#cb_chargeEventResponse) |
4619
+ | error | <code>object</code> | Instance of [chargeError](#cb_chargeError) |
4620
+
4621
+ ## Response Values
4622
+
4623
+ <a name="cb_chargeEventResponse" id="cb_chargeEventResponse"></a>
4624
+
4625
+ ### ChargeEventResponse
4626
+
4627
+ | Param | Type | Description |
4628
+ | ------------------------------- | ------------------------------ | -------------------------------------------------------------------------------------------------- |
4629
+ | status | <code>string</code> | status for the event transaction |
4630
+ | charge_3ds_id | <code>string</code> | Universal unique transaction identifier to identify the transaction |
4631
+ | <code>result.description</code> | <code>string</code> [Optional] | field that you must show to the customer, indicating the method the user must use to authenticate. |
4632
+
4633
+ ### ChargeError
4634
+
4635
+ <a name="cb_chargeError" id="cb_chargeError"></a>
4636
+
4637
+ | Param | Type | Description |
4638
+ | ------------- | ------------------- | ------------------------------------------------------------------- |
4639
+ | error | <code>object</code> | error response |
4640
+ | charge_3ds_id | <code>string</code> | Universal unique transaction identifier to identify the transaction |
4641
+
4610
4642
 
4611
4643
  ## Vault Display Widget
4612
4644
  You can find description of all methods and parameters [here](https://www.npmjs.com/package/@paydock/client-sdk#vault-display-widget)
@@ -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) {
@@ -6116,55 +6180,6 @@
6116
6180
  return MastercardWalletService;
6117
6181
  }(WalletService);
6118
6182
 
6119
- var AccessToken = function () {
6120
- function AccessToken() {
6121
- classCallCheck(this, AccessToken);
6122
- }
6123
-
6124
- createClass(AccessToken, null, [{
6125
- key: "validateJWT",
6126
- value: function validateJWT(jwt) {
6127
- var _jwt$split = jwt.split("."),
6128
- _jwt$split2 = slicedToArray(_jwt$split, 3),
6129
- rawHead = _jwt$split2[0],
6130
- rawBody = _jwt$split2[1],
6131
- signature = _jwt$split2[2];
6132
-
6133
- if (!rawHead || !rawBody || !signature) return null;
6134
- if (2 + rawHead.length + rawBody.length + signature.length !== jwt.length) return null;
6135
- try {
6136
- var head = JSON.parse(atob(rawHead));
6137
- var body = JSON.parse(atob(rawBody));
6138
- return { head: head, body: body, signature: signature };
6139
- } catch (_a) {
6140
- return null;
6141
- }
6142
- }
6143
- }, {
6144
- key: "extractData",
6145
- value: function extractData(body) {
6146
- try {
6147
- return JSON.parse(atob(body.meta));
6148
- } catch (_a) {
6149
- return null;
6150
- }
6151
- }
6152
- }, {
6153
- key: "extractMeta",
6154
- value: function extractMeta(body) {
6155
- try {
6156
- var _JSON$parse = JSON.parse(atob(body.meta)),
6157
- meta = _JSON$parse.meta;
6158
-
6159
- return meta;
6160
- } catch (_a) {
6161
- return null;
6162
- }
6163
- }
6164
- }]);
6165
- return AccessToken;
6166
- }();
6167
-
6168
6183
  var API_AUTH_TYPE;
6169
6184
  (function (API_AUTH_TYPE) {
6170
6185
  API_AUTH_TYPE[API_AUTH_TYPE["PUBLIC_KEY"] = 0] = "PUBLIC_KEY";