@kushki/js 1.40.1-alpha.14317.3 → 1.40.2-alpha
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 +1 -0
- package/lib/Kushki.d.ts +119 -23
- package/lib/Kushki.js +119 -20
- package/lib/KushkiInfo.js +3 -2
- package/lib/constant/Identifiers.d.ts +1 -3
- package/lib/constant/Identifiers.js +1 -3
- package/lib/gateway/KushkiGateway.d.ts +9 -14
- package/lib/gateway/KushkiGateway.js +19 -39
- package/lib/gateway/SiftScience.d.ts +1 -0
- package/lib/gateway/SiftScience.js +5 -0
- package/lib/infrastructure/CardBrandsEnum.d.ts +2 -1
- package/lib/infrastructure/CardBrandsEnum.js +1 -0
- package/lib/infrastructure/CardinalValidated.d.ts +10 -0
- package/lib/infrastructure/CardinalValidated.js +8 -0
- package/lib/infrastructure/Container.js +3 -7
- package/lib/infrastructure/EnvironmentEnum.d.ts +1 -1
- package/lib/infrastructure/EnvironmentEnum.js +1 -1
- package/lib/infrastructure/ErrorEnum.d.ts +4 -1
- package/lib/infrastructure/ErrorEnum.js +19 -1
- package/lib/infrastructure/PathEnum.d.ts +4 -6
- package/lib/infrastructure/PathEnum.js +3 -5
- package/lib/repository/IApplePayService.d.ts +40 -0
- package/lib/repository/ICardService.d.ts +3 -5
- package/lib/repository/IKushkiGateway.d.ts +23 -36
- package/lib/service/ApplePayService.d.ts +36 -0
- package/lib/service/ApplePayService.js +189 -0
- package/lib/service/CardService.d.ts +8 -9
- package/lib/service/CardService.js +103 -112
- package/lib/types/apple_pay_get_token_events.d.ts +46 -0
- package/lib/types/apple_pay_get_token_options.d.ts +12 -0
- package/lib/types/apple_pay_options.d.ts +25 -0
- package/lib/types/apple_pay_start_session_request.d.ts +8 -0
- package/lib/types/kushki_subscription_tokens_request.d.ts +0 -10
- package/lib/types/subscription_token_request.d.ts +0 -10
- package/package.json +5 -6
- package/lib/infrastructure/KPayUserPoolEnum.d.ts +0 -5
- package/lib/infrastructure/KPayUserPoolEnum.js +0 -8
- package/lib/infrastructure/KpayPaymentKind.d.ts +0 -6
- package/lib/infrastructure/KpayPaymentKind.js +0 -9
- package/lib/repository/IAuthService.d.ts +0 -20
- package/lib/repository/IKPayService.d.ts +0 -26
- package/lib/repository/IKPayService.js +0 -2
- package/lib/repository/IMobileProcessorService.d.ts +0 -16
- package/lib/repository/IMobileProcessorService.js +0 -2
- package/lib/service/AuthService.d.ts +0 -31
- package/lib/service/AuthService.js +0 -161
- package/lib/service/KPayService.d.ts +0 -19
- package/lib/service/KPayService.js +0 -45
- package/lib/service/MobileProcessorService.d.ts +0 -35
- package/lib/service/MobileProcessorService.js +0 -126
- package/lib/types/delete_payment_method_request.d.ts +0 -6
- package/lib/types/delete_payment_method_response.d.ts +0 -7
- package/lib/types/init_auth_request.d.ts +0 -6
- package/lib/types/init_auth_response.d.ts +0 -6
- package/lib/types/mobile_processor_charge_request.d.ts +0 -13
- package/lib/types/mobile_processor_charge_response.d.ts +0 -7
- package/lib/types/mobile_processor_token.d.ts +0 -66
- package/lib/types/mobile_processor_token_request.d.ts +0 -11
- package/lib/types/mobile_processor_token_response.d.ts +0 -15
- package/lib/types/payment_data_response.d.ts +0 -37
- package/lib/types/saved_payment_data_request.d.ts +0 -10
- package/lib/types/subscription_token_kpay_request.d.ts +0 -13
- package/lib/types/token_kpay_request.d.ts +0 -12
- package/lib/types/validate_session_response.d.ts +0 -6
- package/lib/types/verify_auth_request.d.ts +0 -7
- package/lib/types/verify_auth_response.d.ts +0 -7
- /package/lib/repository/{IAuthService.js → IApplePayService.js} +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
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 ApplePayService_1;
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.ApplePayService = void 0;
|
|
26
|
+
/**
|
|
27
|
+
* Apple Pay Service file
|
|
28
|
+
*/
|
|
29
|
+
const Identifiers_1 = require("./../../lib/constant/Identifiers");
|
|
30
|
+
const KushkiError_1 = require("./../../lib/generic/KushkiError");
|
|
31
|
+
const CardBrandsEnum_1 = require("./../../lib/infrastructure/CardBrandsEnum");
|
|
32
|
+
const ErrorEnum_1 = require("./../../lib/infrastructure/ErrorEnum");
|
|
33
|
+
const inversify_1 = require("inversify");
|
|
34
|
+
require("reflect-metadata");
|
|
35
|
+
const Kushki_1 = require("./../../lib/Kushki");
|
|
36
|
+
/**
|
|
37
|
+
* Implementation
|
|
38
|
+
*/
|
|
39
|
+
let ApplePayService = ApplePayService_1 = class ApplePayService {
|
|
40
|
+
constructor(gateway) {
|
|
41
|
+
this._appleSdkCdn = "https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js";
|
|
42
|
+
this._appleSdkId = "apple-pay-sdk";
|
|
43
|
+
this._appleButtonElement = "apple-pay-button";
|
|
44
|
+
this._appleButtonContainer = "kushki-apple-pay-button";
|
|
45
|
+
this._requiredMerchantCapabilities = "supports3DS";
|
|
46
|
+
this._maxCompatibleVersion = 16;
|
|
47
|
+
this._gateway = gateway;
|
|
48
|
+
}
|
|
49
|
+
initApplePayButton(options, mid, isTest, regional, onInit, onClick, onError) {
|
|
50
|
+
this._validateAppleDomain(mid, isTest, regional).then((isValid) => {
|
|
51
|
+
if (!isValid) {
|
|
52
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E020), onError);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this._loadAppleSdk(() => this._buildAppleButton(options, onInit, onClick, onError), () => Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E019), onError));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
requestApplePayToken(options, mid, isTest, regional, callback, onCancel) {
|
|
59
|
+
if (this._isNotPaymentAvailable()) {
|
|
60
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E020), callback);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const session_params = Object.assign({ countryCode: options.countryCode, currencyCode: options.currencyCode, merchantCapabilities: [this._requiredMerchantCapabilities], supportedNetworks: [CardBrandsEnum_1.CardBrandsEnum.VISA, CardBrandsEnum_1.CardBrandsEnum.MASTER_CARD], total: {
|
|
64
|
+
amount: options.amount.toString(),
|
|
65
|
+
label: options.displayName,
|
|
66
|
+
} }, options.optionalApplePayFields);
|
|
67
|
+
const session = new window.ApplePaySession(this._getSupportedApplePayVersion(), session_params);
|
|
68
|
+
session.onvalidatemerchant = (event) => this._onValidateMerchant(event, mid, session, options, isTest, regional, callback);
|
|
69
|
+
session.onpaymentauthorized = (event) => this._onPaymentAuthorized(event, mid, session, isTest, regional, callback);
|
|
70
|
+
session.oncancel = () => {
|
|
71
|
+
onCancel();
|
|
72
|
+
};
|
|
73
|
+
session.begin();
|
|
74
|
+
}
|
|
75
|
+
_validateAppleDomain(mid, isTest, regional) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
try {
|
|
78
|
+
const { isValid: is_valid } = yield this._gateway
|
|
79
|
+
.validateAppleDomain(ApplePayService_1.getClientDomain(), mid, isTest, regional)
|
|
80
|
+
.toPromise();
|
|
81
|
+
return !!is_valid;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
_isNotPaymentAvailable() {
|
|
89
|
+
return !window.ApplePaySession || !window.ApplePaySession.canMakePayments();
|
|
90
|
+
}
|
|
91
|
+
_getSupportedApplePayVersion() {
|
|
92
|
+
for (let v = this._maxCompatibleVersion; v >= 1; v--)
|
|
93
|
+
if (window.ApplePaySession.supportsVersion(v))
|
|
94
|
+
return v;
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
97
|
+
_loadAppleSdk(onLoad, onError) {
|
|
98
|
+
const last_script = document.getElementById(this._appleSdkId);
|
|
99
|
+
if (last_script) {
|
|
100
|
+
onLoad();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const script = document.createElement("script");
|
|
104
|
+
script.id = this._appleSdkId;
|
|
105
|
+
script.src = this._appleSdkCdn;
|
|
106
|
+
script.crossOrigin = "anonymous";
|
|
107
|
+
document.head.appendChild(script);
|
|
108
|
+
script.onload = onLoad;
|
|
109
|
+
script.onerror = onError;
|
|
110
|
+
}
|
|
111
|
+
_buildAppleButton(options, onInit, onClick, onError) {
|
|
112
|
+
try {
|
|
113
|
+
if (this._isNotPaymentAvailable()) {
|
|
114
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E020), onError);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const container = document.getElementById(this._appleButtonContainer);
|
|
118
|
+
if (!container) {
|
|
119
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E019), onError);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const button = document.createElement(this._appleButtonElement);
|
|
123
|
+
button.setAttribute("buttonstyle", options.style);
|
|
124
|
+
button.setAttribute("type", options.type);
|
|
125
|
+
button.setAttribute("locale", options.locale);
|
|
126
|
+
button.addEventListener("click", onClick);
|
|
127
|
+
container.textContent = "";
|
|
128
|
+
container.appendChild(button);
|
|
129
|
+
onInit();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
onError(error);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
_onValidateMerchant(event, mid, session, options, isTest, regional, onError) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
try {
|
|
138
|
+
const merchant_session = yield this._gateway
|
|
139
|
+
.startApplePaySession({
|
|
140
|
+
clientDomain: ApplePayService_1.getClientDomain(),
|
|
141
|
+
displayName: options.displayName,
|
|
142
|
+
validationURL: event.validationURL,
|
|
143
|
+
}, mid, isTest, regional)
|
|
144
|
+
.toPromise();
|
|
145
|
+
session.completeMerchantValidation(merchant_session);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E007), onError);
|
|
149
|
+
session.abort();
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
_onPaymentAuthorized(event, mid, session, isTest, regional, callback) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
try {
|
|
156
|
+
const apple_token = event.payment.token.paymentData;
|
|
157
|
+
const kushki_token = yield this._gateway
|
|
158
|
+
.getApplePayToken(apple_token, mid, isTest, regional)
|
|
159
|
+
.toPromise();
|
|
160
|
+
const billing_contact = event.payment.billingContact;
|
|
161
|
+
const shipping_contact = event.payment.shippingContact;
|
|
162
|
+
session.completePayment(window.ApplePaySession.STATUS_SUCCESS);
|
|
163
|
+
callback(Object.assign(Object.assign(Object.assign({}, (billing_contact ? { billingContact: billing_contact } : {})), (shipping_contact ? { shippingContact: shipping_contact } : {})), kushki_token));
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E006), callback);
|
|
167
|
+
session.abort();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
static getClientDomain() {
|
|
172
|
+
let domain = window.location.href;
|
|
173
|
+
const is_in_iframe = window.self !== window.top;
|
|
174
|
+
const parent_ref = window.location.ancestorOrigins;
|
|
175
|
+
const have_parent = parent_ref && parent_ref.length;
|
|
176
|
+
if (is_in_iframe)
|
|
177
|
+
if (have_parent)
|
|
178
|
+
domain = parent_ref[parent_ref.length - 1];
|
|
179
|
+
else
|
|
180
|
+
domain = document.referrer;
|
|
181
|
+
return new URL(domain).hostname;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
ApplePayService = ApplePayService_1 = __decorate([
|
|
185
|
+
inversify_1.injectable(),
|
|
186
|
+
__param(0, inversify_1.inject(Identifiers_1.IDENTIFIERS.KushkiGateway)),
|
|
187
|
+
__metadata("design:paramtypes", [Object])
|
|
188
|
+
], ApplePayService);
|
|
189
|
+
exports.ApplePayService = ApplePayService;
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import "reflect-metadata";
|
|
6
6
|
import { IAntiFraud } from "./../../lib/repository/IAntiFraud";
|
|
7
|
-
import { IAuthService } from "./../../lib/repository/IAuthService";
|
|
8
7
|
import { ICardService } from "./../../lib/repository/ICardService";
|
|
9
8
|
import { IKushkiGateway } from "./../../lib/repository/IKushkiGateway";
|
|
10
9
|
import { Observable } from "rxjs";
|
|
@@ -15,10 +14,8 @@ import { IDeferredResponse } from "./../../lib/types/remote/deferred_response";
|
|
|
15
14
|
import { TokenResponse } from "./../../lib/types/remote/token_response";
|
|
16
15
|
import { SecureInitRequest } from "./../../lib/types/secure_init_request";
|
|
17
16
|
import { SecureInitResponse } from "./../../lib/types/secure_init_response";
|
|
18
|
-
import { SubscriptionTokenKPayRequest } from "./../../lib/types/subscription_token_kpay_request";
|
|
19
17
|
import { SubscriptionTokenRequest } from "./../../lib/types/subscription_token_request";
|
|
20
18
|
import { SubscriptionIdRequest } from "./../../lib/types/subscriptionId_request";
|
|
21
|
-
import { TokenKPayRequest } from "./../../lib/types/token_kpay_request";
|
|
22
19
|
import { TokenRequest } from "./../../lib/types/token_request";
|
|
23
20
|
import { Validate3DSRequest } from "./../../lib/types/validate_3ds_request";
|
|
24
21
|
import { Validate3DsResponse } from "./../../lib/types/validate_3ds_response";
|
|
@@ -35,27 +32,28 @@ export declare class CardService implements ICardService {
|
|
|
35
32
|
private readonly _gateway;
|
|
36
33
|
private readonly _receipt;
|
|
37
34
|
private readonly _antiFraud;
|
|
38
|
-
private readonly _authService;
|
|
39
35
|
private readonly _3Dsecure;
|
|
40
36
|
private readonly _cardNumber;
|
|
41
37
|
private _sandboxEnable;
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
private readonly _paymentValidatedEvent;
|
|
39
|
+
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
42
|
requestDeviceToken(request: SubscriptionIdRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
45
|
-
requestSubscriptionToken(subscriptionTokenRequest: SubscriptionTokenRequest
|
|
43
|
+
requestSubscriptionToken(subscriptionTokenRequest: SubscriptionTokenRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: TokenResponse | ErrorResponse) => void): void;
|
|
46
44
|
requestDeferred(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<IDeferredResponse[]>;
|
|
47
45
|
requestBinInfo(binBody: BinBody, mid: string, isTest: boolean, regional: boolean): Observable<BinInfoResponse>;
|
|
48
46
|
validate3DS(body: Validate3DSRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: Validate3DsResponse | ErrorResponse) => void): void;
|
|
49
47
|
requestSecureInit(request: SecureInitRequest, mid: string, isTest: boolean, regional: boolean, callback: (value: SecureInitResponse | ErrorResponse) => void): void;
|
|
50
48
|
private _getCreateSubscriptionDataToTransform;
|
|
51
49
|
private _request3DSToken;
|
|
52
|
-
private _setupCompleteCardinal;
|
|
53
50
|
private _requestTokenGateway;
|
|
54
51
|
private _getMerchantSettings;
|
|
55
52
|
private _validateParameters;
|
|
56
53
|
private _getDeviceTokenSiftScienceObject;
|
|
57
54
|
private _createSubscriptionSiftScienceSession;
|
|
58
55
|
private _checkCardLength;
|
|
56
|
+
private _checkSecureInitCardLength;
|
|
59
57
|
private _getScienceSession;
|
|
60
58
|
private _checkCurrency;
|
|
61
59
|
private _getRequestSiftObject;
|
|
@@ -65,11 +63,11 @@ export declare class CardService implements ICardService {
|
|
|
65
63
|
private _isSandboxEnabled;
|
|
66
64
|
private _getCybersourceJwtSubscription;
|
|
67
65
|
private _is3DSSecureEnabled;
|
|
66
|
+
private _loadCardinalScript;
|
|
68
67
|
private _initCybersource;
|
|
69
68
|
private _initializeCardinal;
|
|
70
69
|
private _initCybersourceSubscription;
|
|
71
70
|
private _completeCardinal;
|
|
72
|
-
private static _initCardinal;
|
|
73
71
|
private static _ccaCardinal;
|
|
74
72
|
private static _is3dsValid;
|
|
75
73
|
private _setSandboxEnable;
|
|
@@ -78,4 +76,5 @@ export declare class CardService implements ICardService {
|
|
|
78
76
|
private _getUserId;
|
|
79
77
|
private _requestSubscriptionTokenGateway;
|
|
80
78
|
private _requestDeviceToken;
|
|
79
|
+
private _isInvalidSpecificationVersion;
|
|
81
80
|
}
|
|
@@ -28,9 +28,11 @@ var CardService_1;
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.CardService = void 0;
|
|
30
30
|
const cardinal_sandbox_js_1 = require("@kushki/cardinal-sandbox-js");
|
|
31
|
+
const buffer_1 = require("buffer");
|
|
31
32
|
const Identifiers_1 = require("./../../lib/constant/Identifiers");
|
|
32
33
|
const dot = require("dot-object");
|
|
33
34
|
const KushkiError_1 = require("./../../lib/generic/KushkiError");
|
|
35
|
+
const CardinalValidated_1 = require("./../../lib/infrastructure/CardinalValidated");
|
|
34
36
|
const ErrorEnum_1 = require("./../../lib/infrastructure/ErrorEnum");
|
|
35
37
|
const ThreeDSEnum_1 = require("./../../lib/infrastructure/ThreeDSEnum");
|
|
36
38
|
const inversify_1 = require("inversify");
|
|
@@ -40,13 +42,14 @@ const operators_1 = require("rxjs/operators");
|
|
|
40
42
|
const UtilsService_1 = require("./../../lib/service/UtilsService");
|
|
41
43
|
const Kushki_1 = require("./../../lib/Kushki");
|
|
42
44
|
let CardService = CardService_1 = class CardService {
|
|
43
|
-
constructor(gateway,
|
|
45
|
+
constructor(gateway, antiFraud) {
|
|
44
46
|
this._3Dsecure = "active_3dsecure";
|
|
45
47
|
this._cardNumber = "card.number";
|
|
46
48
|
this._sandboxEnable = false;
|
|
49
|
+
this._paymentValidatedEvent = "payments.validated";
|
|
50
|
+
this._paymentSetupCompleteEvent = "payments.setupComplete";
|
|
47
51
|
this._gateway = gateway;
|
|
48
52
|
this._antiFraud = antiFraud;
|
|
49
|
-
this._authService = authService;
|
|
50
53
|
this._receipt = {
|
|
51
54
|
amount: "totalAmount",
|
|
52
55
|
"card.cvc": "card.cvv",
|
|
@@ -80,37 +83,28 @@ let CardService = CardService_1 = class CardService {
|
|
|
80
83
|
this._setSandboxEnable(!!merchant.sandboxEnable);
|
|
81
84
|
return rxjs_1.forkJoin([
|
|
82
85
|
this._getScienceSession(request, mid, isTest, merchant),
|
|
83
|
-
this._getCybersourceJwt(merchant, mid, isTest, regional,
|
|
84
|
-
? request.card.number
|
|
85
|
-
: undefined),
|
|
86
|
+
this._getCybersourceJwt(merchant, mid, isTest, regional, request.card.number),
|
|
86
87
|
rxjs_1.of(merchant),
|
|
87
88
|
]);
|
|
88
89
|
}), operators_1.mergeMap(([sift_object, jwt, merchant]) => {
|
|
89
90
|
request.isDeferred =
|
|
90
91
|
request.isDeferred === undefined ? false : request.isDeferred;
|
|
91
|
-
if (Boolean(request.cvv))
|
|
92
|
-
request.card = { cvc: request.cvv };
|
|
93
92
|
this._checkRequestBody(request);
|
|
94
93
|
const data_to_transform = Object.assign(Object.assign({}, request), sift_object);
|
|
95
94
|
if (jwt !== undefined)
|
|
96
95
|
data_to_transform.jwt = jwt;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
request.walletId
|
|
100
|
-
? this._authService.getAuthorizationToken()
|
|
101
|
-
: rxjs_1.of(undefined),
|
|
102
|
-
rxjs_1.of(merchant),
|
|
103
|
-
]);
|
|
96
|
+
const final_request = dot.transform(this._receipt, Object.assign(Object.assign({}, data_to_transform), { merchantName: merchant.merchant_name }));
|
|
97
|
+
return rxjs_1.of({ final_request, merchant });
|
|
104
98
|
}))
|
|
105
99
|
.subscribe({
|
|
106
100
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
107
|
-
next: (
|
|
101
|
+
next: ({ final_request, merchant, }) => {
|
|
108
102
|
if (final_request.jwt && !merchant.sandboxEnable)
|
|
109
|
-
this._request3DSToken(
|
|
110
|
-
this._requestTokenGateway(final_request, mid, isTest, regional, callback
|
|
103
|
+
this._request3DSToken(() => {
|
|
104
|
+
this._requestTokenGateway(final_request, mid, isTest, regional, callback);
|
|
111
105
|
});
|
|
112
106
|
else
|
|
113
|
-
this._requestTokenGateway(final_request, mid, isTest, regional, callback
|
|
107
|
+
this._requestTokenGateway(final_request, mid, isTest, regional, callback);
|
|
114
108
|
},
|
|
115
109
|
});
|
|
116
110
|
}
|
|
@@ -133,7 +127,7 @@ let CardService = CardService_1 = class CardService {
|
|
|
133
127
|
delete sift_science_obj.sessionId;
|
|
134
128
|
if (jwt && !this._sandboxEnable) {
|
|
135
129
|
sift_science_obj = Object.assign(Object.assign({}, sift_science_obj), { jwt, amount: request.amount, cardHolderName: request.cardHolderName, currency: request.currency });
|
|
136
|
-
this._request3DSToken(
|
|
130
|
+
this._request3DSToken(() => {
|
|
137
131
|
sift_science_obj = Object.assign(Object.assign({}, sift_science_obj), { jwt });
|
|
138
132
|
this._requestDeviceToken(Object.assign({ subscriptionId: request.subscriptionId }, sift_science_obj), mid, isTest, regional, callback);
|
|
139
133
|
});
|
|
@@ -160,23 +154,18 @@ let CardService = CardService_1 = class CardService {
|
|
|
160
154
|
const data_to_transform = this._getCreateSubscriptionDataToTransform(sift_object, subscriptionTokenRequest);
|
|
161
155
|
if (jwt !== undefined)
|
|
162
156
|
data_to_transform.jwt = jwt;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
subscriptionTokenRequest.walletId
|
|
166
|
-
? this._authService.getAuthorizationToken()
|
|
167
|
-
: rxjs_1.of(undefined),
|
|
168
|
-
rxjs_1.of(merchant),
|
|
169
|
-
]);
|
|
157
|
+
const body = dot.transform(this._receipt, Object.assign(Object.assign({}, data_to_transform), { merchantName: merchant.merchant_name }));
|
|
158
|
+
return rxjs_1.of({ body, merchant });
|
|
170
159
|
}))
|
|
171
160
|
.subscribe({
|
|
172
161
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
173
|
-
next: (
|
|
162
|
+
next: ({ body, merchant, }) => {
|
|
174
163
|
if (body.jwt && !merchant.sandboxEnable)
|
|
175
|
-
this._request3DSToken(
|
|
176
|
-
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback
|
|
164
|
+
this._request3DSToken(() => {
|
|
165
|
+
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback);
|
|
177
166
|
});
|
|
178
167
|
else
|
|
179
|
-
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback
|
|
168
|
+
this._requestSubscriptionTokenGateway(body, mid, isTest, regional, callback);
|
|
180
169
|
},
|
|
181
170
|
});
|
|
182
171
|
}
|
|
@@ -201,35 +190,24 @@ let CardService = CardService_1 = class CardService {
|
|
|
201
190
|
UtilsService_1.UtilsService.sGet(body, "security.paReq", ThreeDSEnum_1.ThreeDSEnum.SANDBOX) ===
|
|
202
191
|
ThreeDSEnum_1.ThreeDSEnum.SANDBOX)
|
|
203
192
|
return this._ccaSandbox(body, mid, isTest, regional, callback);
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
});
|
|
209
|
-
Promise.resolve().then(() => require("./../../lib/libs/cardinal/staging")).then(() => {
|
|
210
|
-
this._completeCardinal(body.secureId, mid, isTest, regional, callback);
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
else {
|
|
214
|
-
// tslint:disable-next-line:no-duplicate-string
|
|
215
|
-
Promise.resolve().then(() => require("./../../lib/libs/cardinal/prod")).then(() => {
|
|
216
|
-
CardService_1._ccaCardinal(body);
|
|
217
|
-
});
|
|
218
|
-
Promise.resolve().then(() => require("./../../lib/libs/cardinal/prod")).then(() => {
|
|
219
|
-
this._completeCardinal(body.secureId, mid, isTest, regional, callback);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
193
|
+
if (this._isInvalidSpecificationVersion(body, this._sandboxEnable))
|
|
194
|
+
return Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E012), callback);
|
|
195
|
+
CardService_1._ccaCardinal(body);
|
|
196
|
+
this._completeCardinal(body.secureId, mid, isTest, regional, callback);
|
|
222
197
|
}
|
|
223
198
|
requestSecureInit(request, mid, isTest, regional, callback) {
|
|
224
199
|
rxjs_1.of(1)
|
|
225
|
-
.pipe(operators_1.map(() => this.
|
|
226
|
-
jwt: jwt,
|
|
227
|
-
})))
|
|
200
|
+
.pipe(operators_1.map(() => this._checkSecureInitCardLength(request)), operators_1.switchMap(() => this._getMerchantSettings(mid, isTest, regional)), operators_1.switchMap((merchantSettings) => rxjs_1.iif(() => this._is3DSSecureEnabled(merchantSettings), rxjs_1.of(merchantSettings), rxjs_1.throwError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E013)))), operators_1.switchMap((merchant) => rxjs_1.forkJoin(this._getCybersourceJwt(merchant, mid, isTest, regional, request.card.number), rxjs_1.of(merchant))))
|
|
228
201
|
.subscribe({
|
|
229
202
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
230
|
-
next: (
|
|
231
|
-
|
|
232
|
-
|
|
203
|
+
next: ([jwt_response, merchant_settings]) => {
|
|
204
|
+
const jwt = { jwt: jwt_response };
|
|
205
|
+
if (this._isSandboxEnabled(merchant_settings)) {
|
|
206
|
+
callback(jwt);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this._request3DSToken(() => {
|
|
210
|
+
callback(jwt);
|
|
233
211
|
});
|
|
234
212
|
},
|
|
235
213
|
});
|
|
@@ -239,21 +217,11 @@ let CardService = CardService_1 = class CardService {
|
|
|
239
217
|
return Object.assign({}, subscriptionTokenRequest);
|
|
240
218
|
return Object.assign(Object.assign({}, subscriptionTokenRequest), siftObject);
|
|
241
219
|
}
|
|
242
|
-
_request3DSToken(isTest, callback) {
|
|
243
|
-
if (isTest)
|
|
244
|
-
Promise.resolve().then(() => require("./../../lib/libs/cardinal/staging")).then(() => {
|
|
245
|
-
this._setupCompleteCardinal(callback);
|
|
246
|
-
});
|
|
247
|
-
else
|
|
248
|
-
Promise.resolve().then(() => require("./../../lib/libs/cardinal/prod")).then(() => {
|
|
249
|
-
this._setupCompleteCardinal(callback);
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
220
|
// istanbul ignore next
|
|
253
|
-
|
|
254
|
-
window.Cardinal.on(
|
|
221
|
+
_request3DSToken(callback) {
|
|
222
|
+
window.Cardinal.on(this._paymentSetupCompleteEvent, () => {
|
|
255
223
|
callback();
|
|
256
|
-
})
|
|
224
|
+
});
|
|
257
225
|
}
|
|
258
226
|
// istanbul ignore next
|
|
259
227
|
_requestTokenGateway(body, mid, testEnv, regional, callback, authorization) {
|
|
@@ -284,19 +252,16 @@ let CardService = CardService_1 = class CardService {
|
|
|
284
252
|
_createSubscriptionSiftScienceSession(subscriptionId, mid, isTest, merchantSettingsResponse, regional, request) {
|
|
285
253
|
return rxjs_1.of(1).pipe(operators_1.switchMap(() => this._getUserId(subscriptionId, mid, isTest, regional, request.userId)), operators_1.switchMap((getUserIdResponse) => this._antiFraud.createSiftScienceSession(subscriptionId, "", mid, isTest, merchantSettingsResponse, UtilsService_1.UtilsService.sGet(getUserIdResponse, "userId"))));
|
|
286
254
|
}
|
|
287
|
-
_checkCardLength(request
|
|
255
|
+
_checkCardLength(request) {
|
|
288
256
|
if (request.card.number.length < 14 || request.card.number.length > 19)
|
|
289
|
-
throw new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS[
|
|
257
|
+
throw new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS[ErrorEnum_1.ErrorCode.E005]);
|
|
258
|
+
}
|
|
259
|
+
_checkSecureInitCardLength(request) {
|
|
260
|
+
if (request.card.number.length < 6 || request.card.number.length > 19)
|
|
261
|
+
throw new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS[ErrorEnum_1.ErrorCode.E014]);
|
|
290
262
|
}
|
|
291
263
|
_getScienceSession(request, mid, isTest, merchant) {
|
|
292
|
-
return rxjs_1.of(1).pipe(operators_1.switchMap(() =>
|
|
293
|
-
if (request.card && request.card.number !== undefined)
|
|
294
|
-
return this._antiFraud.createSiftScienceSession(UtilsService_1.getBinFromCreditCardNumberSift(request.card.number), request.card.number.slice(-4), mid, isTest, merchant);
|
|
295
|
-
return rxjs_1.of({
|
|
296
|
-
sessionId: null,
|
|
297
|
-
userId: null,
|
|
298
|
-
});
|
|
299
|
-
}));
|
|
264
|
+
return rxjs_1.of(1).pipe(operators_1.switchMap(() => this._antiFraud.createSiftScienceSession(UtilsService_1.getBinFromCreditCardNumberSift(request.card.number), request.card.number.slice(-4), mid, isTest, merchant)));
|
|
300
265
|
}
|
|
301
266
|
_checkCurrency(request) {
|
|
302
267
|
request.currency =
|
|
@@ -314,8 +279,7 @@ let CardService = CardService_1 = class CardService {
|
|
|
314
279
|
}
|
|
315
280
|
_checkRequestBody(request) {
|
|
316
281
|
this._checkCurrency(request);
|
|
317
|
-
|
|
318
|
-
this._checkCardLength(request);
|
|
282
|
+
this._checkCardLength(request);
|
|
319
283
|
this._checkAmount(request);
|
|
320
284
|
}
|
|
321
285
|
_getCybersourceJwt(merchantSettings, mid, isTest, regional, cardNumber) {
|
|
@@ -341,38 +305,73 @@ let CardService = CardService_1 = class CardService {
|
|
|
341
305
|
_is3DSSecureEnabled(merchantSettings) {
|
|
342
306
|
return merchantSettings[this._3Dsecure] === true;
|
|
343
307
|
}
|
|
308
|
+
_loadCardinalScript(isTest, onLoad, onLoadError) {
|
|
309
|
+
const last_script = document.getElementById("cardinal_sc_id");
|
|
310
|
+
if (last_script)
|
|
311
|
+
last_script.remove();
|
|
312
|
+
const head = document.getElementsByTagName("head")[0];
|
|
313
|
+
const script = document.createElement("script");
|
|
314
|
+
script.id = "cardinal_sc_id";
|
|
315
|
+
script.src = isTest
|
|
316
|
+
? "https://songbirdstag.cardinalcommerce.com/cardinalcruise/v1/songbird.js"
|
|
317
|
+
: "https://songbird.cardinalcommerce.com/cardinalcruise/v1/songbird.js";
|
|
318
|
+
head.appendChild(script);
|
|
319
|
+
script.onload = onLoad;
|
|
320
|
+
script.onerror = onLoadError;
|
|
321
|
+
}
|
|
344
322
|
_initCybersource(cardNumber, mid, isTest, regional) {
|
|
345
|
-
return rxjs_1.
|
|
346
|
-
this.
|
|
323
|
+
return new rxjs_1.Observable(observer => {
|
|
324
|
+
this._loadCardinalScript(isTest, () => {
|
|
325
|
+
observer.next();
|
|
326
|
+
observer.complete();
|
|
327
|
+
}, () => observer.error(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E018)));
|
|
328
|
+
}).pipe(operators_1.switchMap(() => this._gateway.cybersourceJwt(mid, isTest, regional)), operators_1.map((jwtResponse) => {
|
|
329
|
+
this._initializeCardinal(jwtResponse.jwt, cardNumber);
|
|
347
330
|
return jwtResponse.jwt;
|
|
348
331
|
}));
|
|
349
332
|
}
|
|
350
|
-
_initializeCardinal(
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
333
|
+
_initializeCardinal(jwt, cardNumber) {
|
|
334
|
+
window.Cardinal.setup("init", {
|
|
335
|
+
jwt,
|
|
336
|
+
order: {
|
|
337
|
+
Consumer: {
|
|
338
|
+
Account: {
|
|
339
|
+
AccountNumber: UtilsService_1.getBinFromCreditCardNumber(cardNumber),
|
|
340
|
+
},
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
});
|
|
359
344
|
}
|
|
360
345
|
_initCybersourceSubscription(subscriptionId, mid, isTest, regional) {
|
|
361
|
-
return rxjs_1.
|
|
362
|
-
|
|
363
|
-
|
|
346
|
+
return new rxjs_1.Observable(observer => {
|
|
347
|
+
this._loadCardinalScript(isTest, () => {
|
|
348
|
+
observer.next();
|
|
349
|
+
observer.complete();
|
|
350
|
+
}, () => observer.error(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E018)));
|
|
351
|
+
}).pipe(operators_1.switchMap(() => this._gateway.cybersourceJwt(mid, isTest, regional, subscriptionId)), operators_1.map((jwtResponse) => {
|
|
352
|
+
const bin = buffer_1.Buffer.from(jwtResponse.identifier, "base64").toString("ascii");
|
|
353
|
+
this._initializeCardinal(jwtResponse.jwt, bin);
|
|
364
354
|
return jwtResponse.jwt;
|
|
365
355
|
}));
|
|
366
356
|
}
|
|
367
357
|
// istanbul ignore next
|
|
368
358
|
_completeCardinal(secureServiceId, mid, isTest, regional, callback) {
|
|
369
|
-
return window.Cardinal.on(
|
|
359
|
+
return window.Cardinal.on(this._paymentValidatedEvent, (data) => __awaiter(this, void 0, void 0, function* () {
|
|
360
|
+
if (data.ActionCode === CardinalValidated_1.ActionCodeEnum.FAIL && !data.Validated) {
|
|
361
|
+
window.Cardinal.off(this._paymentSetupCompleteEvent);
|
|
362
|
+
window.Cardinal.off(this._paymentValidatedEvent);
|
|
363
|
+
return Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E012), callback);
|
|
364
|
+
}
|
|
370
365
|
const otp_request = {
|
|
371
366
|
secureServiceId,
|
|
372
367
|
otpValue: "",
|
|
373
368
|
};
|
|
374
369
|
const secure = this._gateway.requestSecureServiceValidation(mid, otp_request, isTest, regional);
|
|
375
370
|
return secure.subscribe({
|
|
371
|
+
complete: () => {
|
|
372
|
+
window.Cardinal.off(this._paymentSetupCompleteEvent);
|
|
373
|
+
window.Cardinal.off(this._paymentValidatedEvent);
|
|
374
|
+
},
|
|
376
375
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
377
376
|
next: (response) => {
|
|
378
377
|
callback({
|
|
@@ -382,18 +381,6 @@ let CardService = CardService_1 = class CardService {
|
|
|
382
381
|
});
|
|
383
382
|
}));
|
|
384
383
|
}
|
|
385
|
-
static _initCardinal(jwt, cardNumber) {
|
|
386
|
-
window.Cardinal.setup("init", {
|
|
387
|
-
jwt,
|
|
388
|
-
order: {
|
|
389
|
-
Consumer: {
|
|
390
|
-
Account: {
|
|
391
|
-
AccountNumber: cardNumber,
|
|
392
|
-
},
|
|
393
|
-
},
|
|
394
|
-
},
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
384
|
static _ccaCardinal(tokenResponse) {
|
|
398
385
|
window.Cardinal.continue("cca", {
|
|
399
386
|
AcsUrl: tokenResponse.security.acsURL,
|
|
@@ -431,7 +418,7 @@ let CardService = CardService_1 = class CardService {
|
|
|
431
418
|
},
|
|
432
419
|
});
|
|
433
420
|
// istanbul ignore next
|
|
434
|
-
cardinal_sandbox_js_1.KushkiCardinalSandbox.on(
|
|
421
|
+
cardinal_sandbox_js_1.KushkiCardinalSandbox.on(this._paymentValidatedEvent, (isErrorFlow) => __awaiter(this, void 0, void 0, function* () {
|
|
435
422
|
if (isErrorFlow === true)
|
|
436
423
|
return Kushki_1.Kushki.callbackError(new KushkiError_1.KushkiError(ErrorEnum_1.ERRORS.E008), callback);
|
|
437
424
|
const otp_request = {
|
|
@@ -450,9 +437,9 @@ let CardService = CardService_1 = class CardService {
|
|
|
450
437
|
_getUserId(subscriptionId, mid, testEnv, regional, userId) {
|
|
451
438
|
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)));
|
|
452
439
|
}
|
|
453
|
-
_requestSubscriptionTokenGateway(body, mid, testEnv, regional, callback
|
|
440
|
+
_requestSubscriptionTokenGateway(body, mid, testEnv, regional, callback) {
|
|
454
441
|
this._gateway
|
|
455
|
-
.requestSubscriptionToken(body, mid, testEnv, regional
|
|
442
|
+
.requestSubscriptionToken(body, mid, testEnv, regional)
|
|
456
443
|
.subscribe({
|
|
457
444
|
error: (err) => Kushki_1.Kushki.callbackError(err, callback),
|
|
458
445
|
next: (response) => {
|
|
@@ -468,12 +455,16 @@ let CardService = CardService_1 = class CardService {
|
|
|
468
455
|
},
|
|
469
456
|
});
|
|
470
457
|
}
|
|
458
|
+
_isInvalidSpecificationVersion(body, sandboxEnabled) {
|
|
459
|
+
const is_invalid_version = body.security.specificationVersion !== undefined &&
|
|
460
|
+
body.security.specificationVersion.startsWith("1.");
|
|
461
|
+
return is_invalid_version && !sandboxEnabled;
|
|
462
|
+
}
|
|
471
463
|
};
|
|
472
464
|
CardService = CardService_1 = __decorate([
|
|
473
465
|
inversify_1.injectable(),
|
|
474
466
|
__param(0, inversify_1.inject(Identifiers_1.IDENTIFIERS.KushkiGateway)),
|
|
475
|
-
__param(1, inversify_1.inject(Identifiers_1.IDENTIFIERS.
|
|
476
|
-
|
|
477
|
-
__metadata("design:paramtypes", [Object, Object, Object])
|
|
467
|
+
__param(1, inversify_1.inject(Identifiers_1.IDENTIFIERS.AntiFraud)),
|
|
468
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
478
469
|
], CardService);
|
|
479
470
|
exports.CardService = CardService;
|