@kushki/js 1.40.2-alpha → 1.40.2-alpha-19735.0
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 +19 -2
- package/lib/Kushki.js +17 -0
- package/lib/KushkiInfo.js +1 -1
- package/lib/constant/Identifiers.d.ts +2 -0
- package/lib/constant/Identifiers.js +2 -0
- package/lib/gateway/KushkiGateway.d.ts +9 -3
- package/lib/gateway/KushkiGateway.js +33 -6
- package/lib/infrastructure/Container.js +5 -1
- package/lib/infrastructure/KPayUserPoolEnum.d.ts +5 -0
- package/lib/infrastructure/KPayUserPoolEnum.js +8 -0
- package/lib/infrastructure/KpayPaymentKind.d.ts +6 -0
- package/lib/infrastructure/KpayPaymentKind.js +9 -0
- package/lib/infrastructure/PathEnum.d.ts +3 -0
- package/lib/infrastructure/PathEnum.js +3 -0
- package/lib/repository/IAuthService.d.ts +20 -0
- package/lib/repository/IAuthService.js +2 -0
- package/lib/repository/ICardService.d.ts +5 -3
- package/lib/repository/IKPayService.d.ts +26 -0
- package/lib/repository/IKPayService.js +2 -0
- package/lib/repository/IKushkiGateway.d.ts +24 -2
- package/lib/service/ApplePayService.js +1 -1
- package/lib/service/AuthService.d.ts +31 -0
- package/lib/service/AuthService.js +161 -0
- package/lib/service/CardService.d.ts +7 -3
- package/lib/service/CardService.js +42 -18
- package/lib/service/KPayService.d.ts +19 -0
- package/lib/service/KPayService.js +45 -0
- package/lib/types/apple_pay_get_token_events.d.ts +8 -2
- package/lib/types/apple_pay_get_token_request.d.ts +20 -0
- package/lib/types/delete_payment_method_request.d.ts +6 -0
- package/lib/types/delete_payment_method_response.d.ts +7 -0
- package/lib/types/init_auth_request.d.ts +6 -0
- package/lib/types/init_auth_response.d.ts +6 -0
- package/lib/types/payment_data_response.d.ts +37 -0
- package/lib/types/saved_payment_data_request.d.ts +10 -0
- package/lib/types/subscription_token_kpay_request.d.ts +13 -0
- package/lib/types/token_kpay_request.d.ts +12 -0
- package/lib/types/validate_session_response.d.ts +6 -0
- package/lib/types/verify_auth_request.d.ts +7 -0
- package/lib/types/verify_auth_response.d.ts +7 -0
- package/package.json +5 -3
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var AuthService_1;
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.AuthService = void 0;
|
|
26
|
+
const aws_amplify_1 = require("aws-amplify");
|
|
27
|
+
const axios_1 = require("axios");
|
|
28
|
+
const Identifiers_1 = require("./../../lib/constant/Identifiers");
|
|
29
|
+
const KushkiError_1 = require("./../../lib/generic/KushkiError");
|
|
30
|
+
const CognitoErrorEnum_1 = require("./../../lib/infrastructure/CognitoErrorEnum");
|
|
31
|
+
const ErrorEnum_1 = require("./../../lib/infrastructure/ErrorEnum");
|
|
32
|
+
const KPayUserPoolEnum_1 = require("./../../lib/infrastructure/KPayUserPoolEnum");
|
|
33
|
+
const inversify_1 = require("inversify");
|
|
34
|
+
require("reflect-metadata");
|
|
35
|
+
const rxjs_1 = require("rxjs");
|
|
36
|
+
const operators_1 = require("rxjs/operators");
|
|
37
|
+
const UtilsService_1 = require("./../../lib/service/UtilsService");
|
|
38
|
+
/**
|
|
39
|
+
* Implementation
|
|
40
|
+
*/
|
|
41
|
+
let AuthService = AuthService_1 = class AuthService {
|
|
42
|
+
constructor(gateway) {
|
|
43
|
+
this._gateway = gateway;
|
|
44
|
+
}
|
|
45
|
+
requestInitAuth(body, isTestEnvironment) {
|
|
46
|
+
return rxjs_1.of(1).pipe(operators_1.mergeMap(() => AuthService_1._configureAmplifyCredentials(isTestEnvironment)), operators_1.mergeMap(() => this._validateCurrentSession(body.email)), operators_1.mergeMap(sessionJwt => rxjs_1.iif(() => !!sessionJwt, rxjs_1.of({ result: true }), this._handleInitAuth(body.email))));
|
|
47
|
+
}
|
|
48
|
+
requestVerifyAuth(code, isTestEnvironment) {
|
|
49
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => AuthService_1._configureAmplifyCredentials(isTestEnvironment)), operators_1.concatMap(() => rxjs_1.from(aws_amplify_1.Auth.sendCustomChallengeAnswer(this._cognitoUser, code))), operators_1.catchError(() => rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E009))), operators_1.concatMap(() => this._verifyCurrentSession()), operators_1.map(session => ({
|
|
50
|
+
authorization: session.getRefreshToken().getToken(),
|
|
51
|
+
})));
|
|
52
|
+
}
|
|
53
|
+
validateSession(isTestEnvironment) {
|
|
54
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => AuthService_1._configureAmplifyCredentials(isTestEnvironment)), operators_1.concatMap(() => this._getCurrentUserEmail()));
|
|
55
|
+
}
|
|
56
|
+
getAuthorizationToken() {
|
|
57
|
+
return rxjs_1.of(1).pipe(operators_1.mergeMap(() => this._currentAuthenticatedUser()), operators_1.mergeMap((cognitoUser) => {
|
|
58
|
+
const session = cognitoUser ? cognitoUser.getSignInUserSession() : null;
|
|
59
|
+
if (!session)
|
|
60
|
+
return rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E011));
|
|
61
|
+
return rxjs_1.of(session.getAccessToken().getJwtToken());
|
|
62
|
+
}), operators_1.catchError(() => rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E011))));
|
|
63
|
+
}
|
|
64
|
+
_currentAuthenticatedUser() {
|
|
65
|
+
return rxjs_1.of(1).pipe(operators_1.mergeMap(() => rxjs_1.from(aws_amplify_1.Auth.currentAuthenticatedUser())));
|
|
66
|
+
}
|
|
67
|
+
_verifyCurrentSession() {
|
|
68
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => rxjs_1.from(aws_amplify_1.Auth.currentSession())), operators_1.catchError(() => rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E008))));
|
|
69
|
+
}
|
|
70
|
+
_handleInitAuth(email) {
|
|
71
|
+
const password = AuthService_1._getRandomString();
|
|
72
|
+
return rxjs_1.of(1).pipe(operators_1.mergeMap(() => {
|
|
73
|
+
const user_attributes = {
|
|
74
|
+
"custom:merchant": email,
|
|
75
|
+
given_name: email,
|
|
76
|
+
preferred_username: email,
|
|
77
|
+
};
|
|
78
|
+
const params = {
|
|
79
|
+
password,
|
|
80
|
+
attributes: user_attributes,
|
|
81
|
+
username: email,
|
|
82
|
+
};
|
|
83
|
+
return rxjs_1.from(aws_amplify_1.Auth.signUp(params));
|
|
84
|
+
}), operators_1.concatMap(() => this._userSignIn(email, password)), operators_1.concatMap((cognitoUser) => {
|
|
85
|
+
this._cognitoUser = cognitoUser;
|
|
86
|
+
return cognitoUser
|
|
87
|
+
.getSignInUserSession()
|
|
88
|
+
.getAccessToken()
|
|
89
|
+
.getJwtToken();
|
|
90
|
+
}), operators_1.concatMap((authorization) => rxjs_1.iif(() => !!authorization, rxjs_1.of({ result: true }), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E001)))), operators_1.catchError((error) => {
|
|
91
|
+
const error_code = UtilsService_1.UtilsService.sGet(error, "code", "");
|
|
92
|
+
return rxjs_1.iif(() => error_code === CognitoErrorEnum_1.CognitoErrorEnum.UsernameExistsException, this._userSignInPasswordles(email), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E007)));
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
_validateCurrentSession(email) {
|
|
96
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => aws_amplify_1.Auth.currentSession()), operators_1.concatMap(session => rxjs_1.forkJoin([rxjs_1.of(session), rxjs_1.from(aws_amplify_1.Auth.currentUserInfo())])), operators_1.concatMap(([session, current_user_info]) => {
|
|
97
|
+
if (email &&
|
|
98
|
+
current_user_info.attributes.email.toLowerCase() !==
|
|
99
|
+
email.toLowerCase())
|
|
100
|
+
return this._signOut();
|
|
101
|
+
return rxjs_1.of(session.getAccessToken().getJwtToken());
|
|
102
|
+
}), operators_1.catchError(() => this._signOut()));
|
|
103
|
+
}
|
|
104
|
+
_getCurrentUserEmail() {
|
|
105
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => aws_amplify_1.Auth.currentUserInfo()), operators_1.concatMap(currentInfo => rxjs_1.iif(() => !!currentInfo.attributes.email, rxjs_1.of({
|
|
106
|
+
email: currentInfo.attributes.email.toLowerCase(),
|
|
107
|
+
}), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E011)))), operators_1.catchError(() => rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E011))));
|
|
108
|
+
}
|
|
109
|
+
_signOut() {
|
|
110
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => aws_amplify_1.Auth.signOut()), operators_1.mapTo(false));
|
|
111
|
+
}
|
|
112
|
+
_userSignIn(email, password) {
|
|
113
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => rxjs_1.from(aws_amplify_1.Auth.signIn(email, password))));
|
|
114
|
+
}
|
|
115
|
+
_userSignInPasswordles(email) {
|
|
116
|
+
return rxjs_1.of(1).pipe(operators_1.mergeMap(() => rxjs_1.from(aws_amplify_1.Auth.signIn(email))), operators_1.mergeMap((cognitoUser) => {
|
|
117
|
+
this._cognitoUser = cognitoUser;
|
|
118
|
+
return rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E010));
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
static _configureAmplifyCredentials(test) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
const remote_kpay_user_pool_url = `${test ? KPayUserPoolEnum_1.KPayUserPoolEnum.uat : KPayUserPoolEnum_1.KPayUserPoolEnum.prod}`;
|
|
124
|
+
const { data: cognito_config } = yield axios_1.default.get(remote_kpay_user_pool_url);
|
|
125
|
+
const auth = {
|
|
126
|
+
cognito: {
|
|
127
|
+
APP_CLIENT_ID: cognito_config.appClientId,
|
|
128
|
+
REGION: cognito_config.region,
|
|
129
|
+
USER_POOL_ID: cognito_config.userPoolId,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
aws_amplify_1.Auth.configure({
|
|
133
|
+
Auth: {
|
|
134
|
+
mandatorySignId: true,
|
|
135
|
+
region: auth.cognito.REGION,
|
|
136
|
+
storage: UtilsService_1.UtilsService.sIsEmpty(window) ? "" : window.sessionStorage,
|
|
137
|
+
userPoolId: auth.cognito.USER_POOL_ID,
|
|
138
|
+
userPoolWebClientId: auth.cognito.APP_CLIENT_ID,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
static _getRandomString() {
|
|
144
|
+
return (
|
|
145
|
+
// tslint:disable-next-line:insecure-random
|
|
146
|
+
Math.random()
|
|
147
|
+
.toString(36)
|
|
148
|
+
.slice(2) +
|
|
149
|
+
// tslint:disable-next-line:insecure-random
|
|
150
|
+
Math.random()
|
|
151
|
+
.toString(36)
|
|
152
|
+
.toUpperCase()
|
|
153
|
+
.slice(2));
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
AuthService = AuthService_1 = __decorate([
|
|
157
|
+
inversify_1.injectable(),
|
|
158
|
+
__param(0, inversify_1.inject(Identifiers_1.IDENTIFIERS.KushkiGateway)),
|
|
159
|
+
__metadata("design:paramtypes", [Object])
|
|
160
|
+
], AuthService);
|
|
161
|
+
exports.AuthService = AuthService;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import "reflect-metadata";
|
|
6
6
|
import { IAntiFraud } from "./../../lib/repository/IAntiFraud";
|
|
7
|
+
import { IAuthService } from "./../../lib/repository/IAuthService";
|
|
7
8
|
import { ICardService } from "./../../lib/repository/ICardService";
|
|
8
9
|
import { IKushkiGateway } from "./../../lib/repository/IKushkiGateway";
|
|
9
10
|
import { Observable } from "rxjs";
|
|
@@ -14,8 +15,10 @@ import { IDeferredResponse } from "./../../lib/types/remote/deferred_response";
|
|
|
14
15
|
import { TokenResponse } from "./../../lib/types/remote/token_response";
|
|
15
16
|
import { SecureInitRequest } from "./../../lib/types/secure_init_request";
|
|
16
17
|
import { SecureInitResponse } from "./../../lib/types/secure_init_response";
|
|
18
|
+
import { SubscriptionTokenKPayRequest } from "./../../lib/types/subscription_token_kpay_request";
|
|
17
19
|
import { SubscriptionTokenRequest } from "./../../lib/types/subscription_token_request";
|
|
18
20
|
import { SubscriptionIdRequest } from "./../../lib/types/subscriptionId_request";
|
|
21
|
+
import { TokenKPayRequest } from "./../../lib/types/token_kpay_request";
|
|
19
22
|
import { TokenRequest } from "./../../lib/types/token_request";
|
|
20
23
|
import { Validate3DSRequest } from "./../../lib/types/validate_3ds_request";
|
|
21
24
|
import { Validate3DsResponse } from "./../../lib/types/validate_3ds_response";
|
|
@@ -32,15 +35,16 @@ export declare class CardService implements ICardService {
|
|
|
32
35
|
private readonly _gateway;
|
|
33
36
|
private readonly _receipt;
|
|
34
37
|
private readonly _antiFraud;
|
|
38
|
+
private readonly _authService;
|
|
35
39
|
private readonly _3Dsecure;
|
|
36
40
|
private readonly _cardNumber;
|
|
37
41
|
private _sandboxEnable;
|
|
38
42
|
private readonly _paymentValidatedEvent;
|
|
39
43
|
private readonly _paymentSetupCompleteEvent;
|
|
40
|
-
constructor(gateway: IKushkiGateway, antiFraud: IAntiFraud);
|
|
41
|
-
requestToken(request: TokenRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
44
|
+
constructor(gateway: IKushkiGateway, authService: IAuthService, antiFraud: IAntiFraud);
|
|
45
|
+
requestToken(request: TokenRequest | TokenKPayRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
42
46
|
requestDeviceToken(request: SubscriptionIdRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
43
|
-
requestSubscriptionToken(subscriptionTokenRequest: SubscriptionTokenRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
47
|
+
requestSubscriptionToken(subscriptionTokenRequest: SubscriptionTokenRequest | SubscriptionTokenKPayRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
44
48
|
requestDeferred(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<IDeferredResponse[]>;
|
|
45
49
|
requestBinInfo(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<BinInfoResponse>;
|
|
46
50
|
validate3DS(body: Validate3DSRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: Validate3DsResponse | ErrorResponse) => void): void;
|
|
@@ -42,7 +42,7 @@ const operators_1 = require("rxjs/operators");
|
|
|
42
42
|
const UtilsService_1 = require("./../../lib/service/UtilsService");
|
|
43
43
|
const Kushki_1 = require("./../../lib/Kushki");
|
|
44
44
|
let CardService = CardService_1 = class CardService {
|
|
45
|
-
constructor(gateway, antiFraud) {
|
|
45
|
+
constructor(gateway, authService, antiFraud) {
|
|
46
46
|
this._3Dsecure = "active_3dsecure";
|
|
47
47
|
this._cardNumber = "card.number";
|
|
48
48
|
this._sandboxEnable = false;
|
|
@@ -50,6 +50,7 @@ let CardService = CardService_1 = class CardService {
|
|
|
50
50
|
this._paymentSetupCompleteEvent = "payments.setupComplete";
|
|
51
51
|
this._gateway = gateway;
|
|
52
52
|
this._antiFraud = antiFraud;
|
|
53
|
+
this._authService = authService;
|
|
53
54
|
this._receipt = {
|
|
54
55
|
amount: "totalAmount",
|
|
55
56
|
"card.cvc": "card.cvv",
|
|
@@ -83,28 +84,37 @@ let CardService = CardService_1 = class CardService {
|
|
|
83
84
|
this._setSandboxEnable(!!merchant.sandboxEnable);
|
|
84
85
|
return rxjs_1.forkJoin([
|
|
85
86
|
this._getScienceSession(request, mid, isTest, merchant),
|
|
86
|
-
this._getCybersourceJwt(merchant, mid, isTest, regional, request
|
|
87
|
+
this._getCybersourceJwt(merchant, mid, isTest, regional, Object.prototype.hasOwnProperty.call(request, "card")
|
|
88
|
+
? request.card.number
|
|
89
|
+
: undefined),
|
|
87
90
|
rxjs_1.of(merchant),
|
|
88
91
|
]);
|
|
89
92
|
}), operators_1.mergeMap(([sift_object, jwt, merchant]) => {
|
|
90
93
|
request.isDeferred =
|
|
91
94
|
request.isDeferred === undefined ? false : request.isDeferred;
|
|
95
|
+
if (Boolean(request.cvv))
|
|
96
|
+
request.card = { cvc: request.cvv };
|
|
92
97
|
this._checkRequestBody(request);
|
|
93
98
|
const data_to_transform = Object.assign(Object.assign({}, request), sift_object);
|
|
94
99
|
if (jwt !== undefined)
|
|
95
100
|
data_to_transform.jwt = jwt;
|
|
96
|
-
|
|
97
|
-
|
|
101
|
+
return rxjs_1.forkJoin([
|
|
102
|
+
rxjs_1.of(dot.transform(this._receipt, Object.assign(Object.assign({}, data_to_transform), { merchantName: merchant.merchant_name }))),
|
|
103
|
+
request.walletId
|
|
104
|
+
? this._authService.getAuthorizationToken()
|
|
105
|
+
: rxjs_1.of(undefined),
|
|
106
|
+
rxjs_1.of(merchant),
|
|
107
|
+
]);
|
|
98
108
|
}))
|
|
99
109
|
.subscribe({
|
|
100
110
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
101
|
-
next: (
|
|
111
|
+
next: ([final_request, authorization, merchant]) => {
|
|
102
112
|
if (final_request.jwt && !merchant.sandboxEnable)
|
|
103
113
|
this._request3DSToken(() => {
|
|
104
|
-
this._requestTokenGateway(final_request, mid, isTest, regional, callback);
|
|
114
|
+
this._requestTokenGateway(final_request, mid, isTest, regional, callback, authorization);
|
|
105
115
|
});
|
|
106
116
|
else
|
|
107
|
-
this._requestTokenGateway(final_request, mid, isTest, regional, callback);
|
|
117
|
+
this._requestTokenGateway(final_request, mid, isTest, regional, callback, authorization);
|
|
108
118
|
},
|
|
109
119
|
});
|
|
110
120
|
}
|
|
@@ -154,18 +164,23 @@ let CardService = CardService_1 = class CardService {
|
|
|
154
164
|
const data_to_transform = this._getCreateSubscriptionDataToTransform(sift_object, subscriptionTokenRequest);
|
|
155
165
|
if (jwt !== undefined)
|
|
156
166
|
data_to_transform.jwt = jwt;
|
|
157
|
-
|
|
158
|
-
|
|
167
|
+
return rxjs_1.forkJoin([
|
|
168
|
+
rxjs_1.of(dot.transform(this._receipt, Object.assign(Object.assign({}, data_to_transform), { merchantName: merchant.merchant_name }))),
|
|
169
|
+
subscriptionTokenRequest.walletId
|
|
170
|
+
? this._authService.getAuthorizationToken()
|
|
171
|
+
: rxjs_1.of(undefined),
|
|
172
|
+
rxjs_1.of(merchant),
|
|
173
|
+
]);
|
|
159
174
|
}))
|
|
160
175
|
.subscribe({
|
|
161
176
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
162
|
-
next: (
|
|
177
|
+
next: ([body, jwt, merchant]) => {
|
|
163
178
|
if (body.jwt && !merchant.sandboxEnable)
|
|
164
179
|
this._request3DSToken(() => {
|
|
165
|
-
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback);
|
|
180
|
+
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback, jwt);
|
|
166
181
|
});
|
|
167
182
|
else
|
|
168
|
-
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback);
|
|
183
|
+
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback, jwt);
|
|
169
184
|
},
|
|
170
185
|
});
|
|
171
186
|
}
|
|
@@ -261,7 +276,14 @@ let CardService = CardService_1 = class CardService {
|
|
|
261
276
|
throw new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS[ErrorEnum_1.ErrorCode.E014]);
|
|
262
277
|
}
|
|
263
278
|
_getScienceSession(request, mid, isTest, merchant) {
|
|
264
|
-
return rxjs_1.of(1).pipe(operators_1.switchMap(() =>
|
|
279
|
+
return rxjs_1.of(1).pipe(operators_1.switchMap(() => {
|
|
280
|
+
if (request.card && request.card.number !== undefined)
|
|
281
|
+
return this._antiFraud.createSiftScienceSession(UtilsService_1.getBinFromCreditCardNumberSift(request.card.number), request.card.number.slice(-4), mid, isTest, merchant);
|
|
282
|
+
return rxjs_1.of({
|
|
283
|
+
sessionId: null,
|
|
284
|
+
userId: null,
|
|
285
|
+
});
|
|
286
|
+
}));
|
|
265
287
|
}
|
|
266
288
|
_checkCurrency(request) {
|
|
267
289
|
request.currency =
|
|
@@ -279,7 +301,8 @@ let CardService = CardService_1 = class CardService {
|
|
|
279
301
|
}
|
|
280
302
|
_checkRequestBody(request) {
|
|
281
303
|
this._checkCurrency(request);
|
|
282
|
-
|
|
304
|
+
if (Boolean(request.card) && Boolean(request.card.number))
|
|
305
|
+
this._checkCardLength(request);
|
|
283
306
|
this._checkAmount(request);
|
|
284
307
|
}
|
|
285
308
|
_getCybersourceJwt(merchantSettings, mid, isTest, regional, cardNumber) {
|
|
@@ -437,9 +460,9 @@ let CardService = CardService_1 = class CardService {
|
|
|
437
460
|
_getUserId(subscriptionId, mid, testEnv, regional, userId) {
|
|
438
461
|
return rxjs_1.of(1).pipe(operators_1.switchMap(() => rxjs_1.iif(() => UtilsService_1.UtilsService.sIsEmpty(userId), this._gateway.getUserId(subscriptionId, mid, testEnv, regional), rxjs_1.of(undefined))), operators_1.catchError(() => rxjs_1.of(undefined)));
|
|
439
462
|
}
|
|
440
|
-
_requestSubscriptionTokenGateway(body, mid, testEnv, regional, callback) {
|
|
463
|
+
_requestSubscriptionTokenGateway(body, mid, testEnv, regional, callback, authorization) {
|
|
441
464
|
this._gateway
|
|
442
|
-
.requestSubscriptionToken(body, mid, testEnv, regional)
|
|
465
|
+
.requestSubscriptionToken(body, mid, testEnv, regional, authorization)
|
|
443
466
|
.subscribe({
|
|
444
467
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
445
468
|
next: (response) => {
|
|
@@ -464,7 +487,8 @@ let CardService = CardService_1 = class CardService {
|
|
|
464
487
|
CardService = CardService_1 = __decorate([
|
|
465
488
|
inversify_1.injectable(),
|
|
466
489
|
__param(0, inversify_1.inject(Identifiers_1.IDENTIFIERS.KushkiGateway)),
|
|
467
|
-
__param(1, inversify_1.inject(Identifiers_1.IDENTIFIERS.
|
|
468
|
-
|
|
490
|
+
__param(1, inversify_1.inject(Identifiers_1.IDENTIFIERS.AuthService)),
|
|
491
|
+
__param(2, inversify_1.inject(Identifiers_1.IDENTIFIERS.AntiFraud)),
|
|
492
|
+
__metadata("design:paramtypes", [Object, Object, Object])
|
|
469
493
|
], CardService);
|
|
470
494
|
exports.CardService = CardService;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* tslint:disable:all */
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
import { IAuthService } from "./../../lib/repository/IAuthService";
|
|
4
|
+
import { IKPayService } from "./../../lib/repository/IKPayService";
|
|
5
|
+
import { IKushkiGateway } from "./../../lib/repository/IKushkiGateway";
|
|
6
|
+
import { Observable } from "rxjs";
|
|
7
|
+
import { DeletePaymentMethodRequest } from "./../../lib/types/delete_payment_method_request";
|
|
8
|
+
import { PaymentDataResponse } from "./../../lib/types/payment_data_response";
|
|
9
|
+
import { SavedPaymentMethodRequest } from "./../../lib/types/saved_payment_data_request";
|
|
10
|
+
/**
|
|
11
|
+
* Implementation
|
|
12
|
+
*/
|
|
13
|
+
export declare class KPayService implements IKPayService {
|
|
14
|
+
private readonly _gateway;
|
|
15
|
+
private readonly _authService;
|
|
16
|
+
constructor(gateway: IKushkiGateway, authService: IAuthService);
|
|
17
|
+
deletePaymentMethod(body: DeletePaymentMethodRequest, mid: string, isTest: boolean, regional: boolean): Observable<boolean>;
|
|
18
|
+
requestSavedPaymentMethods(body: SavedPaymentMethodRequest, mid: string, isTest: boolean, regional: boolean): Observable<PaymentDataResponse[]>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KPayService = void 0;
|
|
16
|
+
/**
|
|
17
|
+
* Kushki Service file
|
|
18
|
+
*/
|
|
19
|
+
const Identifiers_1 = require("./../../lib/constant/Identifiers");
|
|
20
|
+
const inversify_1 = require("inversify");
|
|
21
|
+
require("reflect-metadata");
|
|
22
|
+
const rxjs_1 = require("rxjs");
|
|
23
|
+
const operators_1 = require("rxjs/operators");
|
|
24
|
+
/**
|
|
25
|
+
* Implementation
|
|
26
|
+
*/
|
|
27
|
+
let KPayService = class KPayService {
|
|
28
|
+
constructor(gateway, authService) {
|
|
29
|
+
this._gateway = gateway;
|
|
30
|
+
this._authService = authService;
|
|
31
|
+
}
|
|
32
|
+
deletePaymentMethod(body, mid, isTest, regional) {
|
|
33
|
+
return rxjs_1.of(1).pipe(operators_1.concatMap(() => this._authService.getAuthorizationToken()), operators_1.concatMap(jwt => this._gateway.deletePaymentMethod(body, isTest, regional, mid, jwt)));
|
|
34
|
+
}
|
|
35
|
+
requestSavedPaymentMethods(body, mid, isTest, regional) {
|
|
36
|
+
return this._gateway.requestSavedPaymentMethods(body, isTest, regional, mid);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
KPayService = __decorate([
|
|
40
|
+
inversify_1.injectable(),
|
|
41
|
+
__param(0, inversify_1.inject(Identifiers_1.IDENTIFIERS.KushkiGateway)),
|
|
42
|
+
__param(1, inversify_1.inject(Identifiers_1.IDENTIFIERS.AuthService)),
|
|
43
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
44
|
+
], KPayService);
|
|
45
|
+
exports.KPayService = KPayService;
|
|
@@ -6,7 +6,8 @@ export interface ApplePaymentEvent {
|
|
|
6
6
|
billingContact?: ApplePayPaymentContact;
|
|
7
7
|
shippingContact?: ApplePayPaymentContact;
|
|
8
8
|
token: {
|
|
9
|
-
paymentData:
|
|
9
|
+
paymentData: ApplePayPaymentData;
|
|
10
|
+
paymentMethod: ApplePayPaymentMethod;
|
|
10
11
|
};
|
|
11
12
|
};
|
|
12
13
|
validationURL: string;
|
|
@@ -28,7 +29,7 @@ export interface ApplePayPaymentContact {
|
|
|
28
29
|
countryCode: string;
|
|
29
30
|
addressLines: string[];
|
|
30
31
|
}
|
|
31
|
-
export interface
|
|
32
|
+
export interface ApplePayPaymentData {
|
|
32
33
|
data: string;
|
|
33
34
|
header: {
|
|
34
35
|
ephemeralPublicKey: string;
|
|
@@ -39,6 +40,11 @@ export interface ApplePayGetTokenRequest {
|
|
|
39
40
|
signature: string;
|
|
40
41
|
version: string;
|
|
41
42
|
}
|
|
43
|
+
export interface ApplePayPaymentMethod {
|
|
44
|
+
network: string;
|
|
45
|
+
displayName: string;
|
|
46
|
+
type: string;
|
|
47
|
+
}
|
|
42
48
|
export interface AppleTokenResponse {
|
|
43
49
|
token: string;
|
|
44
50
|
billingContact?: ApplePayPaymentContact;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* tslint:disable:all */
|
|
2
|
+
/* tslint:disable:all */
|
|
3
|
+
|
|
4
|
+
export interface ApplePayGetTokenRequest {
|
|
5
|
+
data: string;
|
|
6
|
+
header: {
|
|
7
|
+
ephemeralPublicKey: string;
|
|
8
|
+
publicKeyHash: string;
|
|
9
|
+
transactionId: string;
|
|
10
|
+
[k: string]: any;
|
|
11
|
+
};
|
|
12
|
+
signature: string;
|
|
13
|
+
version: string;
|
|
14
|
+
paymentMethod: ApplePayPaymentMethod;
|
|
15
|
+
}
|
|
16
|
+
export interface ApplePayPaymentMethod {
|
|
17
|
+
network: string;
|
|
18
|
+
displayName: string;
|
|
19
|
+
type: string;
|
|
20
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* tslint:disable:all */
|
|
2
|
+
/* tslint:disable:all */
|
|
3
|
+
|
|
4
|
+
export type PaymentDataResponse = CardPaymentDataResponse | TransferPaymentDataResponse | CashPaymentDataResponse;
|
|
5
|
+
|
|
6
|
+
export interface CardPaymentDataResponse {
|
|
7
|
+
id: string;
|
|
8
|
+
email: string;
|
|
9
|
+
kind: "card";
|
|
10
|
+
brand: string;
|
|
11
|
+
cardHolderName: string;
|
|
12
|
+
expDate: string;
|
|
13
|
+
lastFourDigits: string;
|
|
14
|
+
maskedCardNumber: string;
|
|
15
|
+
}
|
|
16
|
+
export interface TransferPaymentDataResponse {
|
|
17
|
+
id: string;
|
|
18
|
+
bankId: string;
|
|
19
|
+
brand: string;
|
|
20
|
+
documentNumber: string;
|
|
21
|
+
documentType: string;
|
|
22
|
+
email: string;
|
|
23
|
+
kind: "transfer";
|
|
24
|
+
name: string;
|
|
25
|
+
userType: string;
|
|
26
|
+
}
|
|
27
|
+
export interface CashPaymentDataResponse {
|
|
28
|
+
id: string;
|
|
29
|
+
brand: string;
|
|
30
|
+
documentNumber: string;
|
|
31
|
+
documentType: string;
|
|
32
|
+
email: string;
|
|
33
|
+
kind: "cash";
|
|
34
|
+
name: string;
|
|
35
|
+
firstName?: string;
|
|
36
|
+
lastName?: string;
|
|
37
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable:all */
|
|
2
|
+
/* tslint:disable:all */
|
|
3
|
+
|
|
4
|
+
export interface SubscriptionTokenKPayRequest {
|
|
5
|
+
walletId: string;
|
|
6
|
+
currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "CRC" | "GTQ" | "HNL" | "NIO" | "PAB" | "BRL";
|
|
7
|
+
userId?: string;
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
card?: {
|
|
10
|
+
cvc: string;
|
|
11
|
+
};
|
|
12
|
+
[k: string]: any;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/* tslint:disable:all */
|
|
2
|
+
/* tslint:disable:all */
|
|
3
|
+
|
|
4
|
+
export interface TokenKPayRequest {
|
|
5
|
+
walletId: string;
|
|
6
|
+
currency?: "USD" | "COP" | "CLP" | "UF" | "PEN" | "MXN" | "BRL" | "CRC" | "GTQ" | "HNL" | "NIO" | "PAB";
|
|
7
|
+
isDeferred?: boolean;
|
|
8
|
+
amount: number | string;
|
|
9
|
+
months?: number;
|
|
10
|
+
cvv?: string;
|
|
11
|
+
[k: string]: any;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kushki/js",
|
|
3
|
-
"version": "1.40.2-alpha",
|
|
3
|
+
"version": "1.40.2-alpha-19735.0",
|
|
4
4
|
"description": "kushki-js",
|
|
5
5
|
"main": "lib/lib.js",
|
|
6
6
|
"types": "lib/lib.d.ts",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"build:cdn": "webpack --optimize-minimize",
|
|
37
37
|
"build:npm": "npm run tsc:interface && gulp",
|
|
38
38
|
"postinstall": "echo postinstall",
|
|
39
|
-
"depcheck": "depcheck . --ignores=\"serverless-*,@types/*,@kushki/*,rollbar,aws-lambda,prettier,chai,husky,express,lint-staged,ajv,ts-loader,tslint-config-prettier,infrastructure,constant,middleware,core,gateway,service,error,moment-timezone,moment,faker, numeral,dot-object\""
|
|
39
|
+
"depcheck": "depcheck . --ignores=\"serverless-*,@types/*,@kushki/*,rollbar,aws-lambda,prettier,chai,husky,express,lint-staged,ajv,ts-loader,tslint-config-prettier,infrastructure,constant,middleware,core,gateway,service,error,moment-timezone,moment,faker, numeral,dot-object,@aws-amplify/auth \""
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@kushki/cli": "1.4.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"snyk": "1.303.1",
|
|
81
81
|
"source-map-loader": "0.2.4",
|
|
82
82
|
"source-map-support": "0.5.12",
|
|
83
|
-
"string-replace-loader": "3.1.0",
|
|
83
|
+
"string-replace-loader": "^3.1.0",
|
|
84
84
|
"terser-webpack-plugin": "^4.2.3",
|
|
85
85
|
"thread-loader": "2.1.3",
|
|
86
86
|
"ts-loader": "5.4.3",
|
|
@@ -97,8 +97,10 @@
|
|
|
97
97
|
"webpack-dev-server": "3.3.1"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
+
"@aws-amplify/auth": "4.6.1",
|
|
100
101
|
"@kushki/cardinal-sandbox-js": "1.0.6",
|
|
101
102
|
"acorn": "6.4.1",
|
|
103
|
+
"aws-amplify": "4.3.30",
|
|
102
104
|
"axios": "0.21.3",
|
|
103
105
|
"buffer": "^6.0.3",
|
|
104
106
|
"ci": "^2.1.1",
|