@kushki/js 1.31.1 → 1.31.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.
@@ -10,6 +10,7 @@ import { CashTokenRequest } from "./../../lib/types/cash_token_request";
10
10
  import { DeferredOptionsResponse } from "./../../lib/types/deferred_options_response";
11
11
  import { DeletePaymentMethodRequest } from "./../../lib/types/delete_payment_method_request";
12
12
  import { GetUserId } from "./../../lib/types/get_user_id";
13
+ import { JwtResponse } from "./../../lib/types/jwt_response";
13
14
  import { KushkiSubscriptionTokensRequest } from "./../../lib/types/kushki_subscription_tokens_request";
14
15
  import { KushkiTokensRequest } from "./../../lib/types/kushki_tokens_request";
15
16
  import { MerchantSettingsResponse } from "./../../lib/types/merchant_settings_response";
@@ -73,7 +74,7 @@ export declare class KushkiGateway implements IKushkiGateway {
73
74
  chargeMobileProcessor(body: MobileProcessorChargeRequest, publicCredential: string, testEnv: boolean, regional: boolean): Observable<MobileProcessorChargeResponse>;
74
75
  deletePaymentMethod(body: DeletePaymentMethodRequest, testEnv: boolean, regional: boolean, mid: string, authorization: string): Observable<boolean>;
75
76
  requestSavedPaymentMethods(body: SavedPaymentMethodRequest, testEnv: boolean, regional: boolean, mid: string): Observable<PaymentDataResponse[]>;
76
- cybersourceJwt(mid: string, testEnv: boolean, regional: boolean): Observable<string>;
77
+ cybersourceJwt(mid: string, testEnv: boolean, regional: boolean, subscriptionId?: string): Observable<JwtResponse>;
77
78
  getUserId(subscriptionId: string, mid: string, testEnv: boolean, regional: boolean): Observable<GetUserId>;
78
79
  private _assignChannel;
79
80
  private _buildHeader;
@@ -248,11 +248,13 @@ var KushkiGateway = /** @class */ (function () {
248
248
  return _this.requestGet(path, testEnv, regional, mid);
249
249
  }), operators_1.map(function (response) { return response; }));
250
250
  };
251
- KushkiGateway.prototype.cybersourceJwt = function (mid, testEnv, regional) {
251
+ KushkiGateway.prototype.cybersourceJwt = function (mid, testEnv, regional, subscriptionId) {
252
252
  var _this = this;
253
253
  return rxjs_1.of(1).pipe(operators_1.concatMap(function () {
254
- return _this.requestGet(PathEnum_1.PathEnum.cybersource_jwt, testEnv, regional, mid);
255
- }), operators_1.map(function (response) { return response.jwt; }));
254
+ return _this.requestGet(subscriptionId
255
+ ? PathEnum_1.PathEnum.cybersource_jwt + "?subscriptionId=" + subscriptionId
256
+ : PathEnum_1.PathEnum.cybersource_jwt, testEnv, regional, mid);
257
+ }), operators_1.map(function (response) { return response; }));
256
258
  };
