@kushki/js 1.23.0 → 1.25.0-alpha.12360.1

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/lib/Kushki.d.ts CHANGED
@@ -34,6 +34,7 @@ import { TokenChargeRequest } from "./../lib/types/token_charge_request";
34
34
  import { TokenKPayRequest } from "./../lib/types/token_kpay_request";
35
35
  import { TokenRequest } from "./../lib/types/token_request";
36
36
  import { TransferSubscriptionTokenRequest } from "./../lib/types/transfer_subscription_token_request";
37
+ import { Validate3DsResponse } from "./../lib/types/validate_3ds_response";
37
38
  import { ValidateSessionResponse } from "./../lib/types/validate_session_response";
38
39
  import { VerifyAuthRequest } from "./../lib/types/verify_auth_request";
39
40
  import { VerifyAuthResponse } from "./../lib/types/verify_auth_response";
@@ -99,6 +100,7 @@ export declare class Kushki {
99
100
  requestSavedPaymentMethods(body: SavedPaymentMethodRequest, callback: (value: PaymentDataResponse[] | ErrorResponse) => void): void;
100
101
  requestVerifyAuth(body: VerifyAuthRequest, callback: (value: VerifyAuthResponse | ErrorResponse) => void): void;
101
102
  validateSession(callback: (value: ValidateSessionResponse | ErrorResponse) => void): void;
103
+ validate3DS(body: TokenResponse, callback: (value: Validate3DsResponse) => void): void;
102
104
  private static _callbackError;
103
105
  private _requestBankList;
104
106
  private _resolve;
package/lib/Kushki.js CHANGED
@@ -145,6 +145,9 @@ var Kushki = /** @class */ (function () {
145
145
  Kushki.prototype.validateSession = function (callback) {
146
146
  this._resolve(this._authService.validateSession(this._inTestEnvironment), callback);
147
147
  };
148
+ Kushki.prototype.validate3DS = function (body, callback) {
149
+ this._cardService.validate3DS(body, this._merchantId, this._inTestEnvironment, this._regional, callback);
150
+ };
148
151
  Kushki._callbackError = function (err, callback) {
149
152
  if (err instanceof KushkiError_1.KushkiError)
150
153
  callback({
@@ -12,6 +12,7 @@ import { SubscriptionTokenRequest } from "./../../lib/types/subscription_token_r
12
12
  import { SubscriptionIdRequest } from "./../../lib/types/subscriptionId_request";
13
13
  import { TokenKPayRequest } from "./../../lib/types/token_kpay_request";
14
14
  import { TokenRequest } from "./../../lib/types/token_request";
15
+ import { Validate3DsResponse } from "./../../lib/types/validate_3ds_response";
15
16
  export declare type IGeneralTokenRequest = TokenRequest | TokenKPayRequest | SubscriptionTokenRequest | SubscriptionTokenKPayRequest;
16
17
  export interface ICardService {
17
18
  /**
@@ -54,4 +55,13 @@ export interface ICardService {
54
55
  * @param regional - Define if endpoint used regional URL
55
56
  */
56
57
  requestBinInfo(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<BinInfoResponse>;
58
+ /**
59
+ * BinInfo
60
+ * @param body - token kushki response
61
+ * @param mid - public merchant id
62
+ * @param isTest - is test environment
63
+ * @param regional - Define if endpoint used regional URL
64
+ * @param callback - Define callback function to response
65
+ */
66
+ validate3DS(body: TokenResponse, mid: string, isTest: boolean, regional: boolean, callback: (value: Validate3DsResponse) => void): void;
57
67
  }
@@ -1,4 +1,7 @@
1
1
  /* tslint:disable:all */
2
+ /**
3
+ * Card Service file
4
+ */
2
5
  import "reflect-metadata";
3
6
  import { IAntiFraud } from "./../../lib/repository/IAntiFraud";
4
7
  import { IAuthService } from "./../../lib/repository/IAuthService";
@@ -14,21 +17,30 @@ import { SubscriptionTokenRequest } from "./../../lib/types/subscription_token_r
14
17
  import { SubscriptionIdRequest } from "./../../lib/types/subscriptionId_request";
15
18
  import { TokenKPayRequest } from "./../../lib/types/token_kpay_request";
16
19
  import { TokenRequest } from "./../../lib/types/token_request";
20
+ import { Validate3DsResponse } from "./../../lib/types/validate_3ds_response";
17
21
  /**
18
22
  * Implementation
19
23
  */
24
+ declare global {
25
+ interface Window {
26
+ Cardinal: any;
27
+ KushkiCardinalSandbox: any;
28
+ }
29
+ }
20
30
  export declare class CardService implements ICardService {
21
31
  private readonly _gateway;
22
32
  private readonly _receipt;
23
33
  private readonly _antiFraud;
24
34
  private readonly _authService;
25
35
  private readonly _3Dsecure;
36
+ private _sandboxEnable;
26
37
  constructor(gateway: IKushkiGateway, authService: IAuthService, antiFraud: IAntiFraud);
27
38
  requestToken(request: TokenRequest | TokenKPayRequest, mid: string, isTest: boolean, regional: boolean): Observable<TokenResponse>;
28
39
  requestTokenCharge(request: SubscriptionIdRequest, mid: string, isTest: boolean, regional: boolean): Observable<TokenResponse>;
29
40
  requestSubscriptionToken(subscriptionTokenRequest: SubscriptionTokenRequest | SubscriptionTokenKPayRequest, mid: string, isTest: boolean, regional: boolean): Observable<TokenResponse>;
30
41
  requestDeferred(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<IDeferredResponse[]>;
31
42
  requestBinInfo(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<BinInfoResponse>;
43
+ validate3DS(body: TokenResponse, mid: string, isTest: boolean, regional: boolean, callback: (value: Validate3DsResponse) => void): void;
32
44
  private _checkCardLength;
33
45
  private _getScienceSession;
34
46
  private _checkCurrency;
@@ -37,5 +49,11 @@ export declare class CardService implements ICardService {
37
49
  private _checkRequestBody;
38
50
  private _getCybersourceJwt;
39
51
  private _initCybersource;
52
+ private _completeCardinal;
40
53
  private static _initCardinal;
54
+ private static _ccaCardinal;
55
+ private static _is3dsValid;
56
+ private _setSandboxEnable;
57
+ private _initCybersourceSandbox;
58
+ private static _ccaSandbox;
41
59
  }
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ /**
3
+ * Card Service file
4
+ */
2
5
  var __assign = (this && this.__assign) || function () {
3
6
  __assign = Object.assign || function(t) {
4
7
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -22,11 +25,45 @@ var __metadata = (this && this.__metadata) || function (k, v) {
22
25
  var __param = (this && this.__param) || function (paramIndex, decorator) {
23
26
  return function (target, key) { decorator(target, key, paramIndex); }
24
27
  };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
25
64
  exports.__esModule = true;
26
65
  exports.CardService = void 0;
27
- /**
28
- * Card Service file
29
- */
66
+ var cardinal_sandbox_js_1 = require("@kushki/cardinal-sandbox-js");
30
67
  var Identifiers_1 = require("./../../lib/constant/Identifiers");
31
68
  var dot = require("dot-object");
32
69
  var KushkiError_1 = require("./../../lib/generic/KushkiError");
@@ -35,12 +72,10 @@ var inversify_1 = require("inversify");
35
72
  require("reflect-metadata");
36
73
  var rxjs_1 = require("rxjs");
37
74
  var operators_1 = require("rxjs/operators");
38
- /**
39
- * Implementation
40
- */
41
75
  var CardService = /** @class */ (function () {
42
76
  function CardService(gateway, authService, antiFraud) {
43
77
  this._3Dsecure = "active_3dsecure";
78
+ this._sandboxEnable = false;
44
79
  this._gateway = gateway;
45
80
  this._antiFraud = antiFraud;
46
81
  this._authService = authService;
@@ -65,6 +100,7 @@ var CardService = /** @class */ (function () {
65
100
  CardService.prototype.requestToken = function (request, mid, isTest, regional) {
66
101
  var _this = this;
67
102
  return this._gateway.requestMerchantSettings(mid, isTest, regional).pipe(operators_1.switchMap(function (merchant) {
103
+ _this._setSandboxEnable(!!merchant.sandboxEnable);
68
104
  return rxjs_1.forkJoin([
69
105
  _this._getScienceSession(request, mid, isTest, merchant),
70
106
  _this._getCybersourceJwt(merchant, mid, isTest, regional, Object.prototype.hasOwnProperty.call(request, "card")
@@ -134,6 +170,29 @@ var CardService = /** @class */ (function () {
134
170
  CardService.prototype.requestBinInfo = function (binBody, mid, isTest, regional) {
135
171
  return this._gateway.requestBinInfo(mid, String(binBody.bin).substring(0, 6), isTest, regional);
136
172
  };
173
+ CardService.prototype.validate3DS = function (body, mid, isTest, regional, callback) {
174
+ var _this = this;
175
+ if (this._sandboxEnable)
176
+ return CardService_1._ccaSandbox(body, callback);
177
+ if (isTest) {
178
+ // tslint:disable-next-line:no-duplicate-string
179
+ Promise.resolve().then(function () { return require("cardinal-commerce-songbird-staging"); }).then(function () {
180
+ CardService_1._ccaCardinal(body);
181
+ });
182
+ Promise.resolve().then(function () { return require("cardinal-commerce-songbird-staging"); }).then(function () {
183
+ _this._completeCardinal(body.secureId, mid, isTest, regional, callback);
184
+ });
185
+ }
186
+ else {
187
+ // tslint:disable-next-line:no-duplicate-string
188
+ Promise.resolve().then(function () { return require("cardinal-commerce-songbird"); }).then(function () {
189
+ CardService_1._ccaCardinal(body);
190
+ });
191
+ Promise.resolve().then(function () { return require("cardinal-commerce-songbird"); }).then(function () {
192
+ _this._completeCardinal(body.secureId, mid, isTest, regional, callback);
193
+ });
194
+ }
195
+ };
137
196
  CardService.prototype._checkCardLength = function (request) {
138
197
  if (request.card.number.length < 14 || request.card.number.length > 19)
139
198
  throw new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E005);
@@ -174,7 +233,7 @@ var CardService = /** @class */ (function () {
174
233
  return rxjs_1.of(1).pipe(operators_1.switchMap(function () {
175
234
  if (merchantSettings[_this._3Dsecure] === true &&
176
235
  cardNumber !== undefined)
177
- return _this._initCybersource(cardNumber, mid, isTest, regional);
236
+ return rxjs_1.iif(function () { return !!merchantSettings.sandboxEnable; }, _this._initCybersourceSandbox(mid, isTest, regional), _this._initCybersource(cardNumber, mid, isTest, regional));
178
237
  return rxjs_1.of(undefined);
179
238
  }));
180
239
  };
@@ -192,8 +251,28 @@ var CardService = /** @class */ (function () {
192
251
  return jwt;
193
252
  }));
194
253
  };
254
+ // istanbul ignore next
255
+ CardService.prototype._completeCardinal = function (secureServiceId, mid, isTest, regional, callback) {
256
+ var _this = this;
257
+ return window.Cardinal.on("payments.validated", function () { return __awaiter(_this, void 0, void 0, function () {
258
+ var otp_request, secure;
259
+ return __generator(this, function (_a) {
260
+ otp_request = {
261
+ secureServiceId: secureServiceId,
262
+ otpValue: ""
263
+ };
264
+ secure = this._gateway.requestSecureServiceValidation(mid, otp_request, isTest, regional);
265
+ return [2 /*return*/, secure.subscribe({
266
+ next: function (response) {
267
+ callback({
268
+ isValid: CardService_1._is3dsValid(response)
269
+ });
270
+ }
271
+ })];
272
+ });
273
+ }); });
274
+ };
195
275
  CardService._initCardinal = function (jwt, cardNumber) {
196
- // @ts-ignore
197
276
  window.Cardinal.setup("init", {
198
277
  jwt: jwt,
199
278
  order: {
@@ -205,6 +284,46 @@ var CardService = /** @class */ (function () {
205
284
  }
206
285
  });
207
286
  };
287
+ CardService._ccaCardinal = function (tokenResponse) {
288
+ window.Cardinal["continue"]("cca", {
289
+ AcsUrl: tokenResponse.security.acsURL,
290
+ Payload: tokenResponse.security.paReq
291
+ }, {
292
+ OrderDetails: {
293
+ TransactionId: tokenResponse.security.authenticationTransactionId
294
+ }
295
+ });
296
+ };
297
+ // istanbul ignore next
298
+ CardService._is3dsValid = function (secureOtpResponse) {
299
+ return ("message" in secureOtpResponse &&
300
+ secureOtpResponse.message === "3DS000" &&
301
+ secureOtpResponse.code === "ok");
302
+ };
303
+ CardService.prototype._setSandboxEnable = function (payload) {
304
+ this._sandboxEnable = payload;
305
+ };
306
+ CardService.prototype._initCybersourceSandbox = function (mid, isTest, regional) {
307
+ var _this = this;
308
+ return rxjs_1.of(1).pipe(operators_1.switchMap(function () { return _this._gateway.cybersourceJwt(mid, isTest, regional); }), operators_1.map(function (jwt) {
309
+ cardinal_sandbox_js_1.KushkiCardinalSandbox.init();
310
+ return jwt;
311
+ }));
312
+ };
313
+ CardService._ccaSandbox = function (body, callback) {
314
+ cardinal_sandbox_js_1.KushkiCardinalSandbox["continue"]("cca", {
315
+ AcsUrl: body.security.acsURL,
316
+ Payload: body.security.paReq
317
+ }, {
318
+ OrderDetails: {
319
+ TransactionId: body.security.authenticationTransactionId
320
+ }
321
+ });
322
+ // istanbul ignore next
323
+ cardinal_sandbox_js_1.KushkiCardinalSandbox.on("payments.validated", function () {
324
+ return callback({ isValid: true });
325
+ });
326
+ };
208
327
  var CardService_1;
209
328
  CardService = CardService_1 = __decorate([
210
329
  inversify_1.injectable(),
@@ -8,6 +8,7 @@ export interface MerchantSettingsResponse {
8
8
  sandboxBaconKey: string | null;
9
9
  prodBaconKey: string | null;
10
10
  merchant_name: string;
11
+ sandboxEnable?: boolean;
11
12
  [k: string]: any;
12
13
  }
13
14
  export interface ProcessorSettings {
@@ -3,7 +3,7 @@
3
3
 
4
4
  export interface SubscriptionTokenKPayRequest {
5
5
  walletId: string;
6
- currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN";
6
+ currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "CRC" | "GTQ" | "HNL" | "NIO";
7
7
  userId?: string;
8
8
  sessionId?: string;
9
9
  card?: {
@@ -10,7 +10,7 @@ export interface SubscriptionTokenRequest {
10
10
  number: string;
11
11
  [k: string]: any;
12
12
  };
13
- currency?: "USD" | "COP" | "PEN" | "CLP" | "UF" | "MXN";
13
+ currency?: "USD" | "COP" | "PEN" | "CLP" | "UF" | "MXN" | "CRC" | "GTQ" | "HNL" | "NIO";
14
14
  savePaymentData?: boolean;
15
15
  [k: string]: any;
16
16
  }
@@ -3,7 +3,7 @@
3
3
 
4
4
  export interface TokenKPayRequest {
5
5
  walletId: string;
6
- currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "BRL";
6
+ currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "BRL" | "CRC" | "GTQ" | "HNL" | "NIO";
7
7
  isDeferred?: boolean;
8
8
  amount: number | string;
9
9
  months?: number;
@@ -10,7 +10,7 @@ export interface TokenRequest {
10
10
  number: string;
11
11
  [k: string]: any;
12
12
  };
13
- currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "BRL";
13
+ currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "BRL" | "CRC" | "GTQ" | "HNL" | "NIO";
14
14
  isDeferred?: boolean;
15
15
  amount: number | string;
16
16
  months?: number;
@@ -0,0 +1,6 @@
1
+ /* tslint:disable:all */
2
+ /* tslint:disable:all */
3
+
4
+ export interface Validate3DsResponse {
5
+ isValid?: boolean;
6
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kushki/js",
3
- "version": "1.23.0",
3
+ "version": "1.25.0-alpha.12360.1",
4
4
  "description": "kushki-js",
5
5
  "main": "lib/lib.js",
6
6
  "types": "lib/lib.d.ts",
@@ -94,11 +94,13 @@
94
94
  },
95
95
  "dependencies": {
96
96
  "@aws-amplify/auth": "3.4.22",
97
+ "@kushki/cardinal-sandbox-js": "1.0.0-alpha-12360.2",
97
98
  "acorn": "6.4.1",
98
99
  "aws-amplify": "3.3.19",
99
100
  "axios": "0.21.1",
100
101
  "cardinal-commerce-songbird": "1.0.2",
101
102
  "cardinal-commerce-songbird-staging": "1.0.5",
103
+ "ci": "^2.1.1",
102
104
  "dot-object": "2.1.4",
103
105
  "inversify": "5.0.1",
104
106
  "jsonwebtoken": "8.5.1",