typescript-pos 0.1.1 → 0.2.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/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/dist/index.cjs +991 -227
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +93 -10
- package/dist/index.d.ts +93 -10
- package/dist/index.js +990 -227
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -52,6 +52,7 @@ __export(index_exports, {
|
|
|
52
52
|
NotImplementedError: () => NotImplementedError,
|
|
53
53
|
OrderMismatchError: () => OrderMismatchError,
|
|
54
54
|
PAYMENT_STATUS: () => PAYMENT_STATUS,
|
|
55
|
+
PayFlexCPV4Pos: () => PayFlexCPV4Pos,
|
|
55
56
|
PayFlexPosAccount: () => PayFlexPosAccount,
|
|
56
57
|
PayFlexV4Pos: () => PayFlexV4Pos,
|
|
57
58
|
PosError: () => PosError,
|
|
@@ -93,7 +94,9 @@ var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
|
93
94
|
"secret_key",
|
|
94
95
|
"store_key",
|
|
95
96
|
"cvv2val",
|
|
96
|
-
"expires"
|
|
97
|
+
"expires",
|
|
98
|
+
"expiremonth",
|
|
99
|
+
"expireyear"
|
|
97
100
|
]);
|
|
98
101
|
var PAN_PATTERN = /(?<!\d)\d{13,19}(?!\d)/g;
|
|
99
102
|
var MASK = "***";
|
|
@@ -105,42 +108,45 @@ var SENSITIVE_TAGS = [
|
|
|
105
108
|
"Expiry",
|
|
106
109
|
"ExpiryDate",
|
|
107
110
|
"Expires",
|
|
111
|
+
"ExpireMonth",
|
|
112
|
+
"ExpireYear",
|
|
108
113
|
"Password",
|
|
109
114
|
"MerchantPassword",
|
|
110
115
|
"Pan"
|
|
111
116
|
];
|
|
112
117
|
var XML_PATTERN = new RegExp(`(<(${SENSITIVE_TAGS.join("|")})(?:\\s[^>]*)?>)[^<]*(</\\2\\s*>)`, "gi");
|
|
113
118
|
var QUERY_PATTERN = new RegExp(`(?<![A-Za-z0-9_])(${SENSITIVE_TAGS.join("|")})=[^&\\s"']*`, "gi");
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (typeof
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
if (
|
|
125
|
-
if (
|
|
119
|
+
var JSON_PATTERN = new RegExp(`"(${SENSITIVE_TAGS.join("|")})"\\s*:\\s*"(?:[^"\\\\]|\\\\.)*"`, "gi");
|
|
120
|
+
function maskString(value2) {
|
|
121
|
+
return value2.replace(XML_PATTERN, `$1${MASK}$3`).replace(QUERY_PATTERN, `$1=${MASK}`).replace(JSON_PATTERN, `"$1":"${MASK}"`).replace(PAN_PATTERN, (m) => `${m.slice(0, 6)}****${m.slice(-4)}`);
|
|
122
|
+
}
|
|
123
|
+
function mask(value2, seen, depth) {
|
|
124
|
+
if (typeof value2 === "string") return maskString(value2);
|
|
125
|
+
if (typeof value2 === "number" || typeof value2 === "bigint") {
|
|
126
|
+
const str = String(value2);
|
|
127
|
+
return /^\d{13,19}$/.test(str) ? maskString(str) : value2;
|
|
128
|
+
}
|
|
129
|
+
if (typeof value2 === "function") return "[Function]";
|
|
130
|
+
if (value2 === null || typeof value2 !== "object") return value2;
|
|
131
|
+
if (seen.has(value2)) return seen.get(value2);
|
|
126
132
|
if (depth >= MAX_DEPTH) return "[MaxDepth]";
|
|
127
|
-
if (
|
|
128
|
-
const out2 = { name:
|
|
129
|
-
seen.set(
|
|
133
|
+
if (value2 instanceof Error) {
|
|
134
|
+
const out2 = { name: value2.name, message: maskString(value2.message) };
|
|
135
|
+
seen.set(value2, out2);
|
|
130
136
|
return out2;
|
|
131
137
|
}
|
|
132
|
-
if (Array.isArray(
|
|
138
|
+
if (Array.isArray(value2)) {
|
|
133
139
|
const out2 = [];
|
|
134
|
-
seen.set(
|
|
135
|
-
for (const item of
|
|
140
|
+
seen.set(value2, out2);
|
|
141
|
+
for (const item of value2) out2.push(mask(item, seen, depth + 1));
|
|
136
142
|
return out2;
|
|
137
143
|
}
|
|
138
|
-
const tag = Object.prototype.toString.call(
|
|
139
|
-
if (tag === "Date") return
|
|
144
|
+
const tag = Object.prototype.toString.call(value2).slice(8, -1);
|
|
145
|
+
if (tag === "Date") return value2;
|
|
140
146
|
if (tag !== "Object") return `[${tag}]`;
|
|
141
147
|
const out = {};
|
|
142
|
-
seen.set(
|
|
143
|
-
for (const [key, item] of Object.entries(
|
|
148
|
+
seen.set(value2, out);
|
|
149
|
+
for (const [key, item] of Object.entries(value2)) {
|
|
144
150
|
if (SENSITIVE_KEYS.has(key.toLowerCase()) && item !== null && item !== void 0) {
|
|
145
151
|
out[key] = MASK;
|
|
146
152
|
} else {
|
|
@@ -197,9 +203,9 @@ var OrderMismatchError = class extends PosError {
|
|
|
197
203
|
* Always `false` when no response is attached.
|
|
198
204
|
*/
|
|
199
205
|
paymentMayHaveCompleted;
|
|
200
|
-
constructor(
|
|
201
|
-
super(`Callback ${
|
|
202
|
-
this.field =
|
|
206
|
+
constructor(field4, expected, actual, response) {
|
|
207
|
+
super(`Callback ${field4} mismatch: expected "${expected}", got "${actual}"`);
|
|
208
|
+
this.field = field4;
|
|
203
209
|
this.expected = expected;
|
|
204
210
|
this.actual = actual;
|
|
205
211
|
this.paymentMayHaveCompleted = response !== void 0 && (response.status === "approved" || response.proc_return_code === "00");
|
|
@@ -243,7 +249,7 @@ var HttpTransport = class {
|
|
|
243
249
|
const exchange = async () => {
|
|
244
250
|
let res;
|
|
245
251
|
let bytes;
|
|
246
|
-
let
|
|
252
|
+
let text6;
|
|
247
253
|
try {
|
|
248
254
|
res = await this.fetchImpl(url, {
|
|
249
255
|
method: "POST",
|
|
@@ -253,7 +259,7 @@ var HttpTransport = class {
|
|
|
253
259
|
redirect: "error"
|
|
254
260
|
});
|
|
255
261
|
bytes = new Uint8Array(await res.arrayBuffer());
|
|
256
|
-
|
|
262
|
+
text6 = new TextDecoder().decode(bytes);
|
|
257
263
|
} catch (e) {
|
|
258
264
|
if (e instanceof PosHttpError) throw e;
|
|
259
265
|
throw new PosHttpError(
|
|
@@ -263,9 +269,9 @@ var HttpTransport = class {
|
|
|
263
269
|
);
|
|
264
270
|
}
|
|
265
271
|
if (res.status < 200 || res.status >= 300) {
|
|
266
|
-
throw new PosHttpError(`Bank returned HTTP ${res.status}`, { url, status: res.status, body:
|
|
272
|
+
throw new PosHttpError(`Bank returned HTTP ${res.status}`, { url, status: res.status, body: text6 });
|
|
267
273
|
}
|
|
268
|
-
return { status: res.status, body:
|
|
274
|
+
return { status: res.status, body: text6, bytes, headers: res.headers };
|
|
269
275
|
};
|
|
270
276
|
const pending = exchange();
|
|
271
277
|
pending.catch(() => {
|
|
@@ -283,13 +289,13 @@ function freezeConfig(config) {
|
|
|
283
289
|
deepFreeze(config);
|
|
284
290
|
return config;
|
|
285
291
|
}
|
|
286
|
-
function deepFreeze(
|
|
287
|
-
for (const child of Object.values(
|
|
292
|
+
function deepFreeze(value2) {
|
|
293
|
+
for (const child of Object.values(value2)) {
|
|
288
294
|
if (child !== null && typeof child === "object") {
|
|
289
295
|
deepFreeze(child);
|
|
290
296
|
}
|
|
291
297
|
}
|
|
292
|
-
Object.freeze(
|
|
298
|
+
Object.freeze(value2);
|
|
293
299
|
}
|
|
294
300
|
|
|
295
301
|
// src/config/posProductionConfig.ts
|
|
@@ -353,6 +359,13 @@ var posProductionConfig = freezeConfig({
|
|
|
353
359
|
query_api: "https://apigw.vakifbank.com.tr:8443/virtualPos/Search"
|
|
354
360
|
}
|
|
355
361
|
},
|
|
362
|
+
"vakifbank-cp": {
|
|
363
|
+
name: "VakifBank-PayFlex-Common-Payment",
|
|
364
|
+
class: "PayFlexCPV4Pos",
|
|
365
|
+
gateway_endpoints: {
|
|
366
|
+
payment_api: "https://inbound.apigateway.vakifbank.com.tr:8443/commonPayment"
|
|
367
|
+
}
|
|
368
|
+
},
|
|
356
369
|
"ziraat-vpos": {
|
|
357
370
|
name: "Ziraat Bankas\u0131 PayFlex",
|
|
358
371
|
class: "PayFlexV4Pos",
|
|
@@ -393,6 +406,13 @@ var posTestConfig = freezeConfig({
|
|
|
393
406
|
query_api: "https://inbound.apigatewaytest.vakifbank.com.tr:8443/virtualPos/Search"
|
|
394
407
|
}
|
|
395
408
|
},
|
|
409
|
+
"vakifbank-cp": {
|
|
410
|
+
name: "VakifBank-PayFlex-Common-Payment",
|
|
411
|
+
class: "PayFlexCPV4Pos",
|
|
412
|
+
gateway_endpoints: {
|
|
413
|
+
payment_api: "https://inbound.apigatewaytest.vakifbank.com.tr:8443/commonPayment"
|
|
414
|
+
}
|
|
415
|
+
},
|
|
396
416
|
"ziraat-vpos": {
|
|
397
417
|
name: "Ziraat Bankas\u0131",
|
|
398
418
|
class: "PayFlexV4Pos",
|
|
@@ -690,36 +710,36 @@ var XmlDecoder = {
|
|
|
690
710
|
|
|
691
711
|
// src/serializer/XmlEncoder.ts
|
|
692
712
|
var ILLEGAL_XML_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F]/g;
|
|
693
|
-
function escapeText(
|
|
694
|
-
return
|
|
713
|
+
function escapeText(value2) {
|
|
714
|
+
return value2.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
695
715
|
}
|
|
696
|
-
function escapeAttr(
|
|
697
|
-
return escapeText(
|
|
716
|
+
function escapeAttr(value2) {
|
|
717
|
+
return escapeText(value2).replace(/"/g, """);
|
|
698
718
|
}
|
|
699
|
-
function scalar(
|
|
700
|
-
if (
|
|
701
|
-
if (
|
|
702
|
-
if (
|
|
703
|
-
return String(
|
|
719
|
+
function scalar(value2) {
|
|
720
|
+
if (value2 === true) return "1";
|
|
721
|
+
if (value2 === false) return "0";
|
|
722
|
+
if (value2 === null || value2 === void 0) return "";
|
|
723
|
+
return String(value2).replace(ILLEGAL_XML_CHARS, "");
|
|
704
724
|
}
|
|
705
|
-
function text(
|
|
706
|
-
const str = scalar(
|
|
725
|
+
function text(value2) {
|
|
726
|
+
const str = scalar(value2);
|
|
707
727
|
if (/[<>&]/.test(str)) return `<![CDATA[${str.replace(/]]>/g, "]]]]><![CDATA[>")}]]>`;
|
|
708
728
|
return str;
|
|
709
729
|
}
|
|
710
|
-
function element(name,
|
|
711
|
-
if (Array.isArray(
|
|
712
|
-
if (
|
|
730
|
+
function element(name, value2) {
|
|
731
|
+
if (Array.isArray(value2)) return value2.map((item) => element(name, item)).join("");
|
|
732
|
+
if (value2 !== null && typeof value2 === "object") {
|
|
713
733
|
let attrs = "";
|
|
714
734
|
let inner = "";
|
|
715
|
-
for (const [key, v] of Object.entries(
|
|
735
|
+
for (const [key, v] of Object.entries(value2)) {
|
|
716
736
|
if (key.startsWith("@")) attrs += ` ${key.slice(1)}="${escapeAttr(scalar(v))}"`;
|
|
717
737
|
else if (key === "#") inner += text(v);
|
|
718
738
|
else inner += element(key, v);
|
|
719
739
|
}
|
|
720
740
|
return inner === "" ? `<${name}${attrs}/>` : `<${name}${attrs}>${inner}</${name}>`;
|
|
721
741
|
}
|
|
722
|
-
const str = text(
|
|
742
|
+
const str = text(value2);
|
|
723
743
|
return str === "" ? `<${name}/>` : `<${name}>${str}</${name}>`;
|
|
724
744
|
}
|
|
725
745
|
var XmlEncoder = {
|
|
@@ -846,9 +866,9 @@ var REPLACED_LATIN1_LETTERS = /* @__PURE__ */ new Set([208, 221, 222, 240, 253,
|
|
|
846
866
|
function inIso88599(codePoint) {
|
|
847
867
|
return codePoint <= 255 ? !REPLACED_LATIN1_LETTERS.has(codePoint) : TURKISH_LETTERS.has(codePoint);
|
|
848
868
|
}
|
|
849
|
-
function replaceUnrepresentable(
|
|
869
|
+
function replaceUnrepresentable(value2, replace) {
|
|
850
870
|
let out = "";
|
|
851
|
-
for (const char of
|
|
871
|
+
for (const char of value2) {
|
|
852
872
|
out += inIso88599(char.codePointAt(0)) ? char : replace(char);
|
|
853
873
|
}
|
|
854
874
|
return out;
|
|
@@ -970,30 +990,30 @@ var CARD_TYPE = {
|
|
|
970
990
|
};
|
|
971
991
|
|
|
972
992
|
// src/serializer/FormEncoder.ts
|
|
973
|
-
function phpUrlEncode(
|
|
974
|
-
return encodeURIComponent(
|
|
993
|
+
function phpUrlEncode(value2) {
|
|
994
|
+
return encodeURIComponent(value2).replace(/[!'()*~]/g, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(/%20/g, "+");
|
|
975
995
|
}
|
|
976
|
-
function scalarToString(
|
|
977
|
-
if (typeof
|
|
978
|
-
return String(
|
|
996
|
+
function scalarToString(value2) {
|
|
997
|
+
if (typeof value2 === "boolean") return value2 ? "1" : "0";
|
|
998
|
+
return String(value2);
|
|
979
999
|
}
|
|
980
1000
|
function sub(prefix, key) {
|
|
981
1001
|
return prefix === null ? phpUrlEncode(key) : `${prefix}%5B${phpUrlEncode(key)}%5D`;
|
|
982
1002
|
}
|
|
983
|
-
function build(prefix,
|
|
984
|
-
if (
|
|
985
|
-
if (Array.isArray(
|
|
986
|
-
|
|
1003
|
+
function build(prefix, value2, out) {
|
|
1004
|
+
if (value2 === null || value2 === void 0) return;
|
|
1005
|
+
if (Array.isArray(value2)) {
|
|
1006
|
+
value2.forEach((item, i) => {
|
|
987
1007
|
build(sub(prefix, String(i)), item, out);
|
|
988
1008
|
});
|
|
989
1009
|
return;
|
|
990
1010
|
}
|
|
991
|
-
if (typeof
|
|
992
|
-
for (const [k, v] of Object.entries(
|
|
1011
|
+
if (typeof value2 === "object") {
|
|
1012
|
+
for (const [k, v] of Object.entries(value2)) build(sub(prefix, k), v, out);
|
|
993
1013
|
return;
|
|
994
1014
|
}
|
|
995
1015
|
if (prefix === null) return;
|
|
996
|
-
out.push(`${prefix}=${phpUrlEncode(scalarToString(
|
|
1016
|
+
out.push(`${prefix}=${phpUrlEncode(scalarToString(value2))}`);
|
|
997
1017
|
}
|
|
998
1018
|
var FormEncoder = {
|
|
999
1019
|
encode(data) {
|
|
@@ -1003,6 +1023,44 @@ var FormEncoder = {
|
|
|
1003
1023
|
}
|
|
1004
1024
|
};
|
|
1005
1025
|
|
|
1026
|
+
// src/client/PayFlexCPV4PosHttpClient.ts
|
|
1027
|
+
var PayFlexCPV4PosHttpClient = class _PayFlexCPV4PosHttpClient extends AbstractHttpClient {
|
|
1028
|
+
static API_NAME_PAYMENT_API = "payment_api";
|
|
1029
|
+
/** Accepted for configs that name the endpoint `gateway_3d`. */
|
|
1030
|
+
static API_NAME_GATEWAY_3D = "gateway_3d";
|
|
1031
|
+
constructor(endpoint, transport, logger = noopLogger) {
|
|
1032
|
+
super(endpoint, transport, logger);
|
|
1033
|
+
}
|
|
1034
|
+
static supports(gatewayClass, apiName) {
|
|
1035
|
+
return gatewayClass === "PayFlexCPV4Pos" && (apiName === _PayFlexCPV4PosHttpClient.API_NAME_PAYMENT_API || apiName === _PayFlexCPV4PosHttpClient.API_NAME_GATEWAY_3D);
|
|
1036
|
+
}
|
|
1037
|
+
supportsTx(_txType, _paymentModel) {
|
|
1038
|
+
return true;
|
|
1039
|
+
}
|
|
1040
|
+
getApiUrl(txType, _paymentModel) {
|
|
1041
|
+
const base = this.endpoint.endsWith("/") ? this.endpoint.slice(0, -1) : this.endpoint;
|
|
1042
|
+
if (txType === TX_TYPE.INTERNAL_3D_FORM_BUILD) {
|
|
1043
|
+
return `${base}/CreateToken`;
|
|
1044
|
+
}
|
|
1045
|
+
return `${base}/GetVposTransaction`;
|
|
1046
|
+
}
|
|
1047
|
+
encode(txType, _paymentModel, requestData, _order) {
|
|
1048
|
+
if (txType === TX_TYPE.INTERNAL_3D_FORM_BUILD) {
|
|
1049
|
+
return { data: FormEncoder.encode(requestData), format: "form" };
|
|
1050
|
+
}
|
|
1051
|
+
return { data: JSON.stringify(requestData), format: "json" };
|
|
1052
|
+
}
|
|
1053
|
+
headers(txType, paymentModel, encoded) {
|
|
1054
|
+
return { ...super.headers(txType, paymentModel, encoded), Accept: "application/json" };
|
|
1055
|
+
}
|
|
1056
|
+
decode(body) {
|
|
1057
|
+
if (body.trimStart().startsWith("<")) {
|
|
1058
|
+
return Promise.resolve(XmlDecoder.decode(body));
|
|
1059
|
+
}
|
|
1060
|
+
return Promise.resolve(JsonDecoder.decode(body));
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1006
1064
|
// src/client/PayFlexV4Pos3DFormHttpClient.ts
|
|
1007
1065
|
var PayFlexV4Pos3DFormHttpClient = class _PayFlexV4Pos3DFormHttpClient extends AbstractHttpClient {
|
|
1008
1066
|
static API_NAME_GATEWAY_3D_API = "gateway_3d";
|
|
@@ -1175,17 +1233,17 @@ function randomHexString(length = 24) {
|
|
|
1175
1233
|
}
|
|
1176
1234
|
|
|
1177
1235
|
// src/crypt/AbstractCrypt.ts
|
|
1178
|
-
function isContainer(
|
|
1179
|
-
if (Array.isArray(
|
|
1180
|
-
if (
|
|
1181
|
-
const proto = Object.getPrototypeOf(
|
|
1236
|
+
function isContainer(value2) {
|
|
1237
|
+
if (Array.isArray(value2)) return true;
|
|
1238
|
+
if (value2 === null || typeof value2 !== "object") return false;
|
|
1239
|
+
const proto = Object.getPrototypeOf(value2);
|
|
1182
1240
|
return proto === Object.prototype || proto === null;
|
|
1183
1241
|
}
|
|
1184
|
-
function phpString(
|
|
1185
|
-
if (
|
|
1186
|
-
if (
|
|
1187
|
-
if (isContainer(
|
|
1188
|
-
return String(
|
|
1242
|
+
function phpString(value2) {
|
|
1243
|
+
if (value2 === null || value2 === void 0 || value2 === false) return "";
|
|
1244
|
+
if (value2 === true) return "1";
|
|
1245
|
+
if (isContainer(value2)) return "Array";
|
|
1246
|
+
return String(value2);
|
|
1189
1247
|
}
|
|
1190
1248
|
var AbstractCrypt = class {
|
|
1191
1249
|
/** Node `crypto.createHash` algorithm. */
|
|
@@ -1239,10 +1297,10 @@ var AbstractCrypt = class {
|
|
|
1239
1297
|
}
|
|
1240
1298
|
findIn(haystack, needle) {
|
|
1241
1299
|
const isList = Array.isArray(haystack);
|
|
1242
|
-
for (const [key,
|
|
1243
|
-
if (!isList && key === needle) return phpString(
|
|
1244
|
-
if (isContainer(
|
|
1245
|
-
const found = this.findIn(
|
|
1300
|
+
for (const [key, value2] of Object.entries(haystack)) {
|
|
1301
|
+
if (!isList && key === needle) return phpString(value2);
|
|
1302
|
+
if (isContainer(value2)) {
|
|
1303
|
+
const found = this.findIn(value2, needle);
|
|
1246
1304
|
if (found !== void 0) return found;
|
|
1247
1305
|
}
|
|
1248
1306
|
}
|
|
@@ -1252,10 +1310,10 @@ var AbstractCrypt = class {
|
|
|
1252
1310
|
|
|
1253
1311
|
// src/crypt/AssecoPosCrypt.ts
|
|
1254
1312
|
var EXCLUDED_KEYS = /* @__PURE__ */ new Set(["hash", "encoding", "nationalidno"]);
|
|
1255
|
-
function phpString2(
|
|
1256
|
-
if (
|
|
1257
|
-
if (
|
|
1258
|
-
return String(
|
|
1313
|
+
function phpString2(value2) {
|
|
1314
|
+
if (value2 === null || value2 === void 0 || value2 === false) return "";
|
|
1315
|
+
if (value2 === true) return "1";
|
|
1316
|
+
return String(value2);
|
|
1259
1317
|
}
|
|
1260
1318
|
var AssecoPosCrypt = class extends AbstractCrypt {
|
|
1261
1319
|
hashAlgorithm = "sha512";
|
|
@@ -1270,10 +1328,10 @@ var AssecoPosCrypt = class extends AbstractCrypt {
|
|
|
1270
1328
|
* `nationalidno` (seen in Ziraat callbacks) must not be part of the hash string; confirmed by Asseco.
|
|
1271
1329
|
*/
|
|
1272
1330
|
create3DHash(account, formInputs) {
|
|
1273
|
-
const values = Object.entries(formInputs).sort(([a], [b]) => strnatcasecmp(a, b)).filter(([key]) => !EXCLUDED_KEYS.has(key.toLowerCase())).map(([,
|
|
1331
|
+
const values = Object.entries(formInputs).sort(([a], [b]) => strnatcasecmp(a, b)).filter(([key]) => !EXCLUDED_KEYS.has(key.toLowerCase())).map(([, value2]) => phpString2(value2));
|
|
1274
1332
|
values.push(account.getSecretKey());
|
|
1275
1333
|
const escaped = values.map(
|
|
1276
|
-
(
|
|
1334
|
+
(value2) => value2.replaceAll("\\", "\\\\").replaceAll(this.hashSeparator, `\\${this.hashSeparator}`)
|
|
1277
1335
|
);
|
|
1278
1336
|
return this.hashString(escaped.join(this.hashSeparator));
|
|
1279
1337
|
}
|
|
@@ -1292,6 +1350,22 @@ var AssecoPosCrypt = class extends AbstractCrypt {
|
|
|
1292
1350
|
}
|
|
1293
1351
|
};
|
|
1294
1352
|
|
|
1353
|
+
// src/crypt/PayFlexCPV4PosCrypt.ts
|
|
1354
|
+
var PayFlexCPV4PosCrypt = class extends AbstractCrypt {
|
|
1355
|
+
static supports(gatewayClass) {
|
|
1356
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
1357
|
+
}
|
|
1358
|
+
create3DHash(_account, _formInputs) {
|
|
1359
|
+
throw new NotImplementedError("Common payment has no 3D form hash.");
|
|
1360
|
+
}
|
|
1361
|
+
check3DHash(_account, _data) {
|
|
1362
|
+
throw new NotImplementedError("The common payment callback is confirmed by the query API.");
|
|
1363
|
+
}
|
|
1364
|
+
createHash(_account, _requestData) {
|
|
1365
|
+
throw new NotImplementedError("The common payment registration is sent without HashedData.");
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
|
|
1295
1369
|
// src/crypt/PayFlexV4PosCrypt.ts
|
|
1296
1370
|
var import_node_crypto4 = require("crypto");
|
|
1297
1371
|
var import_iconv_lite2 = __toESM(require("iconv-lite"), 1);
|
|
@@ -1330,11 +1404,11 @@ var PayFlexV4PosCrypt = class extends NullCrypt {
|
|
|
1330
1404
|
if (hashKey === void 0) {
|
|
1331
1405
|
return true;
|
|
1332
1406
|
}
|
|
1333
|
-
const
|
|
1334
|
-
const
|
|
1335
|
-
return typeof
|
|
1407
|
+
const field4 = (name) => {
|
|
1408
|
+
const value2 = Object.hasOwn(data, name) ? data[name] : void 0;
|
|
1409
|
+
return typeof value2 === "string" ? value2 : "";
|
|
1336
1410
|
};
|
|
1337
|
-
const hashString =
|
|
1411
|
+
const hashString = field4("VerifyEnrollmentRequestId") + field4("MerchantId") + field4("PurchCurrency") + field4("PurchAmount").replaceAll(".", "") + field4("Eci").padStart(2, "0") + field4("Cavv") + field4("MdStatus") + field4("Status") + account.getPassword();
|
|
1338
1412
|
const expected = this.hashBytes(import_iconv_lite2.default.encode(hashString, "ISO-8859-9"));
|
|
1339
1413
|
if (timingSafeEqualStr(data[hashKey], expected)) {
|
|
1340
1414
|
this.logger.debug("hash check is successful");
|
|
@@ -1349,22 +1423,22 @@ var PayFlexV4PosCrypt = class extends NullCrypt {
|
|
|
1349
1423
|
};
|
|
1350
1424
|
|
|
1351
1425
|
// src/util/required.ts
|
|
1352
|
-
function isSet(
|
|
1353
|
-
return
|
|
1426
|
+
function isSet(value2) {
|
|
1427
|
+
return value2 !== void 0 && value2 !== null;
|
|
1354
1428
|
}
|
|
1355
1429
|
function required(order, key) {
|
|
1356
|
-
const
|
|
1357
|
-
if (!isSet(
|
|
1430
|
+
const value2 = order[key];
|
|
1431
|
+
if (!isSet(value2) || value2 === "") {
|
|
1358
1432
|
throw new PosError(`Order field "${String(key)}" is required`);
|
|
1359
1433
|
}
|
|
1360
|
-
return
|
|
1434
|
+
return value2;
|
|
1361
1435
|
}
|
|
1362
1436
|
function requiredString(data, key, what) {
|
|
1363
|
-
const
|
|
1364
|
-
if (!isSet(
|
|
1437
|
+
const value2 = data[key];
|
|
1438
|
+
if (!isSet(value2) || value2 === "") {
|
|
1365
1439
|
throw new PosError(`${what} field "${key}" is required`);
|
|
1366
1440
|
}
|
|
1367
|
-
return String(
|
|
1441
|
+
return String(value2);
|
|
1368
1442
|
}
|
|
1369
1443
|
|
|
1370
1444
|
// src/hooks.ts
|
|
@@ -1601,6 +1675,130 @@ var AssecoPosRequestDataMapper = class extends AbstractRequestDataMapper {
|
|
|
1601
1675
|
}
|
|
1602
1676
|
};
|
|
1603
1677
|
|
|
1678
|
+
// src/data-mapper/request/mapper/PayFlexCPV4PosRequestDataMapper.ts
|
|
1679
|
+
var ORDER_ID_PATTERN = /^[0-9a-zA-Z-]+$/;
|
|
1680
|
+
var TRANSACTION_ID_PATTERN = /^[0-9A-Za-z-]{1,40}$/;
|
|
1681
|
+
var PayFlexCPV4PosRequestDataMapper = class extends AbstractRequestDataMapper {
|
|
1682
|
+
static supports(gatewayClass) {
|
|
1683
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
1684
|
+
}
|
|
1685
|
+
create3DPaymentRequestData(_account, _order, _txType, _responseData, _creditCard = null) {
|
|
1686
|
+
throw new NotImplementedError("Common payment completes the payment on the bank page");
|
|
1687
|
+
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Query (GetVposTransaction) body built from the callback data. At least one of `TransactionId` / `PaymentToken`
|
|
1690
|
+
* is needed (VakifBank Common Payment guide v2.1 §6.5).
|
|
1691
|
+
*/
|
|
1692
|
+
create3DPaymentStatusRequestData(account, responseData) {
|
|
1693
|
+
return this.createQueryData(account, responseData.TransactionId, responseData.PaymentToken, "3D response");
|
|
1694
|
+
}
|
|
1695
|
+
/**
|
|
1696
|
+
* Registration (CreateToken) body. Field set and the `MerchantId` rule follow VakifBank Common Payment guide
|
|
1697
|
+
* v2.1 §4/§5: `MerchantId` is `1`, or the sub merchant id for sub-dealer accounts.
|
|
1698
|
+
*/
|
|
1699
|
+
create3DFormInitializeRequestData(account, order, _paymentModel, txType, creditCard = null) {
|
|
1700
|
+
const orderId = String(required(order, "id"));
|
|
1701
|
+
if (!ORDER_ID_PATTERN.test(orderId)) {
|
|
1702
|
+
throw new PosError('Order field "id" may only contain digits, letters and hyphens');
|
|
1703
|
+
}
|
|
1704
|
+
let transactionId;
|
|
1705
|
+
if (isSet(order.transaction_id) && order.transaction_id !== "") {
|
|
1706
|
+
transactionId = order.transaction_id;
|
|
1707
|
+
if (!TRANSACTION_ID_PATTERN.test(transactionId)) {
|
|
1708
|
+
throw new PosError('Order field "transaction_id" must be 1-40 characters of digits, letters and hyphens');
|
|
1709
|
+
}
|
|
1710
|
+
} else {
|
|
1711
|
+
transactionId = this.crypt.generateRandomString(32);
|
|
1712
|
+
}
|
|
1713
|
+
const requestData = {
|
|
1714
|
+
HostMerchantId: account.getMerchantId(),
|
|
1715
|
+
MerchantId: this.getMerchantId(account),
|
|
1716
|
+
MerchantPassword: account.getPassword(),
|
|
1717
|
+
HostTerminalId: account.getTerminalId(),
|
|
1718
|
+
TransactionType: this.valueMapper.mapTxType(txType),
|
|
1719
|
+
TransactionId: transactionId,
|
|
1720
|
+
AmountCode: String(this.valueMapper.mapCurrency(order.currency ?? CURRENCY.TRY)),
|
|
1721
|
+
Amount: String(this.valueFormatter.formatAmount(required(order, "amount"))),
|
|
1722
|
+
OrderId: orderId,
|
|
1723
|
+
// 3D is always applied; "Half Secure" (AllowNotEnrolledCard true) can be opted into with a request hook.
|
|
1724
|
+
IsSecure: "true",
|
|
1725
|
+
AllowNotEnrolledCard: "false",
|
|
1726
|
+
SuccessUrl: required(order, "success_url"),
|
|
1727
|
+
FailUrl: required(order, "fail_url"),
|
|
1728
|
+
RequestLanguage: this.getLang(order),
|
|
1729
|
+
// printed on the card holder statement
|
|
1730
|
+
Extract: "",
|
|
1731
|
+
// merchant defined extra items
|
|
1732
|
+
CustomItems: ""
|
|
1733
|
+
};
|
|
1734
|
+
if (creditCard !== null) {
|
|
1735
|
+
const cardType = creditCard.getType();
|
|
1736
|
+
requestData.BrandNumber = cardType !== null ? this.valueMapper.mapCardType(cardType) : "";
|
|
1737
|
+
requestData.CVV = creditCard.getCvv();
|
|
1738
|
+
requestData.PAN = creditCard.getNumber();
|
|
1739
|
+
requestData.ExpireMonth = this.valueFormatter.formatCardExpDate(creditCard, "ExpireMonth");
|
|
1740
|
+
requestData.ExpireYear = this.valueFormatter.formatCardExpDate(creditCard, "ExpireYear");
|
|
1741
|
+
requestData.CardHoldersName = creditCard.getHolderName() ?? "";
|
|
1742
|
+
}
|
|
1743
|
+
if (order.installment) {
|
|
1744
|
+
requestData.InstallmentCount = String(this.valueFormatter.formatInstallment(order.installment));
|
|
1745
|
+
}
|
|
1746
|
+
return requestData;
|
|
1747
|
+
}
|
|
1748
|
+
createNonSecurePaymentRequestData(_account, _order, _txType, _creditCard) {
|
|
1749
|
+
throw new NotImplementedError("Common payment has no non-secure payment");
|
|
1750
|
+
}
|
|
1751
|
+
createNonSecurePostAuthPaymentRequestData(_account, _order) {
|
|
1752
|
+
throw new NotImplementedError("Common payment has no post authorization");
|
|
1753
|
+
}
|
|
1754
|
+
/** Query (GetVposTransaction) body from the order's `transaction_id` / `payment_token`. */
|
|
1755
|
+
createStatusRequestData(account, order) {
|
|
1756
|
+
return this.createQueryData(account, order.transaction_id, order.payment_token, "Order");
|
|
1757
|
+
}
|
|
1758
|
+
createCancelRequestData(_account, _order) {
|
|
1759
|
+
throw new NotImplementedError("Common payment has no cancel");
|
|
1760
|
+
}
|
|
1761
|
+
createRefundRequestData(_account, _order, _refundTxType) {
|
|
1762
|
+
throw new NotImplementedError("Common payment has no refund");
|
|
1763
|
+
}
|
|
1764
|
+
createOrderHistoryRequestData(_account, _order) {
|
|
1765
|
+
throw new NotImplementedError("Common payment has no order history");
|
|
1766
|
+
}
|
|
1767
|
+
/** The browser is sent to the bank page with a GET carrying the payment token; no hash is calculated. */
|
|
1768
|
+
async create3DFormData(_account, _order, _paymentModel, _txType, _gatewayURL, _creditCard = null, extraData = null) {
|
|
1769
|
+
if (extraData === null) {
|
|
1770
|
+
throw new PosError("extraData can not be null");
|
|
1771
|
+
}
|
|
1772
|
+
return {
|
|
1773
|
+
gateway: requiredString(extraData, "CommonPaymentUrl", "3D response"),
|
|
1774
|
+
method: "GET",
|
|
1775
|
+
inputs: { Ptkn: requiredString(extraData, "PaymentToken", "3D response") }
|
|
1776
|
+
};
|
|
1777
|
+
}
|
|
1778
|
+
getMerchantId(account) {
|
|
1779
|
+
const sub2 = account.getSubMerchantId();
|
|
1780
|
+
return account.isSubBranch() && sub2 ? sub2 : "1";
|
|
1781
|
+
}
|
|
1782
|
+
createQueryData(account, transactionId, paymentToken, what) {
|
|
1783
|
+
const data = {
|
|
1784
|
+
HostMerchantId: account.getMerchantId(),
|
|
1785
|
+
MerchantId: this.getMerchantId(account),
|
|
1786
|
+
Password: account.getPassword()
|
|
1787
|
+
};
|
|
1788
|
+
if (typeof transactionId === "string" && transactionId !== "") {
|
|
1789
|
+
data.TransactionId = transactionId;
|
|
1790
|
+
}
|
|
1791
|
+
if (typeof paymentToken === "string" && paymentToken !== "") {
|
|
1792
|
+
data.PaymentToken = paymentToken;
|
|
1793
|
+
}
|
|
1794
|
+
if (data.TransactionId === void 0 && data.PaymentToken === void 0) {
|
|
1795
|
+
const [a, b] = what === "Order" ? ["transaction_id", "payment_token"] : ["TransactionId", "PaymentToken"];
|
|
1796
|
+
throw new PosError(`${what} field "${a}" or "${b}" is required`);
|
|
1797
|
+
}
|
|
1798
|
+
return data;
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1604
1802
|
// src/data-mapper/request/mapper/PayFlexV4PosRequestDataMapper.ts
|
|
1605
1803
|
var PayFlexV4PosRequestDataMapper = class extends AbstractRequestDataMapper {
|
|
1606
1804
|
static supports(gatewayClass) {
|
|
@@ -1821,7 +2019,7 @@ var AssecoPosRequestValueFormatter = class {
|
|
|
1821
2019
|
}
|
|
1822
2020
|
};
|
|
1823
2021
|
|
|
1824
|
-
// src/
|
|
2022
|
+
// src/util/numberFormat2.ts
|
|
1825
2023
|
var MAX_AMOUNT = 1e13;
|
|
1826
2024
|
function numberFormat2(amount) {
|
|
1827
2025
|
if (!Number.isFinite(amount) || Math.abs(amount) >= MAX_AMOUNT) {
|
|
@@ -1830,9 +2028,42 @@ function numberFormat2(amount) {
|
|
|
1830
2028
|
const magnitude = Math.abs(amount);
|
|
1831
2029
|
const floor = Math.floor(magnitude * 100);
|
|
1832
2030
|
const cents = magnitude >= (floor + 0.5) / 100 ? floor + 1 : floor;
|
|
1833
|
-
const
|
|
1834
|
-
return amount < 0 && cents !== 0 ? `-${
|
|
2031
|
+
const text6 = (cents / 100).toFixed(2);
|
|
2032
|
+
return amount < 0 && cents !== 0 ? `-${text6}` : text6;
|
|
1835
2033
|
}
|
|
2034
|
+
|
|
2035
|
+
// src/data-mapper/request/value-formatter/PayFlexCPV4PosRequestValueFormatter.ts
|
|
2036
|
+
var PayFlexCPV4PosRequestValueFormatter = class {
|
|
2037
|
+
static supports(gatewayClass) {
|
|
2038
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
2039
|
+
}
|
|
2040
|
+
/** 0 => '0', 1 => '0', 2 => '2' */
|
|
2041
|
+
formatInstallment(installment) {
|
|
2042
|
+
return installment > 1 ? String(installment) : "0";
|
|
2043
|
+
}
|
|
2044
|
+
/** ex: 10.1 => '10.10' */
|
|
2045
|
+
formatAmount(amount, _txType = null) {
|
|
2046
|
+
return numberFormat2(amount);
|
|
2047
|
+
}
|
|
2048
|
+
/** 'ExpireMonth' => 'm' (04), 'ExpireYear' => 'Y' (2024, four digits per guide section 4), 'Expiry' => 'Ym' (202404) */
|
|
2049
|
+
formatCardExpDate(card, fieldName) {
|
|
2050
|
+
if (fieldName === "ExpireMonth") {
|
|
2051
|
+
return card.getExpirationDate("m");
|
|
2052
|
+
}
|
|
2053
|
+
if (fieldName === "ExpireYear") {
|
|
2054
|
+
return card.getExpirationDate("Y");
|
|
2055
|
+
}
|
|
2056
|
+
if (fieldName === "Expiry") {
|
|
2057
|
+
return card.getExpirationDate("Ym");
|
|
2058
|
+
}
|
|
2059
|
+
throw new PosError("Unsupported field name");
|
|
2060
|
+
}
|
|
2061
|
+
formatDateTime(_dateTime, _fieldName = null) {
|
|
2062
|
+
throw new NotImplementedError("Date formatting is not supported.");
|
|
2063
|
+
}
|
|
2064
|
+
};
|
|
2065
|
+
|
|
2066
|
+
// src/data-mapper/request/value-formatter/PayFlexV4PosRequestValueFormatter.ts
|
|
1836
2067
|
function istanbulParts(dateTime) {
|
|
1837
2068
|
const parts = new Intl.DateTimeFormat("en-US", {
|
|
1838
2069
|
timeZone: "Europe/Istanbul",
|
|
@@ -1882,11 +2113,11 @@ function ownValue(obj, key) {
|
|
|
1882
2113
|
|
|
1883
2114
|
// src/data-mapper/request/value-mapper/AbstractRequestValueMapper.ts
|
|
1884
2115
|
function requireMapped(table, key, what) {
|
|
1885
|
-
const
|
|
1886
|
-
if (
|
|
2116
|
+
const value2 = ownValue(table, key);
|
|
2117
|
+
if (value2 === void 0) {
|
|
1887
2118
|
throw new PosError(`${what} "${key}" is not mapped.`);
|
|
1888
2119
|
}
|
|
1889
|
-
return
|
|
2120
|
+
return value2;
|
|
1890
2121
|
}
|
|
1891
2122
|
var AbstractRequestValueMapper = class {
|
|
1892
2123
|
cardTypeMappings = {};
|
|
@@ -2013,6 +2244,35 @@ var AssecoPosRequestValueMapper = class extends AbstractRequestValueMapper {
|
|
|
2013
2244
|
}
|
|
2014
2245
|
};
|
|
2015
2246
|
|
|
2247
|
+
// src/data-mapper/request/value-mapper/PayFlexCPV4PosRequestValueMapper.ts
|
|
2248
|
+
var PayFlexCPV4PosRequestValueMapper = class extends AbstractRequestValueMapper {
|
|
2249
|
+
cardTypeMappings = {
|
|
2250
|
+
[CARD_TYPE.VISA]: "100",
|
|
2251
|
+
[CARD_TYPE.MASTERCARD]: "200",
|
|
2252
|
+
[CARD_TYPE.TROY]: "300",
|
|
2253
|
+
[CARD_TYPE.AMEX]: "400"
|
|
2254
|
+
};
|
|
2255
|
+
txTypeMappings = {
|
|
2256
|
+
[TX_TYPE.PAY_AUTH]: "Sale",
|
|
2257
|
+
[TX_TYPE.PAY_PRE_AUTH]: "Auth",
|
|
2258
|
+
[TX_TYPE.PAY_POST_AUTH]: "Capture",
|
|
2259
|
+
[TX_TYPE.CANCEL]: "Cancel",
|
|
2260
|
+
[TX_TYPE.REFUND]: "Refund",
|
|
2261
|
+
[TX_TYPE.REFUND_PARTIAL]: "Refund",
|
|
2262
|
+
[TX_TYPE.STATUS]: "OrderInquiry"
|
|
2263
|
+
};
|
|
2264
|
+
langMappings = {
|
|
2265
|
+
[LANG.TR]: "tr-TR",
|
|
2266
|
+
[LANG.EN]: "en-US"
|
|
2267
|
+
};
|
|
2268
|
+
static supports(gatewayClass) {
|
|
2269
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
2270
|
+
}
|
|
2271
|
+
mapCurrency(currency) {
|
|
2272
|
+
return String(super.mapCurrency(currency));
|
|
2273
|
+
}
|
|
2274
|
+
};
|
|
2275
|
+
|
|
2016
2276
|
// src/data-mapper/request/value-mapper/PayFlexV4PosRequestValueMapper.ts
|
|
2017
2277
|
var PayFlexV4PosRequestValueMapper = class extends AbstractRequestValueMapper {
|
|
2018
2278
|
cardTypeMappings = {
|
|
@@ -2049,16 +2309,16 @@ var TX_DECLINED = "declined";
|
|
|
2049
2309
|
|
|
2050
2310
|
// src/data-mapper/response/mapper/AbstractResponseDataMapper.ts
|
|
2051
2311
|
var PHP_TRIM_CHARS = /* @__PURE__ */ new Set([" ", " ", "\n", "\r", "\0", "\v"]);
|
|
2052
|
-
function phpTrim(
|
|
2312
|
+
function phpTrim(value2) {
|
|
2053
2313
|
let start = 0;
|
|
2054
|
-
let end =
|
|
2055
|
-
while (start < end && PHP_TRIM_CHARS.has(
|
|
2056
|
-
while (end > start && PHP_TRIM_CHARS.has(
|
|
2057
|
-
return
|
|
2058
|
-
}
|
|
2059
|
-
function isPlainObject(
|
|
2060
|
-
if (
|
|
2061
|
-
const proto = Object.getPrototypeOf(
|
|
2314
|
+
let end = value2.length;
|
|
2315
|
+
while (start < end && PHP_TRIM_CHARS.has(value2.charAt(start))) start++;
|
|
2316
|
+
while (end > start && PHP_TRIM_CHARS.has(value2.charAt(end - 1))) end--;
|
|
2317
|
+
return value2.slice(start, end);
|
|
2318
|
+
}
|
|
2319
|
+
function isPlainObject(value2) {
|
|
2320
|
+
if (value2 === null || typeof value2 !== "object") return false;
|
|
2321
|
+
const proto = Object.getPrototypeOf(value2);
|
|
2062
2322
|
return proto === Object.prototype || proto === null;
|
|
2063
2323
|
}
|
|
2064
2324
|
var AbstractResponseDataMapper = class {
|
|
@@ -2170,8 +2430,8 @@ var AbstractResponseDataMapper = class {
|
|
|
2170
2430
|
}
|
|
2171
2431
|
if (isPlainObject(data)) {
|
|
2172
2432
|
const result = {};
|
|
2173
|
-
for (const [key,
|
|
2174
|
-
result[key] = this.emptyStringsToNull(
|
|
2433
|
+
for (const [key, value2] of Object.entries(data)) {
|
|
2434
|
+
result[key] = this.emptyStringsToNull(value2);
|
|
2175
2435
|
}
|
|
2176
2436
|
return result;
|
|
2177
2437
|
}
|
|
@@ -2187,21 +2447,21 @@ function field(data, key) {
|
|
|
2187
2447
|
return null;
|
|
2188
2448
|
}
|
|
2189
2449
|
function text2(data, key) {
|
|
2190
|
-
const
|
|
2191
|
-
if (
|
|
2192
|
-
return typeof
|
|
2450
|
+
const value2 = field(data, key);
|
|
2451
|
+
if (value2 === null) return null;
|
|
2452
|
+
return typeof value2 === "string" ? value2 : String(value2);
|
|
2193
2453
|
}
|
|
2194
|
-
function phpInt(
|
|
2195
|
-
if (
|
|
2196
|
-
const n = Number.parseInt(
|
|
2454
|
+
function phpInt(value2) {
|
|
2455
|
+
if (value2 === null) return 0;
|
|
2456
|
+
const n = Number.parseInt(value2.trim(), 10);
|
|
2197
2457
|
return Number.isNaN(n) ? 0 : n;
|
|
2198
2458
|
}
|
|
2199
|
-
function greaterThanZero(
|
|
2200
|
-
const trimmed =
|
|
2459
|
+
function greaterThanZero(value2) {
|
|
2460
|
+
const trimmed = value2.trim();
|
|
2201
2461
|
if (trimmed !== "" && Number.isFinite(Number(trimmed))) {
|
|
2202
2462
|
return Number(trimmed) > 0;
|
|
2203
2463
|
}
|
|
2204
|
-
return
|
|
2464
|
+
return value2 > "0";
|
|
2205
2465
|
}
|
|
2206
2466
|
var AssecoPosResponseDataMapper = class extends AbstractResponseDataMapper {
|
|
2207
2467
|
static supports(gatewayClass) {
|
|
@@ -2539,8 +2799,8 @@ var AssecoPosResponseDataMapper = class extends AbstractResponseDataMapper {
|
|
|
2539
2799
|
mapCurrency(raw, txType) {
|
|
2540
2800
|
return this.valueMapper.mapCurrency(text2(raw, "currency") ?? "", txType);
|
|
2541
2801
|
}
|
|
2542
|
-
formatOptionalDateTime(
|
|
2543
|
-
return
|
|
2802
|
+
formatOptionalDateTime(value2, txType) {
|
|
2803
|
+
return value2 === null ? null : this.valueFormatter.formatDateTime(value2, txType);
|
|
2544
2804
|
}
|
|
2545
2805
|
mapSingleOrderHistoryTransaction(rawTxData) {
|
|
2546
2806
|
const txType = TX_TYPE.ORDER_HISTORY;
|
|
@@ -2600,23 +2860,180 @@ var AssecoPosResponseDataMapper = class extends AbstractResponseDataMapper {
|
|
|
2600
2860
|
}
|
|
2601
2861
|
};
|
|
2602
2862
|
|
|
2863
|
+
// src/data-mapper/response/mapper/PayFlexCPV4PosResponseDataMapper.ts
|
|
2864
|
+
function field2(data, key) {
|
|
2865
|
+
if (data !== null && typeof data === "object" && !Array.isArray(data) && Object.hasOwn(data, key)) {
|
|
2866
|
+
return data[key] ?? null;
|
|
2867
|
+
}
|
|
2868
|
+
return null;
|
|
2869
|
+
}
|
|
2870
|
+
function text3(data, key) {
|
|
2871
|
+
const value2 = field2(data, key);
|
|
2872
|
+
if (value2 === null) return null;
|
|
2873
|
+
return typeof value2 === "string" ? value2 : String(value2);
|
|
2874
|
+
}
|
|
2875
|
+
function firstText(data, ...keys) {
|
|
2876
|
+
for (const key of keys) {
|
|
2877
|
+
const value2 = text3(data, key);
|
|
2878
|
+
if (value2 !== null) return value2;
|
|
2879
|
+
}
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2882
|
+
function normalizeAmount(value2) {
|
|
2883
|
+
if (typeof value2 === "string" && /^\d+,\d{1,2}$/.test(value2)) {
|
|
2884
|
+
return value2.replace(",", ".");
|
|
2885
|
+
}
|
|
2886
|
+
return value2;
|
|
2887
|
+
}
|
|
2888
|
+
var PayFlexCPV4PosResponseDataMapper = class _PayFlexCPV4PosResponseDataMapper extends AbstractResponseDataMapper {
|
|
2889
|
+
static PROCEDURE_SUCCESS_CODE = "0000";
|
|
2890
|
+
static supports(gatewayClass) {
|
|
2891
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
2892
|
+
}
|
|
2893
|
+
map3DPaymentData(_raw3DAuthResponseData, _rawPaymentResponseData, _txType, _order) {
|
|
2894
|
+
throw new NotImplementedError("Common Payment has no separate 3D payment step");
|
|
2895
|
+
}
|
|
2896
|
+
map3DPayResponseData(raw3DAuthResponseData, txType, _order) {
|
|
2897
|
+
const raw = this.emptyStringsToNull(raw3DAuthResponseData);
|
|
2898
|
+
const response = this.getCommonPaymentResponse(raw, txType, MODEL.THREE_D_PAY);
|
|
2899
|
+
response.md_status = null;
|
|
2900
|
+
response.md_error_message = null;
|
|
2901
|
+
response.transaction_security = null;
|
|
2902
|
+
response.transaction_id = field2(raw, "TransactionId");
|
|
2903
|
+
response.masked_number = field2(raw, "MaskedPan");
|
|
2904
|
+
if (response.status === TX_APPROVED) {
|
|
2905
|
+
const amount = normalizeAmount(field2(raw, "Amount"));
|
|
2906
|
+
const bankTxType = text3(raw, "TransactionType");
|
|
2907
|
+
const amountCode = text3(raw, "AmountCode");
|
|
2908
|
+
const hostDate = text3(raw, "HostDate");
|
|
2909
|
+
response.auth_code = firstText(raw, "AuthCode", "AuthorizeId");
|
|
2910
|
+
response.ref_ret_num = field2(raw, "TransactionId");
|
|
2911
|
+
response.order_id = firstText(raw, "OrderID", "OrderId");
|
|
2912
|
+
response.currency = amountCode !== null ? this.valueMapper.mapCurrency(amountCode, txType) : null;
|
|
2913
|
+
response.amount = this.formatAmount(amount, txType);
|
|
2914
|
+
response.transaction_type = bankTxType !== null ? this.valueMapper.mapTxType(bankTxType) : null;
|
|
2915
|
+
response.installment_count = this.valueFormatter.formatInstallment(text3(raw, "InstallmentCount"), txType);
|
|
2916
|
+
response.transaction_time = this.formatHostDate(hostDate, txType);
|
|
2917
|
+
}
|
|
2918
|
+
return response;
|
|
2919
|
+
}
|
|
2920
|
+
map3DHostResponseData(raw3DAuthResponseData, txType, order) {
|
|
2921
|
+
const response = this.map3DPayResponseData(raw3DAuthResponseData, txType, order);
|
|
2922
|
+
response.payment_model = MODEL.THREE_D_HOST;
|
|
2923
|
+
return response;
|
|
2924
|
+
}
|
|
2925
|
+
mapRefundResponse(_rawResponseData) {
|
|
2926
|
+
throw new NotImplementedError("Refund is not supported by Common Payment");
|
|
2927
|
+
}
|
|
2928
|
+
mapCancelResponse(_rawResponseData) {
|
|
2929
|
+
throw new NotImplementedError("Cancel is not supported by Common Payment");
|
|
2930
|
+
}
|
|
2931
|
+
/** Maps the transaction query answer (VakifBank Common Payment guide v2.1 §6.5). */
|
|
2932
|
+
mapStatusResponse(rawResponseData) {
|
|
2933
|
+
const txType = TX_TYPE.STATUS;
|
|
2934
|
+
const raw = this.emptyStringsToNull(rawResponseData);
|
|
2935
|
+
const response = this.getDefaultStatusResponse(raw);
|
|
2936
|
+
const { status, procCode, errorMessage } = this.resolveOutcome(raw);
|
|
2937
|
+
response.status = status;
|
|
2938
|
+
response.proc_return_code = procCode;
|
|
2939
|
+
response.error_code = status === TX_DECLINED ? procCode : null;
|
|
2940
|
+
response.error_message = errorMessage;
|
|
2941
|
+
if (status === TX_APPROVED) {
|
|
2942
|
+
const amount = normalizeAmount(field2(raw, "Amount"));
|
|
2943
|
+
const bankTxType = text3(raw, "TransactionType");
|
|
2944
|
+
const amountCode = text3(raw, "AmountCode");
|
|
2945
|
+
const hostDate = text3(raw, "HostDate");
|
|
2946
|
+
response.order_id = firstText(raw, "OrderID", "OrderId");
|
|
2947
|
+
response.auth_code = firstText(raw, "AuthCode", "AuthorizeId");
|
|
2948
|
+
response.transaction_id = field2(raw, "TransactionId");
|
|
2949
|
+
response.ref_ret_num = field2(raw, "Rrn");
|
|
2950
|
+
response.transaction_time = this.formatHostDate(hostDate, txType);
|
|
2951
|
+
response.transaction_type = bankTxType !== null ? this.valueMapper.mapTxType(bankTxType) : null;
|
|
2952
|
+
response.first_amount = this.formatAmount(amount, txType);
|
|
2953
|
+
response.currency = amountCode !== null ? this.valueMapper.mapCurrency(amountCode, txType) : null;
|
|
2954
|
+
response.masked_number = field2(raw, "MaskedPan");
|
|
2955
|
+
response.installment_count = this.valueFormatter.formatInstallment(text3(raw, "InstallmentCount"), txType);
|
|
2956
|
+
}
|
|
2957
|
+
return response;
|
|
2958
|
+
}
|
|
2959
|
+
mapPaymentResponse(_rawPaymentResponseData, _txType, _order) {
|
|
2960
|
+
throw new NotImplementedError("Common Payment has no direct payment API");
|
|
2961
|
+
}
|
|
2962
|
+
mapOrderHistoryResponse(_rawResponseData) {
|
|
2963
|
+
throw new NotImplementedError("Order history is not supported by Common Payment");
|
|
2964
|
+
}
|
|
2965
|
+
is3dAuthSuccess(_mdStatus) {
|
|
2966
|
+
return true;
|
|
2967
|
+
}
|
|
2968
|
+
extractMdStatus(_raw3DAuthResponseData) {
|
|
2969
|
+
return null;
|
|
2970
|
+
}
|
|
2971
|
+
getProcReturnCode(response) {
|
|
2972
|
+
return firstText(response, "Rc", "ResultCode");
|
|
2973
|
+
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Only a string or number amount is formatted; anything else maps to null. The gateway binds the raw answer
|
|
2976
|
+
* amount, so a malformed value fails the binding instead of throwing here.
|
|
2977
|
+
*/
|
|
2978
|
+
formatAmount(amount, txType) {
|
|
2979
|
+
return typeof amount === "string" || typeof amount === "number" ? this.valueFormatter.formatAmount(amount, txType) : null;
|
|
2980
|
+
}
|
|
2981
|
+
/** `HostDate` is informational: an unknown format gives null and a warning instead of failing the mapping. */
|
|
2982
|
+
formatHostDate(hostDate, txType) {
|
|
2983
|
+
if (hostDate === null) return null;
|
|
2984
|
+
try {
|
|
2985
|
+
return this.valueFormatter.formatDateTime(hostDate, txType);
|
|
2986
|
+
} catch (e) {
|
|
2987
|
+
if (!(e instanceof PosError)) throw e;
|
|
2988
|
+
this.logger.warn("unrecognized HostDate format in the transaction query answer", { HostDate: hostDate });
|
|
2989
|
+
return null;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
/** Status, procedure code and message shared by the callback and query mappings. */
|
|
2993
|
+
resolveOutcome(raw) {
|
|
2994
|
+
const errorCode = text3(raw, "ErrorCode");
|
|
2995
|
+
if (errorCode !== null) {
|
|
2996
|
+
return {
|
|
2997
|
+
status: TX_DECLINED,
|
|
2998
|
+
procCode: errorCode,
|
|
2999
|
+
errorMessage: firstText(raw, "Message", "ResultDescription", "ResponseMessage")
|
|
3000
|
+
};
|
|
3001
|
+
}
|
|
3002
|
+
const procCode = this.getProcReturnCode(raw);
|
|
3003
|
+
if (procCode === _PayFlexCPV4PosResponseDataMapper.PROCEDURE_SUCCESS_CODE) {
|
|
3004
|
+
return { status: TX_APPROVED, procCode, errorMessage: null };
|
|
3005
|
+
}
|
|
3006
|
+
return { status: TX_DECLINED, procCode, errorMessage: firstText(raw, "Message", "ResultDescription") };
|
|
3007
|
+
}
|
|
3008
|
+
getCommonPaymentResponse(raw, txType, paymentModel) {
|
|
3009
|
+
const { status, procCode, errorMessage } = this.resolveOutcome(raw);
|
|
3010
|
+
const response = this.getDefaultPaymentResponse(txType, paymentModel);
|
|
3011
|
+
response.proc_return_code = procCode;
|
|
3012
|
+
response.status = status;
|
|
3013
|
+
response.error_code = status === TX_DECLINED ? procCode : null;
|
|
3014
|
+
response.error_message = errorMessage;
|
|
3015
|
+
response.all = raw;
|
|
3016
|
+
return response;
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
3019
|
+
|
|
2603
3020
|
// src/data-mapper/response/mapper/PayFlexV4PosResponseDataMapper.ts
|
|
2604
3021
|
var FULL_3D_ECI = /* @__PURE__ */ new Set(["02", "05"]);
|
|
2605
3022
|
var BANK_TIME_OFFSET_MS = 3 * 60 * 60 * 1e3;
|
|
2606
|
-
function
|
|
3023
|
+
function field3(data, key) {
|
|
2607
3024
|
if (data !== null && typeof data === "object" && !Array.isArray(data) && Object.hasOwn(data, key)) {
|
|
2608
3025
|
return data[key] ?? null;
|
|
2609
3026
|
}
|
|
2610
3027
|
return null;
|
|
2611
3028
|
}
|
|
2612
|
-
function
|
|
2613
|
-
const
|
|
2614
|
-
if (
|
|
2615
|
-
return typeof
|
|
3029
|
+
function text4(data, key) {
|
|
3030
|
+
const value2 = field3(data, key);
|
|
3031
|
+
if (value2 === null) return null;
|
|
3032
|
+
return typeof value2 === "string" ? value2 : String(value2);
|
|
2616
3033
|
}
|
|
2617
3034
|
function record(data, key) {
|
|
2618
|
-
const
|
|
2619
|
-
return
|
|
3035
|
+
const value2 = field3(data, key);
|
|
3036
|
+
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2) ? value2 : {};
|
|
2620
3037
|
}
|
|
2621
3038
|
var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper extends AbstractResponseDataMapper {
|
|
2622
3039
|
static PROCEDURE_SUCCESS_CODE = "0000";
|
|
@@ -2634,19 +3051,19 @@ var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper exten
|
|
|
2634
3051
|
const threeDAuthStatus = authSuccess ? TX_APPROVED : TX_DECLINED;
|
|
2635
3052
|
const declined = threeDAuthStatus === TX_DECLINED;
|
|
2636
3053
|
const paymentResponseData = authSuccess && rawPaymentResponseData !== null ? this.mapPaymentResponse(rawPaymentResponseData, txType, order) : this.getDefaultPaymentResponse(txType, null);
|
|
2637
|
-
const purchCurrency =
|
|
3054
|
+
const purchCurrency = text4(raw, "PurchCurrency");
|
|
2638
3055
|
const threeDResponse = {
|
|
2639
|
-
eci:
|
|
2640
|
-
cavv:
|
|
3056
|
+
eci: field3(raw, "Eci"),
|
|
3057
|
+
cavv: field3(raw, "Cavv"),
|
|
2641
3058
|
auth_code: null,
|
|
2642
|
-
order_id:
|
|
3059
|
+
order_id: field3(raw, "VerifyEnrollmentRequestId"),
|
|
2643
3060
|
status: threeDAuthStatus,
|
|
2644
3061
|
currency: paymentResponseData.currency ?? (purchCurrency !== null ? this.valueMapper.mapCurrency(purchCurrency, txType) : null),
|
|
2645
|
-
installment_count: paymentResponseData.installment_count ?? this.valueFormatter.formatInstallment(
|
|
2646
|
-
error_code: declined ?
|
|
2647
|
-
error_message: declined ?
|
|
3062
|
+
installment_count: paymentResponseData.installment_count ?? this.valueFormatter.formatInstallment(text4(raw, "InstallmentCount"), txType),
|
|
3063
|
+
error_code: declined ? field3(raw, "ErrorCode") : null,
|
|
3064
|
+
error_message: declined ? field3(raw, "ErrorMessage") : null,
|
|
2648
3065
|
md_status: mdStatus,
|
|
2649
|
-
md_error_message: declined ?
|
|
3066
|
+
md_error_message: declined ? field3(raw, "ErrorMessage") : null,
|
|
2650
3067
|
transaction_security: null,
|
|
2651
3068
|
all: rawPaymentResponseData,
|
|
2652
3069
|
"3d_all": raw
|
|
@@ -2668,13 +3085,13 @@ var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper exten
|
|
|
2668
3085
|
const status = resultCode === _PayFlexV4PosResponseDataMapper.PROCEDURE_SUCCESS_CODE ? TX_APPROVED : TX_DECLINED;
|
|
2669
3086
|
const declined = status === TX_DECLINED;
|
|
2670
3087
|
return {
|
|
2671
|
-
order_id:
|
|
2672
|
-
auth_code: declined ? null :
|
|
2673
|
-
ref_ret_num:
|
|
3088
|
+
order_id: field3(raw, "TransactionId"),
|
|
3089
|
+
auth_code: declined ? null : field3(raw, "AuthCode"),
|
|
3090
|
+
ref_ret_num: field3(raw, "Rrn"),
|
|
2674
3091
|
proc_return_code: resultCode,
|
|
2675
|
-
transaction_id:
|
|
3092
|
+
transaction_id: field3(raw, "TransactionId"),
|
|
2676
3093
|
error_code: declined ? resultCode : null,
|
|
2677
|
-
error_message: declined ?
|
|
3094
|
+
error_message: declined ? field3(raw, "ResultDetail") : null,
|
|
2678
3095
|
status,
|
|
2679
3096
|
all: raw
|
|
2680
3097
|
};
|
|
@@ -2683,65 +3100,65 @@ var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper exten
|
|
|
2683
3100
|
const txType = TX_TYPE.STATUS;
|
|
2684
3101
|
const raw = this.emptyStringsToNull(rawResponseData);
|
|
2685
3102
|
const responseInfo = record(raw, "ResponseInfo");
|
|
2686
|
-
const procReturnCode =
|
|
3103
|
+
const procReturnCode = text4(responseInfo, "ResponseCode");
|
|
2687
3104
|
const defaultResponse = this.getDefaultStatusResponse(raw);
|
|
2688
3105
|
defaultResponse.proc_return_code = procReturnCode;
|
|
2689
3106
|
const status = procReturnCode === _PayFlexV4PosResponseDataMapper.PROCEDURE_SUCCESS_CODE ? TX_APPROVED : TX_DECLINED;
|
|
2690
3107
|
defaultResponse.status = status;
|
|
2691
3108
|
if (status === TX_DECLINED) {
|
|
2692
3109
|
defaultResponse.error_code = procReturnCode;
|
|
2693
|
-
defaultResponse.error_message =
|
|
3110
|
+
defaultResponse.error_message = text4(responseInfo, "ResponseMessage");
|
|
2694
3111
|
return defaultResponse;
|
|
2695
3112
|
}
|
|
2696
3113
|
const txResultInfo = record(record(raw, "TransactionSearchResultInfo"), "TransactionSearchResultInfo");
|
|
2697
3114
|
const orderProcCode = this.getProcReturnCode(txResultInfo);
|
|
2698
3115
|
let orderStatus = PAYMENT_STATUS.PAYMENT_COMPLETED;
|
|
2699
|
-
if (
|
|
3116
|
+
if (field3(txResultInfo, "IsCanceled") === "true") {
|
|
2700
3117
|
orderStatus = PAYMENT_STATUS.CANCELED;
|
|
2701
|
-
} else if (
|
|
3118
|
+
} else if (field3(txResultInfo, "IsReversed") === "true") {
|
|
2702
3119
|
orderStatus = "REVERSED";
|
|
2703
|
-
} else if (
|
|
3120
|
+
} else if (field3(txResultInfo, "IsRefunded") === "true") {
|
|
2704
3121
|
orderStatus = PAYMENT_STATUS.FULLY_REFUNDED;
|
|
2705
3122
|
}
|
|
2706
3123
|
const orderApproved = orderProcCode === _PayFlexV4PosResponseDataMapper.PROCEDURE_SUCCESS_CODE;
|
|
2707
|
-
const bankTxType =
|
|
2708
|
-
const amountCode =
|
|
2709
|
-
const amount =
|
|
2710
|
-
defaultResponse.order_id =
|
|
2711
|
-
defaultResponse.auth_code =
|
|
2712
|
-
defaultResponse.transaction_id =
|
|
2713
|
-
defaultResponse.ref_ret_num =
|
|
3124
|
+
const bankTxType = text4(txResultInfo, "TransactionType");
|
|
3125
|
+
const amountCode = text4(txResultInfo, "AmountCode");
|
|
3126
|
+
const amount = text4(txResultInfo, "CurrencyAmount") ?? text4(txResultInfo, "Amount");
|
|
3127
|
+
defaultResponse.order_id = text4(txResultInfo, "OrderId");
|
|
3128
|
+
defaultResponse.auth_code = field3(txResultInfo, "AuthCode");
|
|
3129
|
+
defaultResponse.transaction_id = field3(txResultInfo, "TransactionId");
|
|
3130
|
+
defaultResponse.ref_ret_num = field3(txResultInfo, "Rrn");
|
|
2714
3131
|
defaultResponse.order_status = orderStatus;
|
|
2715
3132
|
defaultResponse.transaction_type = bankTxType !== null ? this.valueMapper.mapTxType(bankTxType) : null;
|
|
2716
3133
|
defaultResponse.currency = amountCode !== null ? this.valueMapper.mapCurrency(amountCode, txType) : null;
|
|
2717
3134
|
defaultResponse.first_amount = amount !== null ? this.valueFormatter.formatAmount(amount, txType) : null;
|
|
2718
3135
|
defaultResponse.capture_amount = null;
|
|
2719
3136
|
defaultResponse.status = orderApproved ? TX_APPROVED : TX_DECLINED;
|
|
2720
|
-
defaultResponse.error_code = orderApproved ? null :
|
|
2721
|
-
defaultResponse.error_message = orderApproved ? null :
|
|
3137
|
+
defaultResponse.error_code = orderApproved ? null : text4(txResultInfo, "HostResultCode");
|
|
3138
|
+
defaultResponse.error_message = orderApproved ? null : text4(txResultInfo, "ResponseMessage");
|
|
2722
3139
|
return defaultResponse;
|
|
2723
3140
|
}
|
|
2724
3141
|
mapPaymentResponse(rawPaymentResponseData, txType, _order) {
|
|
2725
3142
|
this.logger.debug("mapping payment response", [rawPaymentResponseData]);
|
|
2726
3143
|
const raw = this.emptyStringsToNull(rawPaymentResponseData);
|
|
2727
3144
|
const commonResponse = this.getCommonPaymentResponse(raw, txType);
|
|
2728
|
-
const currencyCode =
|
|
2729
|
-
const tlAmount =
|
|
2730
|
-
const bankTxType =
|
|
2731
|
-
commonResponse.order_id =
|
|
3145
|
+
const currencyCode = text4(raw, "CurrencyCode");
|
|
3146
|
+
const tlAmount = field3(raw, "TLAmount");
|
|
3147
|
+
const bankTxType = text4(raw, "TransactionType");
|
|
3148
|
+
commonResponse.order_id = text4(raw, "OrderId");
|
|
2732
3149
|
commonResponse.currency = currencyCode !== null ? this.valueMapper.mapCurrency(currencyCode, txType) : null;
|
|
2733
3150
|
commonResponse.amount = tlAmount !== null ? this.valueFormatter.formatAmount(tlAmount, txType) : null;
|
|
2734
3151
|
commonResponse.transaction_type = bankTxType !== null ? this.valueMapper.mapTxType(bankTxType) : null;
|
|
2735
3152
|
if (commonResponse.status === TX_APPROVED) {
|
|
2736
|
-
let txTime =
|
|
3153
|
+
let txTime = text4(raw, "HostDate");
|
|
2737
3154
|
if (txTime !== null && txTime.length === 10) {
|
|
2738
3155
|
txTime = `${new Date(Date.now() + BANK_TIME_OFFSET_MS).getUTCFullYear()}${txTime}`;
|
|
2739
3156
|
}
|
|
2740
|
-
commonResponse.transaction_id =
|
|
3157
|
+
commonResponse.transaction_id = field3(raw, "TransactionId");
|
|
2741
3158
|
commonResponse.transaction_time = txTime !== null ? this.valueFormatter.formatDateTime(txTime, txType) : null;
|
|
2742
|
-
commonResponse.auth_code =
|
|
2743
|
-
commonResponse.ref_ret_num =
|
|
2744
|
-
commonResponse.batch_num =
|
|
3159
|
+
commonResponse.auth_code = field3(raw, "AuthCode");
|
|
3160
|
+
commonResponse.ref_ret_num = field3(raw, "TransactionId");
|
|
3161
|
+
commonResponse.batch_num = field3(raw, "BatchNo");
|
|
2745
3162
|
}
|
|
2746
3163
|
this.logger.debug("mapped payment response", commonResponse);
|
|
2747
3164
|
return commonResponse;
|
|
@@ -2759,30 +3176,30 @@ var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper exten
|
|
|
2759
3176
|
if (mdStatus !== "Y" || raw3DAuthResponseData === null || typeof raw3DAuthResponseData !== "object") {
|
|
2760
3177
|
return false;
|
|
2761
3178
|
}
|
|
2762
|
-
const
|
|
2763
|
-
const status =
|
|
2764
|
-
const eci =
|
|
2765
|
-
const cavv =
|
|
2766
|
-
const md =
|
|
3179
|
+
const own2 = (key) => Object.hasOwn(raw3DAuthResponseData, key) ? raw3DAuthResponseData[key] : void 0;
|
|
3180
|
+
const status = own2("Status");
|
|
3181
|
+
const eci = own2("Eci");
|
|
3182
|
+
const cavv = own2("Cavv");
|
|
3183
|
+
const md = own2("MdStatus");
|
|
2767
3184
|
return status === "Y" && typeof eci === "string" && FULL_3D_ECI.has(eci) && typeof cavv === "string" && cavv.trim() !== "" && (md === void 0 || md === null || md === "" || md === "1");
|
|
2768
3185
|
}
|
|
2769
3186
|
/** The enrollment / authentication `Status` (Y, A, N, U, E). */
|
|
2770
3187
|
extractMdStatus(raw3DAuthResponseData) {
|
|
2771
|
-
return
|
|
3188
|
+
return text4(raw3DAuthResponseData, "Status");
|
|
2772
3189
|
}
|
|
2773
3190
|
getProcReturnCode(response) {
|
|
2774
|
-
return
|
|
3191
|
+
return text4(response, "ResultCode");
|
|
2775
3192
|
}
|
|
2776
3193
|
getCommonPaymentResponse(responseData, txType) {
|
|
2777
3194
|
const resultCode = this.getProcReturnCode(responseData);
|
|
2778
3195
|
const status = resultCode === _PayFlexV4PosResponseDataMapper.PROCEDURE_SUCCESS_CODE ? TX_APPROVED : TX_DECLINED;
|
|
2779
|
-
const secureType =
|
|
3196
|
+
const secureType = text4(responseData, "ThreeDSecureType");
|
|
2780
3197
|
const paymentModel = secureType !== null ? this.valueMapper.mapSecureType(secureType, txType) : null;
|
|
2781
3198
|
const response = this.getDefaultPaymentResponse(txType, paymentModel);
|
|
2782
3199
|
response.proc_return_code = resultCode;
|
|
2783
3200
|
response.status = status;
|
|
2784
3201
|
response.error_code = status === TX_DECLINED ? resultCode : null;
|
|
2785
|
-
response.error_message = status === TX_DECLINED ?
|
|
3202
|
+
response.error_message = status === TX_DECLINED ? text4(responseData, "ResultDetail") : null;
|
|
2786
3203
|
response.all = responseData;
|
|
2787
3204
|
return response;
|
|
2788
3205
|
}
|
|
@@ -2790,18 +3207,18 @@ var PayFlexV4PosResponseDataMapper = class _PayFlexV4PosResponseDataMapper exten
|
|
|
2790
3207
|
|
|
2791
3208
|
// src/data-mapper/response/value-formatter/AbstractResponseValueFormatter.ts
|
|
2792
3209
|
var PHP_NUMERIC = /^[ \t\n\r\v\f]*[+-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?[ \t\n\r\v\f]*$/;
|
|
2793
|
-
function phpInt2(
|
|
2794
|
-
if (
|
|
2795
|
-
if (PHP_NUMERIC.test(
|
|
2796
|
-
const n2 = Math.trunc(Number(
|
|
3210
|
+
function phpInt2(value2) {
|
|
3211
|
+
if (value2 === null || value2 === void 0) return 0;
|
|
3212
|
+
if (PHP_NUMERIC.test(value2)) {
|
|
3213
|
+
const n2 = Math.trunc(Number(value2));
|
|
2797
3214
|
return Number.isFinite(n2) ? n2 : 0;
|
|
2798
3215
|
}
|
|
2799
|
-
const n = Number.parseInt(
|
|
3216
|
+
const n = Number.parseInt(value2.replace(/^[ \t\n\r\v\f]+/, ""), 10);
|
|
2800
3217
|
return Number.isNaN(n) ? 0 : n;
|
|
2801
3218
|
}
|
|
2802
|
-
function phpFloat(
|
|
2803
|
-
if (typeof
|
|
2804
|
-
const n = Number.parseFloat(
|
|
3219
|
+
function phpFloat(value2) {
|
|
3220
|
+
if (typeof value2 === "number") return value2;
|
|
3221
|
+
const n = Number.parseFloat(value2.replace(/^[ \t\n\r\v\f]+/, ""));
|
|
2805
3222
|
return Number.isFinite(n) ? n : 0;
|
|
2806
3223
|
}
|
|
2807
3224
|
var BANK_TIMEZONE_OFFSET_MINUTES = 180;
|
|
@@ -2817,16 +3234,16 @@ function parseOffset(offset) {
|
|
|
2817
3234
|
return sign * (Number(digits.slice(0, 2)) * 60 + Number(digits.slice(2)));
|
|
2818
3235
|
}
|
|
2819
3236
|
function parseDateTime(input) {
|
|
2820
|
-
const
|
|
2821
|
-
if (
|
|
3237
|
+
const value2 = input.trim();
|
|
3238
|
+
if (value2.toLowerCase() === "now") {
|
|
2822
3239
|
return /* @__PURE__ */ new Date();
|
|
2823
3240
|
}
|
|
2824
3241
|
let parts = null;
|
|
2825
|
-
const iso = ISO_LIKE.exec(
|
|
3242
|
+
const iso = ISO_LIKE.exec(value2);
|
|
2826
3243
|
if (iso) {
|
|
2827
3244
|
parts = [iso[1], iso[2], iso[3], iso[4], iso[5], iso[6], iso[7], iso[8]];
|
|
2828
3245
|
} else {
|
|
2829
|
-
const dotted = DOTTED.exec(
|
|
3246
|
+
const dotted = DOTTED.exec(value2);
|
|
2830
3247
|
if (dotted) {
|
|
2831
3248
|
parts = [dotted[3], dotted[2], dotted[1], dotted[4], dotted[5], dotted[6]];
|
|
2832
3249
|
}
|
|
@@ -2864,11 +3281,11 @@ var AssecoPosResponseValueFormatter = class extends AbstractResponseValueFormatt
|
|
|
2864
3281
|
}
|
|
2865
3282
|
/** Status and order history responses return amounts in minor units (`1001` -> 10.01). */
|
|
2866
3283
|
formatAmount(amount, txType) {
|
|
2867
|
-
const
|
|
3284
|
+
const value2 = super.formatAmount(amount, txType);
|
|
2868
3285
|
if (txType === TX_TYPE.STATUS || txType === TX_TYPE.ORDER_HISTORY) {
|
|
2869
|
-
return
|
|
3286
|
+
return value2 / 100;
|
|
2870
3287
|
}
|
|
2871
|
-
return
|
|
3288
|
+
return value2;
|
|
2872
3289
|
}
|
|
2873
3290
|
};
|
|
2874
3291
|
|
|
@@ -2881,9 +3298,9 @@ var BasicResponseValueFormatter = class extends AbstractResponseValueFormatter {
|
|
|
2881
3298
|
};
|
|
2882
3299
|
|
|
2883
3300
|
// src/data-mapper/response/value-mapper/AbstractResponseValueMapper.ts
|
|
2884
|
-
function phpKey(
|
|
2885
|
-
if (typeof
|
|
2886
|
-
return String(
|
|
3301
|
+
function phpKey(value2) {
|
|
3302
|
+
if (typeof value2 === "boolean") return value2 ? "1" : "0";
|
|
3303
|
+
return String(value2);
|
|
2887
3304
|
}
|
|
2888
3305
|
var AbstractResponseValueMapper = class {
|
|
2889
3306
|
/** Bank currency code -> CURRENCY value. */
|
|
@@ -2980,6 +3397,30 @@ var AssecoPosResponseValueMapper = class extends AbstractResponseValueMapper {
|
|
|
2980
3397
|
}
|
|
2981
3398
|
};
|
|
2982
3399
|
|
|
3400
|
+
// src/data-mapper/response/value-mapper/PayFlexCPV4PosResponseValueMapper.ts
|
|
3401
|
+
var PayFlexCPV4PosResponseValueMapper = class extends AbstractResponseValueMapper {
|
|
3402
|
+
currencyMappings = {
|
|
3403
|
+
"949": CURRENCY.TRY,
|
|
3404
|
+
"840": CURRENCY.USD,
|
|
3405
|
+
"978": CURRENCY.EUR,
|
|
3406
|
+
"826": CURRENCY.GBP,
|
|
3407
|
+
"392": CURRENCY.JPY,
|
|
3408
|
+
"643": CURRENCY.RUB
|
|
3409
|
+
};
|
|
3410
|
+
txTypeMappings = {
|
|
3411
|
+
[TX_TYPE.PAY_AUTH]: "Sale",
|
|
3412
|
+
[TX_TYPE.PAY_PRE_AUTH]: "Auth",
|
|
3413
|
+
[TX_TYPE.PAY_POST_AUTH]: "Capture",
|
|
3414
|
+
[TX_TYPE.CANCEL]: "Cancel",
|
|
3415
|
+
[TX_TYPE.REFUND]: "Refund",
|
|
3416
|
+
[TX_TYPE.REFUND_PARTIAL]: "Refund",
|
|
3417
|
+
[TX_TYPE.STATUS]: "OrderInquiry"
|
|
3418
|
+
};
|
|
3419
|
+
static supports(gatewayClass) {
|
|
3420
|
+
return gatewayClass === "PayFlexCPV4Pos";
|
|
3421
|
+
}
|
|
3422
|
+
};
|
|
3423
|
+
|
|
2983
3424
|
// src/data-mapper/response/value-mapper/PayFlexV4PosResponseValueMapper.ts
|
|
2984
3425
|
var PayFlexV4PosResponseValueMapper = class extends AbstractResponseValueMapper {
|
|
2985
3426
|
currencyMappings = {
|
|
@@ -3486,43 +3927,331 @@ var AssecoPos = class extends AbstractGateway {
|
|
|
3486
3927
|
}
|
|
3487
3928
|
}
|
|
3488
3929
|
};
|
|
3489
|
-
function parseAmount(
|
|
3490
|
-
if (typeof
|
|
3491
|
-
return Number.isFinite(
|
|
3930
|
+
function parseAmount(value2) {
|
|
3931
|
+
if (typeof value2 === "number") {
|
|
3932
|
+
return Number.isFinite(value2) ? value2 : Number.NaN;
|
|
3492
3933
|
}
|
|
3493
|
-
return typeof
|
|
3934
|
+
return typeof value2 === "string" && DECIMAL.test(value2) ? Number(value2) : Number.NaN;
|
|
3494
3935
|
}
|
|
3495
|
-
function asText(
|
|
3496
|
-
return
|
|
3936
|
+
function asText(value2) {
|
|
3937
|
+
return value2 === null || value2 === void 0 ? "" : String(value2);
|
|
3497
3938
|
}
|
|
3498
3939
|
|
|
3940
|
+
// src/gateway/PayFlexCPV4Pos.ts
|
|
3941
|
+
var SUCCESS_CODE = "0000";
|
|
3942
|
+
var ANSWER_AMOUNT = /^(\d+)(?:[.,](\d{1,2}))?$/;
|
|
3943
|
+
var NO_IDS_MESSAGE = "Callback carries no TransactionId or PaymentToken; the result cannot be confirmed with the bank.";
|
|
3944
|
+
var DECIMAL2 = /^\s*[+-]?(\d+(\.\d*)?|\.\d+)\s*$/;
|
|
3945
|
+
var ALTERNATIVE = 'use a PayFlexV4Pos gateway (bank "vakifbank") with transaction_id = the common payment TransactionId';
|
|
3946
|
+
function own(data, key) {
|
|
3947
|
+
return Object.hasOwn(data, key) ? data[key] : void 0;
|
|
3948
|
+
}
|
|
3949
|
+
function value(data, key) {
|
|
3950
|
+
return own(data, key) ?? void 0;
|
|
3951
|
+
}
|
|
3952
|
+
function asText2(v) {
|
|
3953
|
+
return v === null || v === void 0 ? "" : String(v);
|
|
3954
|
+
}
|
|
3955
|
+
function nonEmpty(data, key) {
|
|
3956
|
+
const v = value(data, key);
|
|
3957
|
+
if (v === void 0) return null;
|
|
3958
|
+
const s = String(v);
|
|
3959
|
+
return s === "" ? null : s;
|
|
3960
|
+
}
|
|
3961
|
+
function firstNonEmptyString(data, ...keys) {
|
|
3962
|
+
for (const key of keys) {
|
|
3963
|
+
const v = value(data, key);
|
|
3964
|
+
if (typeof v === "string" && v !== "") return v;
|
|
3965
|
+
}
|
|
3966
|
+
return null;
|
|
3967
|
+
}
|
|
3968
|
+
function nonEmptyString(v) {
|
|
3969
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
3970
|
+
}
|
|
3971
|
+
function answerCents(v) {
|
|
3972
|
+
if (typeof v !== "string" && !(typeof v === "number" && Number.isFinite(v))) return null;
|
|
3973
|
+
const match = ANSWER_AMOUNT.exec(String(v));
|
|
3974
|
+
if (match === null) return null;
|
|
3975
|
+
return BigInt(match[1]) * 100n + BigInt((match[2] ?? "").padEnd(2, "0"));
|
|
3976
|
+
}
|
|
3977
|
+
function orderCents(v) {
|
|
3978
|
+
let amount;
|
|
3979
|
+
if (typeof v === "number") {
|
|
3980
|
+
amount = v;
|
|
3981
|
+
} else if (typeof v === "string" && DECIMAL2.test(v)) {
|
|
3982
|
+
amount = Number(v);
|
|
3983
|
+
} else {
|
|
3984
|
+
return null;
|
|
3985
|
+
}
|
|
3986
|
+
try {
|
|
3987
|
+
return BigInt(numberFormat2(amount).replace(".", ""));
|
|
3988
|
+
} catch (e) {
|
|
3989
|
+
if (e instanceof PosError) return null;
|
|
3990
|
+
throw e;
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
var PayFlexCPV4Pos = class extends AbstractGateway {
|
|
3994
|
+
static NAME = "PayFlex-Common-Payment-V4";
|
|
3995
|
+
static GATEWAY_CLASS = "PayFlexCPV4Pos";
|
|
3996
|
+
static supportedTransactions = {
|
|
3997
|
+
[TX_TYPE.PAY_AUTH]: [MODEL.THREE_D_PAY, MODEL.THREE_D_HOST],
|
|
3998
|
+
[TX_TYPE.PAY_PRE_AUTH]: [MODEL.THREE_D_PAY, MODEL.THREE_D_HOST],
|
|
3999
|
+
[TX_TYPE.PAY_POST_AUTH]: false,
|
|
4000
|
+
[TX_TYPE.STATUS]: true,
|
|
4001
|
+
[TX_TYPE.CANCEL]: false,
|
|
4002
|
+
[TX_TYPE.REFUND]: false,
|
|
4003
|
+
[TX_TYPE.REFUND_PARTIAL]: false,
|
|
4004
|
+
[TX_TYPE.ORDER_HISTORY]: false
|
|
4005
|
+
};
|
|
4006
|
+
cpRequestDataMapper;
|
|
4007
|
+
constructor(config, account, deps) {
|
|
4008
|
+
super(config, account, deps);
|
|
4009
|
+
const mapper = deps.requestDataMapper;
|
|
4010
|
+
if (typeof mapper.create3DPaymentStatusRequestData !== "function") {
|
|
4011
|
+
throw new PosError("PayFlexCPV4Pos needs a request data mapper with create3DPaymentStatusRequestData");
|
|
4012
|
+
}
|
|
4013
|
+
this.cpRequestDataMapper = deps.requestDataMapper;
|
|
4014
|
+
}
|
|
4015
|
+
/**
|
|
4016
|
+
* Registers the payment and returns the redirect (GET `CommonPaymentUrl?Ptkn=…`) to the bank card page.
|
|
4017
|
+
*
|
|
4018
|
+
* @throws UnsupportedFormFormatError for `formFormat: 'html'`
|
|
4019
|
+
* @throws PosError when the registration is not accepted
|
|
4020
|
+
*/
|
|
4021
|
+
async get3DFormData(order, paymentModel, txType, card = null, createWithoutCard = false, formFormat = null) {
|
|
4022
|
+
this.check3DFormInputs(paymentModel, txType, card, createWithoutCard);
|
|
4023
|
+
if (formFormat === FORM_FORMAT.HTML) {
|
|
4024
|
+
throw new UnsupportedFormFormatError("Unsupported 3D form format!");
|
|
4025
|
+
}
|
|
4026
|
+
const requestTxType = TX_TYPE.INTERNAL_3D_FORM_BUILD;
|
|
4027
|
+
const requestData = await this.dispatchRequestDataPrepared(
|
|
4028
|
+
this.requestDataMapper.create3DFormInitializeRequestData(this.account, order, paymentModel, txType, card),
|
|
4029
|
+
requestTxType,
|
|
4030
|
+
order,
|
|
4031
|
+
paymentModel
|
|
4032
|
+
);
|
|
4033
|
+
const answer = await this.sendRequest(requestTxType, paymentModel, requestData, order);
|
|
4034
|
+
this.assertRegistered(answer);
|
|
4035
|
+
this.logger.debug("preparing 3D form data");
|
|
4036
|
+
return await this.requestDataMapper.create3DFormData(
|
|
4037
|
+
this.account,
|
|
4038
|
+
null,
|
|
4039
|
+
paymentModel,
|
|
4040
|
+
txType,
|
|
4041
|
+
"",
|
|
4042
|
+
null,
|
|
4043
|
+
answer
|
|
4044
|
+
);
|
|
4045
|
+
}
|
|
4046
|
+
async make3DPayment(_gatewayResponseData, _order, _txType, _card = null) {
|
|
4047
|
+
throw new UnsupportedPaymentModelError("Common payment supports the 3D Pay and 3D Host models only");
|
|
4048
|
+
}
|
|
4049
|
+
/**
|
|
4050
|
+
* @throws OrderMismatchError when the approved query answer belongs to another payment
|
|
4051
|
+
* @throws PosHttpError when the query fails or answers something that is not JSON/XML (e.g. an HTML page)
|
|
4052
|
+
*/
|
|
4053
|
+
make3DPayPayment(gatewayResponseData, order, txType) {
|
|
4054
|
+
return this.completeHostedPayment(gatewayResponseData, order, txType, MODEL.THREE_D_PAY);
|
|
4055
|
+
}
|
|
4056
|
+
/**
|
|
4057
|
+
* @throws OrderMismatchError when the approved query answer belongs to another payment
|
|
4058
|
+
* @throws PosHttpError when the query fails or answers something that is not JSON/XML (e.g. an HTML page)
|
|
4059
|
+
*/
|
|
4060
|
+
make3DHostPayment(gatewayResponseData, order, txType) {
|
|
4061
|
+
return this.completeHostedPayment(gatewayResponseData, order, txType, MODEL.THREE_D_HOST);
|
|
4062
|
+
}
|
|
4063
|
+
async makeRegularPayment(_order, _card, _txType) {
|
|
4064
|
+
throw new UnsupportedPaymentModelError("Common payment has no non-secure payment");
|
|
4065
|
+
}
|
|
4066
|
+
async makeRegularPostPayment(_order) {
|
|
4067
|
+
throw new UnsupportedTransactionTypeError(`Common payment has no post authorization; ${ALTERNATIVE}`);
|
|
4068
|
+
}
|
|
4069
|
+
async cancel(_order) {
|
|
4070
|
+
throw new UnsupportedTransactionTypeError(`Common payment has no cancel; ${ALTERNATIVE}`);
|
|
4071
|
+
}
|
|
4072
|
+
async refund(_order) {
|
|
4073
|
+
throw new UnsupportedTransactionTypeError(`Common payment has no refund; ${ALTERNATIVE}`);
|
|
4074
|
+
}
|
|
4075
|
+
async orderHistory(_order) {
|
|
4076
|
+
throw new UnsupportedTransactionTypeError("Common payment has no order history");
|
|
4077
|
+
}
|
|
4078
|
+
/**
|
|
4079
|
+
* Registration succeeds only with a payment token, an `https:` payment URL and no error code
|
|
4080
|
+
* (VakifBank Common Payment guide v2.1 §4: `ErrorCode` is set only on failure).
|
|
4081
|
+
*/
|
|
4082
|
+
assertRegistered(answer) {
|
|
4083
|
+
const errorCode = nonEmpty(answer, "ErrorCode");
|
|
4084
|
+
const statusCode = nonEmpty(answer, "StatusCode");
|
|
4085
|
+
const token = nonEmpty(answer, "PaymentToken");
|
|
4086
|
+
const url = nonEmpty(answer, "CommonPaymentUrl");
|
|
4087
|
+
const failed = token === null || url === null || errorCode !== null && errorCode !== SUCCESS_CODE || statusCode !== null && statusCode !== "0";
|
|
4088
|
+
if (failed) {
|
|
4089
|
+
this.logger.error("payment register fail response", answer);
|
|
4090
|
+
const message = nonEmpty(answer, "ResponseMessage") ?? nonEmpty(answer, "ErrorMessage") ?? nonEmpty(answer, "StatusDescription") ?? "Common payment registration failed";
|
|
4091
|
+
throw new PosError(message, {
|
|
4092
|
+
cause: { code: value(answer, "ErrorCode") ?? value(answer, "StatusCode") ?? null }
|
|
4093
|
+
});
|
|
4094
|
+
}
|
|
4095
|
+
let protocol;
|
|
4096
|
+
try {
|
|
4097
|
+
protocol = new URL(url).protocol;
|
|
4098
|
+
} catch {
|
|
4099
|
+
protocol = "";
|
|
4100
|
+
}
|
|
4101
|
+
if (protocol !== "https:") {
|
|
4102
|
+
this.logger.error("payment register response has no https payment URL", { url });
|
|
4103
|
+
throw new PosError("Common payment URL must be an https: URL");
|
|
4104
|
+
}
|
|
4105
|
+
}
|
|
4106
|
+
/**
|
|
4107
|
+
* Confirms the browser callback with the transaction query (VakifBank Common Payment guide v2.1 §6.4, §6.5) and
|
|
4108
|
+
* binds an approved answer to the order. The callback result code never decides the status.
|
|
4109
|
+
*
|
|
4110
|
+
* @throws OrderMismatchError (`paymentMayHaveCompleted: false`, no HTTP call) when the callback ids contradict
|
|
4111
|
+
* the order's `transaction_id` / `payment_token`
|
|
4112
|
+
*/
|
|
4113
|
+
async completeHostedPayment(callback, order, txType, paymentModel) {
|
|
4114
|
+
if (txType !== TX_TYPE.PAY_AUTH && txType !== TX_TYPE.PAY_PRE_AUTH) {
|
|
4115
|
+
throw new UnsupportedTransactionTypeError(`Invalid transaction type "${txType}" provided`);
|
|
4116
|
+
}
|
|
4117
|
+
const cb = callback;
|
|
4118
|
+
const callbackSaysApproved = firstNonEmptyString(cb, "Rc", "RC", "ResultCode") === SUCCESS_CODE;
|
|
4119
|
+
const map = (data) => paymentModel === MODEL.THREE_D_PAY ? this.responseDataMapper.map3DPayResponseData(data, txType, order) : this.responseDataMapper.map3DHostResponseData(data, txType, order);
|
|
4120
|
+
const orderTransactionId = nonEmptyString(order.transaction_id);
|
|
4121
|
+
const orderPaymentToken = nonEmptyString(order.payment_token);
|
|
4122
|
+
const callbackTransactionId = nonEmpty(cb, "TransactionId");
|
|
4123
|
+
const callbackPaymentToken = nonEmpty(cb, "PaymentToken");
|
|
4124
|
+
if (orderTransactionId !== null && callbackTransactionId !== null && callbackTransactionId !== orderTransactionId) {
|
|
4125
|
+
this.rejectCallbackId(orderTransactionId, callbackTransactionId);
|
|
4126
|
+
}
|
|
4127
|
+
if (orderPaymentToken !== null && callbackPaymentToken !== null && callbackPaymentToken !== orderPaymentToken) {
|
|
4128
|
+
this.rejectCallbackId(orderPaymentToken, callbackPaymentToken);
|
|
4129
|
+
}
|
|
4130
|
+
const queryByOrder = orderTransactionId !== null || orderPaymentToken !== null;
|
|
4131
|
+
if (!queryByOrder && callbackTransactionId === null && callbackPaymentToken === null) {
|
|
4132
|
+
this.logger.error("3D callback has no TransactionId or PaymentToken to confirm", {
|
|
4133
|
+
callback_says_approved: callbackSaysApproved
|
|
4134
|
+
});
|
|
4135
|
+
const response2 = {
|
|
4136
|
+
...map({}),
|
|
4137
|
+
status: "declined",
|
|
4138
|
+
proc_return_code: null,
|
|
4139
|
+
error_code: null,
|
|
4140
|
+
error_message: NO_IDS_MESSAGE,
|
|
4141
|
+
all: cb
|
|
4142
|
+
};
|
|
4143
|
+
if (callbackSaysApproved) response2.requires_manual_review = true;
|
|
4144
|
+
return response2;
|
|
4145
|
+
}
|
|
4146
|
+
const queryTxType = TX_TYPE.INTERNAL_3D_PAYMENT_STATUS;
|
|
4147
|
+
const queryModel = MODEL.NON_SECURE;
|
|
4148
|
+
const query = await this.dispatchRequestDataPrepared(
|
|
4149
|
+
queryByOrder ? this.requestDataMapper.createStatusRequestData(this.account, order) : this.cpRequestDataMapper.create3DPaymentStatusRequestData(this.account, cb),
|
|
4150
|
+
queryTxType,
|
|
4151
|
+
order,
|
|
4152
|
+
queryModel
|
|
4153
|
+
);
|
|
4154
|
+
const answer = await this.sendRequest(queryTxType, queryModel, query, order);
|
|
4155
|
+
const response = map(answer);
|
|
4156
|
+
if (response.status === "approved") {
|
|
4157
|
+
this.assertAnswerMatchesOrder(
|
|
4158
|
+
answer,
|
|
4159
|
+
orderTransactionId ?? callbackTransactionId,
|
|
4160
|
+
orderPaymentToken,
|
|
4161
|
+
order,
|
|
4162
|
+
txType,
|
|
4163
|
+
response
|
|
4164
|
+
);
|
|
4165
|
+
this.logger.debug("finished 3D payment", { mapped_response: response });
|
|
4166
|
+
return response;
|
|
4167
|
+
}
|
|
4168
|
+
if (callbackSaysApproved) {
|
|
4169
|
+
this.logger.error("3D callback says approved but the transaction query does not confirm it", {
|
|
4170
|
+
proc_return_code: response.proc_return_code,
|
|
4171
|
+
error_code: response.error_code
|
|
4172
|
+
});
|
|
4173
|
+
return { ...response, requires_manual_review: true };
|
|
4174
|
+
}
|
|
4175
|
+
this.logger.debug("finished 3D payment", { mapped_response: response });
|
|
4176
|
+
return response;
|
|
4177
|
+
}
|
|
4178
|
+
/** A callback id that contradicts the order's own id: rejected before any HTTP call. */
|
|
4179
|
+
rejectCallbackId(expected, actual) {
|
|
4180
|
+
this.logger.error("3D callback id does not match the order", { expected, actual });
|
|
4181
|
+
throw new OrderMismatchError("transaction_id", expected, actual);
|
|
4182
|
+
}
|
|
4183
|
+
/** Binds an approved query answer to the order (fail closed: a missing required value never matches). */
|
|
4184
|
+
assertAnswerMatchesOrder(answer, expectedTransactionId, expectedPaymentToken, order, txType, response) {
|
|
4185
|
+
const fail2 = (field4, expected, actual) => {
|
|
4186
|
+
this.logger.error(`transaction query ${field4} does not match the payment`, { expected, actual });
|
|
4187
|
+
throw new OrderMismatchError(field4, expected, actual, response);
|
|
4188
|
+
};
|
|
4189
|
+
const expectedOrderId = asText2(order.id);
|
|
4190
|
+
const answerOrderId = value(answer, "OrderID") ?? value(answer, "OrderId");
|
|
4191
|
+
if (expectedOrderId === "" || typeof answerOrderId !== "string" || answerOrderId !== expectedOrderId) {
|
|
4192
|
+
fail2("order_id", expectedOrderId, asText2(answerOrderId));
|
|
4193
|
+
}
|
|
4194
|
+
const answerAmount = answerCents(value(answer, "Amount"));
|
|
4195
|
+
const orderAmount = orderCents(order.amount);
|
|
4196
|
+
if (answerAmount === null || orderAmount === null || answerAmount !== orderAmount) {
|
|
4197
|
+
fail2("amount", asText2(order.amount), asText2(value(answer, "Amount")));
|
|
4198
|
+
}
|
|
4199
|
+
const expectedCurrency = String(this.requestValueMapper.mapCurrency(order.currency ?? CURRENCY.TRY));
|
|
4200
|
+
const answerCurrency = value(answer, "AmountCode") ?? value(answer, "CurrencyCode");
|
|
4201
|
+
if (answerCurrency === void 0) {
|
|
4202
|
+
if (expectedCurrency !== "949") fail2("currency", expectedCurrency, "");
|
|
4203
|
+
} else if (String(answerCurrency) !== expectedCurrency) {
|
|
4204
|
+
fail2("currency", expectedCurrency, asText2(answerCurrency));
|
|
4205
|
+
}
|
|
4206
|
+
const answerMerchantId = value(answer, "HostMerchantId");
|
|
4207
|
+
if (answerMerchantId !== void 0 && String(answerMerchantId) !== this.account.getMerchantId()) {
|
|
4208
|
+
fail2("merchant_id", this.account.getMerchantId(), asText2(answerMerchantId));
|
|
4209
|
+
}
|
|
4210
|
+
const answerTxType = value(answer, "TransactionType");
|
|
4211
|
+
if (answerTxType !== void 0) {
|
|
4212
|
+
const expectedTxType = this.requestValueMapper.mapTxType(txType);
|
|
4213
|
+
if (String(answerTxType) !== expectedTxType) {
|
|
4214
|
+
fail2("transaction_type", expectedTxType, asText2(answerTxType));
|
|
4215
|
+
}
|
|
4216
|
+
}
|
|
4217
|
+
const answerTransactionId = value(answer, "TransactionId");
|
|
4218
|
+
if (expectedTransactionId !== null && answerTransactionId !== void 0 && String(answerTransactionId) !== expectedTransactionId) {
|
|
4219
|
+
fail2("transaction_id", expectedTransactionId, asText2(answerTransactionId));
|
|
4220
|
+
}
|
|
4221
|
+
const answerPaymentToken = value(answer, "PaymentToken");
|
|
4222
|
+
if (expectedPaymentToken !== null && answerPaymentToken !== void 0 && String(answerPaymentToken) !== expectedPaymentToken) {
|
|
4223
|
+
fail2("transaction_id", expectedPaymentToken, asText2(answerPaymentToken));
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
};
|
|
4227
|
+
|
|
3499
4228
|
// src/gateway/PayFlexV4Pos.ts
|
|
3500
4229
|
var AMOUNT_TOLERANCE2 = 5e-3;
|
|
3501
4230
|
var CALLBACK_AMOUNT = /^\d+(\.\d{2})?$/;
|
|
3502
|
-
var
|
|
4231
|
+
var DECIMAL3 = /^\s*[+-]?(\d+(\.\d*)?|\.\d+)\s*$/;
|
|
3503
4232
|
function record2(data, key) {
|
|
3504
4233
|
if (data !== null && typeof data === "object" && !Array.isArray(data) && Object.hasOwn(data, key)) {
|
|
3505
|
-
const
|
|
3506
|
-
if (
|
|
3507
|
-
return
|
|
4234
|
+
const value2 = data[key];
|
|
4235
|
+
if (value2 !== null && typeof value2 === "object" && !Array.isArray(value2)) {
|
|
4236
|
+
return value2;
|
|
3508
4237
|
}
|
|
3509
4238
|
}
|
|
3510
4239
|
return {};
|
|
3511
4240
|
}
|
|
3512
|
-
function parseCallbackAmount(
|
|
3513
|
-
if (typeof
|
|
3514
|
-
return Number(
|
|
4241
|
+
function parseCallbackAmount(value2) {
|
|
4242
|
+
if (typeof value2 !== "string" || !CALLBACK_AMOUNT.test(value2)) return Number.NaN;
|
|
4243
|
+
return Number(value2.replace(".", "")) / 100;
|
|
3515
4244
|
}
|
|
3516
|
-
function parseOrderAmount(
|
|
3517
|
-
if (typeof
|
|
3518
|
-
return typeof
|
|
4245
|
+
function parseOrderAmount(value2) {
|
|
4246
|
+
if (typeof value2 === "number") return Number.isFinite(value2) ? value2 : Number.NaN;
|
|
4247
|
+
return typeof value2 === "string" && DECIMAL3.test(value2) ? Number(value2) : Number.NaN;
|
|
3519
4248
|
}
|
|
3520
|
-
function
|
|
3521
|
-
return
|
|
4249
|
+
function asText3(value2) {
|
|
4250
|
+
return value2 === null || value2 === void 0 ? "" : String(value2);
|
|
3522
4251
|
}
|
|
3523
|
-
function
|
|
3524
|
-
const
|
|
3525
|
-
return
|
|
4252
|
+
function text5(data, key) {
|
|
4253
|
+
const value2 = Object.hasOwn(data, key) ? data[key] : void 0;
|
|
4254
|
+
return value2 === void 0 || value2 === null ? "" : String(value2);
|
|
3526
4255
|
}
|
|
3527
4256
|
var PayFlexV4Pos = class extends AbstractGateway {
|
|
3528
4257
|
static NAME = "PayFlexV4";
|
|
@@ -3588,12 +4317,12 @@ var PayFlexV4Pos = class extends AbstractGateway {
|
|
|
3588
4317
|
}
|
|
3589
4318
|
const data = await this.sendEnrollmentRequest(order, card, txType, paymentModel);
|
|
3590
4319
|
const veRes = record2(record2(data, "Message"), "VERes");
|
|
3591
|
-
const status =
|
|
4320
|
+
const status = text5(veRes, "Status");
|
|
3592
4321
|
if (status !== "Y") {
|
|
3593
4322
|
this.logger.error("enrollment fail response", data);
|
|
3594
4323
|
if (status === "E") {
|
|
3595
|
-
throw new PosError(
|
|
3596
|
-
cause: { code:
|
|
4324
|
+
throw new PosError(text5(data, "ErrorMessage") || "Enrollment failed", {
|
|
4325
|
+
cause: { code: text5(data, "MessageErrorCode") }
|
|
3597
4326
|
});
|
|
3598
4327
|
}
|
|
3599
4328
|
if (status === "N") {
|
|
@@ -3634,29 +4363,29 @@ var PayFlexV4Pos = class extends AbstractGateway {
|
|
|
3634
4363
|
* guard only stops naive replays.
|
|
3635
4364
|
*/
|
|
3636
4365
|
assertCallbackMatchesOrder(callback, order) {
|
|
3637
|
-
const
|
|
3638
|
-
const callbackAmount = parseCallbackAmount(
|
|
4366
|
+
const own2 = (key) => Object.hasOwn(callback, key) ? callback[key] : void 0;
|
|
4367
|
+
const callbackAmount = parseCallbackAmount(own2("PurchAmount"));
|
|
3639
4368
|
const orderAmount = parseOrderAmount(order.amount);
|
|
3640
4369
|
if (!(Math.abs(callbackAmount - orderAmount) < AMOUNT_TOLERANCE2)) {
|
|
3641
|
-
this.fail("amount",
|
|
4370
|
+
this.fail("amount", asText3(order.amount), asText3(own2("PurchAmount")));
|
|
3642
4371
|
}
|
|
3643
4372
|
const expectedCurrency = String(this.requestValueMapper.mapCurrency(order.currency ?? CURRENCY.TRY));
|
|
3644
|
-
if (
|
|
3645
|
-
this.fail("currency", expectedCurrency,
|
|
4373
|
+
if (own2("PurchCurrency") !== expectedCurrency) {
|
|
4374
|
+
this.fail("currency", expectedCurrency, asText3(own2("PurchCurrency")));
|
|
3646
4375
|
}
|
|
3647
4376
|
const merchantIds = [this.account.getMerchantId()];
|
|
3648
4377
|
const subMerchantId = this.account.getSubMerchantId();
|
|
3649
4378
|
if (this.account.isSubBranch() && subMerchantId !== null && subMerchantId !== "") {
|
|
3650
4379
|
merchantIds.push(subMerchantId);
|
|
3651
4380
|
}
|
|
3652
|
-
const merchantId =
|
|
4381
|
+
const merchantId = own2("MerchantId");
|
|
3653
4382
|
if (typeof merchantId !== "string" || !merchantIds.includes(merchantId)) {
|
|
3654
|
-
this.fail("merchant_id", merchantIds.join(" | "),
|
|
4383
|
+
this.fail("merchant_id", merchantIds.join(" | "), asText3(merchantId));
|
|
3655
4384
|
}
|
|
3656
4385
|
}
|
|
3657
|
-
fail(
|
|
3658
|
-
this.logger.error(`3D callback ${
|
|
3659
|
-
throw new OrderMismatchError(
|
|
4386
|
+
fail(field4, expected, actual) {
|
|
4387
|
+
this.logger.error(`3D callback ${field4} does not match the payment`, { expected, actual });
|
|
4388
|
+
throw new OrderMismatchError(field4, expected, actual);
|
|
3660
4389
|
}
|
|
3661
4390
|
/** Enrollment status query (VerifyEnrollmentRequest) sent to `gateway_3d`. */
|
|
3662
4391
|
async sendEnrollmentRequest(order, card, orderTxType, paymentModel) {
|
|
@@ -3697,6 +4426,8 @@ var PosFactory = {
|
|
|
3697
4426
|
return createAssecoPos(account, gatewayConfig, transport, logger, hooks);
|
|
3698
4427
|
case PayFlexV4Pos.GATEWAY_CLASS:
|
|
3699
4428
|
return createPayFlexV4Pos(account, gatewayConfig, transport, logger, hooks);
|
|
4429
|
+
case PayFlexCPV4Pos.GATEWAY_CLASS:
|
|
4430
|
+
return createPayFlexCPV4Pos(account, gatewayConfig, transport, logger, hooks);
|
|
3700
4431
|
default:
|
|
3701
4432
|
throw new GatewayClassNotConfiguredError(
|
|
3702
4433
|
`Gateway class [${bankConfig.class}] of bank [${bankName}] is not supported.`
|
|
@@ -3766,6 +4497,38 @@ function createPayFlexV4Pos(account, config, transport, logger, hooks) {
|
|
|
3766
4497
|
hooks
|
|
3767
4498
|
});
|
|
3768
4499
|
}
|
|
4500
|
+
function createPayFlexCPV4Pos(account, config, transport, logger, hooks) {
|
|
4501
|
+
if (!(account instanceof PayFlexPosAccount)) {
|
|
4502
|
+
throw new PosError(
|
|
4503
|
+
`Bank [${account.getBankName()}] is configured for PayFlexCPV4Pos and needs a PayFlexPosAccount.`
|
|
4504
|
+
);
|
|
4505
|
+
}
|
|
4506
|
+
const crypt = new PayFlexCPV4PosCrypt(logger);
|
|
4507
|
+
const requestValueMapper = new PayFlexCPV4PosRequestValueMapper();
|
|
4508
|
+
const requestValueFormatter = new PayFlexCPV4PosRequestValueFormatter();
|
|
4509
|
+
return new PayFlexCPV4Pos(config, account, {
|
|
4510
|
+
requestValueMapper,
|
|
4511
|
+
requestValueFormatter,
|
|
4512
|
+
requestDataMapper: new PayFlexCPV4PosRequestDataMapper(
|
|
4513
|
+
requestValueMapper,
|
|
4514
|
+
requestValueFormatter,
|
|
4515
|
+
hooks,
|
|
4516
|
+
crypt,
|
|
4517
|
+
config.lang ?? LANG.TR
|
|
4518
|
+
),
|
|
4519
|
+
responseDataMapper: new PayFlexCPV4PosResponseDataMapper(
|
|
4520
|
+
new BasicResponseValueFormatter(),
|
|
4521
|
+
new PayFlexCPV4PosResponseValueMapper(),
|
|
4522
|
+
logger
|
|
4523
|
+
),
|
|
4524
|
+
crypt,
|
|
4525
|
+
clientStrategy: new HttpClientStrategy([
|
|
4526
|
+
new PayFlexCPV4PosHttpClient(requiredEndpoint(config, "payment_api"), transport, logger)
|
|
4527
|
+
]),
|
|
4528
|
+
logger,
|
|
4529
|
+
hooks
|
|
4530
|
+
});
|
|
4531
|
+
}
|
|
3769
4532
|
function assertHttpsEndpoints(config) {
|
|
3770
4533
|
const endpoints = config.gateway_endpoints ?? {};
|
|
3771
4534
|
for (const [key, url] of Object.entries(endpoints)) {
|
|
@@ -3792,7 +4555,7 @@ function requiredEndpoint(config, key) {
|
|
|
3792
4555
|
}
|
|
3793
4556
|
|
|
3794
4557
|
// src/index.ts
|
|
3795
|
-
var VERSION = "0.
|
|
4558
|
+
var VERSION = "0.2.0";
|
|
3796
4559
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3797
4560
|
0 && (module.exports = {
|
|
3798
4561
|
AbstractGateway,
|
|
@@ -3817,6 +4580,7 @@ var VERSION = "0.1.1";
|
|
|
3817
4580
|
NotImplementedError,
|
|
3818
4581
|
OrderMismatchError,
|
|
3819
4582
|
PAYMENT_STATUS,
|
|
4583
|
+
PayFlexCPV4Pos,
|
|
3820
4584
|
PayFlexPosAccount,
|
|
3821
4585
|
PayFlexV4Pos,
|
|
3822
4586
|
PosError,
|