257
259
  KushkiGateway.prototype.getUserId = function (subscriptionId, mid, testEnv, regional) {
258
260
  var _this = this;
@@ -11,6 +11,7 @@ import { CashTokenRequest } from "./../../lib/types/cash_token_request";
11
11
  import { DeferredOptionsResponse } from "./../../lib/types/deferred_options_response";
12
12
  import { DeletePaymentMethodRequest } from "./../../lib/types/delete_payment_method_request";
13
13
  import { GetUserId } from "./../../lib/types/get_user_id";
14
+ import { JwtResponse } from "./../../lib/types/jwt_response";
14
15
  import { KushkiSubscriptionTokensRequest } from "./../../lib/types/kushki_subscription_tokens_request";
15
16
  import { KushkiTokensRequest } from "./../../lib/types/kushki_tokens_request";
16
17
  import { MerchantSettingsResponse } from "./../../lib/types/merchant_settings_response";
@@ -161,7 +162,7 @@ export interface IKushkiGateway {
161
162
  * @param testEnv - is test environment
162
163
  * @param regional - Define if endpoint used regional URL
163
164
  */
164
- cybersourceJwt(mid: string, testEnv: boolean, regional: boolean): Observable<string>;
165
+ cybersourceJwt(mid: string, testEnv: boolean, regional: boolean, subscriptionId?: string): Observable<JwtResponse>;
165
166
  /**
166
167
  * Get userId
167
168
  * @param subscriptionId subscription id for the request
@@ -61,7 +61,12 @@ export declare class CardService implements ICardService {
61
61
  private _checkAmount;
62
62
  private _checkRequestBody;
63
63
  private _getCybersourceJwt;
64
+ private _isSandboxEnabled;
65
+ private _getCybersourceJwtSubscription;
66
+ private _is3DSSecureEnabled;
64
67
  private _initCybersource;
68
+ private _initializeCardinal;
69
+ private _initCybersourceSubscription;
65
70
  private _completeCardinal;
66
71
  private static _initCardinal;
67
72
  private static _ccaCardinal;
@@ -157,9 +157,7 @@ var CardService = /** @class */ (function () {
157
157
  _this._setSandboxEnable(!!merchant.sandboxEnable);
158
158
  return rxjs_1.forkJoin([
159
159
  _this._getDeviceTokenSiftScienceObject(request, mid, isTest, merchant, regional),
160
- _this._getCybersourceJwt(merchant, mid, isTest, regional, Object.prototype.hasOwnProperty.call(request, "cardNumber")
161
- ? request.cardNumber
162
- : undefined),
160
+ _this._getCybersourceJwtSubscription(merchant, mid, isTest, regional, request.subscriptionId),
163
161
  ]);
164
162
  }), operators_1.switchMap(function (_a) {
165
163
  var sift_science_obj = _a[0], jwt = _a[1];
@@ -243,7 +241,7 @@ var CardService = /** @class */ (function () {
243
241
  CardService.prototype.requestSecureInit = function (request, mid, isTest, regional) {
244
242
  var _this = this;
245
243
  return rxjs_1.of(1).pipe(operators_1.map(function () { return _this._checkCardLength(request, ErrorEnum_1.ErrorCode.E014); }), operators_1.switchMap(function () { return _this._getMerchantSettings(mid, isTest, regional); }), operators_1.switchMap(function (merchantSettings) {
246
- return rxjs_1.iif(function () { return merchantSettings[_this._3Dsecure] === true; }, rxjs_1.of(merchantSettings), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E013)));
244
+ return rxjs_1.iif(function () { return _this._is3DSSecureEnabled(merchantSettings); }, rxjs_1.of(merchantSettings), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E013)));
247
245
  }), operators_1.switchMap(function (merchant) {
248
246
  return _this._getCybersourceJwt(merchant, mid, isTest, regional, request.card.number);
249
247
  }), operators_1.map(function (jwt) { return ({
@@ -352,24 +350,51 @@ var CardService = /** @class */ (function () {
352
350
  CardService.prototype._getCybersourceJwt = function (merchantSettings, mid, isTest, regional, cardNumber) {
353
351
  var _this = this;
354
352
  return rxjs_1.of(1).pipe(operators_1.switchMap(function () {
355
- if (merchantSettings[_this._3Dsecure] === true &&
353
+ if (_this._is3DSSecureEnabled(merchantSettings) &&
356
354
  cardNumber !== undefined)
357
- return rxjs_1.iif(function () { return !!merchantSettings.sandboxEnable; }, _this._initCybersourceSandbox(mid, isTest, regional), _this._initCybersource(cardNumber, mid, isTest, regional));
355
+ return rxjs_1.iif(function () { return _this._isSandboxEnabled(merchantSettings); }, _this._initCybersourceSandbox(mid, isTest, regional), _this._initCybersource(cardNumber, mid, isTest, regional));
356
+ return rxjs_1.of(undefined);
357
+ }));
358
+ };
359
+ CardService.prototype._isSandboxEnabled = function (merchantSettings) {
360
+ return !!merchantSettings.sandboxEnable;
361
+ };
362
+ CardService.prototype._getCybersourceJwtSubscription = function (merchantSettings, mid, isTest, regional, subscriptionId) {
363
+ var _this = this;
364
+ return rxjs_1.of(1).pipe(operators_1.switchMap(function () {
365
+ if (_this._is3DSSecureEnabled(merchantSettings))
366
+ return rxjs_1.iif(function () { return _this._isSandboxEnabled(merchantSettings); }, _this._initCybersourceSandbox(mid, isTest, regional), _this._initCybersourceSubscription(subscriptionId, mid, isTest, regional));
358
367
  return rxjs_1.of(undefined);
359
368
  }));
360
369
  };
370
+ CardService.prototype._is3DSSecureEnabled = function (merchantSettings) {
371
+ return merchantSettings[this._3Dsecure] === true;
372
+ };
361
373
  CardService.prototype._initCybersource = function (cardNumber, mid, isTest, regional) {
362
374
  var _this = this;
363
- return rxjs_1.of(1).pipe(operators_1.switchMap(function () { return _this._gateway.cybersourceJwt(mid, isTest, regional); }), operators_1.map(function (jwt) {
364
- if (isTest)
365
- Promise.resolve().then(function () { return require("./../../lib/libs/cardinal/staging"); }).then(function () {
366
- CardService_1._initCardinal(jwt, cardNumber);
367
- });
368
- else
369
- Promise.resolve().then(function () { return require("./../../lib/libs/cardinal/prod"); }).then(function () {
370
- CardService_1._initCardinal(jwt, cardNumber);
371
- });
372
- return jwt;
375
+ return rxjs_1.of(1).pipe(operators_1.switchMap(function () { return _this._gateway.cybersourceJwt(mid, isTest, regional); }), operators_1.map(function (jwtResponse) {
376
+ _this._initializeCardinal(isTest, jwtResponse.jwt, cardNumber);
377
+ return jwtResponse.jwt;
378
+ }));
379
+ };
380
+ CardService.prototype._initializeCardinal = function (isTest, jwt, identifier) {
381
+ if (isTest)
382
+ Promise.resolve().then(function () { return require("./../../lib/libs/cardinal/staging"); }).then(function () {
383
+ CardService_1._initCardinal(jwt, identifier);
384
+ });
385
+ else
386
+ Promise.resolve().then(function () { return require("./../../lib/libs/cardinal/prod"); }).then(function () {
387
+ CardService_1._initCardinal(jwt, identifier);
388
+ });
389
+ };
390
+ CardService.prototype._initCybersourceSubscription = function (subscriptionId, mid, isTest, regional) {
391
+ var _this = this;
392
+ return rxjs_1.of(1).pipe(operators_1.switchMap(function () {
393
+ return _this._gateway.cybersourceJwt(mid, isTest, regional, subscriptionId);
394
+ }), operators_1.map(function (jwtResponse) {
395
+ var bin = Buffer.from(jwtResponse.identifier, "base64").toString("ascii");
396
+ _this._initializeCardinal(isTest, jwtResponse.jwt, bin);
397
+ return jwtResponse.jwt;
373
398
  }));
374
399
  };
375
400
  // istanbul ignore next
@@ -431,9 +456,9 @@ var CardService = /** @class */ (function () {
431
456
  };
432
457
  CardService.prototype._initCybersourceSandbox = function (mid, isTest, regional) {
433
458
  var _this = this;
434
- return rxjs_1.of(1).pipe(operators_1.switchMap(function () { return _this._gateway.cybersourceJwt(mid, isTest, regional); }), operators_1.map(function (jwt) {
459
+ return rxjs_1.of(1).pipe(operators_1.switchMap(function () { return _this._gateway.cybersourceJwt(mid, isTest, regional); }), operators_1.map(function (jwtResponse) {
435
460
  cardinal_sandbox_js_1.KushkiCardinalSandbox.init();
436
- return jwt;
461
+ return jwtResponse.jwt;
437
462
  }));
438
463
  };
439
464
  CardService.prototype._ccaSandbox = function (body, mid, isTest, regional, callback) {
@@ -3,4 +3,5 @@
3
3
 
4
4
  export interface JwtResponse {
5
5
  jwt: string;
6
+ identifier?: string;
6
7
  }
@@ -9,7 +9,6 @@ export interface SubscriptionIdRequest {
9
9
  sessionId?: string | null;
10
10
  amount?: Amount;
11
11
  currency?: Currency;
12
- cardNumber?: string;
13
12
  cardHolderName?: string;
14
13
  [k: string]: any;
15
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kushki/js",
3
- "version": "1.31.1",
3
+ "version": "1.31.2",
4
4
  "description": "kushki-js",
5
5
  "main": "lib/lib.js",
6
6
  "types": "lib/lib.d.ts",