@munchi_oy/payments 1.6.9 → 1.10.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/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/src/MunchiPaymentSDK.d.ts +7 -1
- package/dist/src/MunchiPaymentSDK.d.ts.map +1 -1
- package/dist/src/strategies/ManualSessionStrategy.d.ts +10 -0
- package/dist/src/strategies/ManualSessionStrategy.d.ts.map +1 -0
- package/dist/src/strategies/VivaAppToAppStrategy.d.ts.map +1 -1
- package/dist/src/strategies/VivaSessionStrategy.d.ts +34 -0
- package/dist/src/strategies/VivaSessionStrategy.d.ts.map +1 -0
- package/dist/src/strategies/sessionResult.d.ts +5 -0
- package/dist/src/strategies/sessionResult.d.ts.map +1 -0
- package/dist/src/types/payment.d.ts +27 -2
- package/dist/src/types/payment.d.ts.map +1 -1
- package/dist/src/types/sdk.d.ts +9 -0
- package/dist/src/types/sdk.d.ts.map +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/MunchiPaymentSDK.ts +131 -1
- package/src/strategies/ManualSessionStrategy.ts +93 -0
- package/src/strategies/VivaAppToAppStrategy.ts +49 -33
- package/src/strategies/VivaSessionStrategy.ts +367 -0
- package/src/strategies/sessionResult.ts +92 -0
- package/src/types/payment.ts +64 -12
- package/src/types/sdk.ts +10 -0
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/types/payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"payment.d.ts","sourceRoot":"","sources":["../../../src/types/payment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACf,MAAM,iBAAiB,CAAC;AAEzB,MAAM,MAAM,kBAA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a,CAAC,CAAC;IAC1B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3B,MAAM,CACJ,MAAM,EAAE,aAAa,EACrB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,mBAAmB,CACjB,MAAM,EAAE,oBAAoB,EAC5B,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,iBAAiB,CACf,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;CACf"}
|
package/dist/src/types/sdk.d.ts
CHANGED
|
@@ -59,5 +59,14 @@ export interface SDKOptions {
|
|
|
59
59
|
*/
|
|
60
60
|
autoResetOnPaymentComplete?: AutoResetOptions;
|
|
61
61
|
appToApp?: AppToAppConfig;
|
|
62
|
+
/**
|
|
63
|
+
* Routes POS Viva payments through the backend payment-session flow
|
|
64
|
+
* (VivaSessionStrategy) instead of the legacy v4 VivaStrategy. Kiosk/handheld
|
|
65
|
+
* leave this unset and stay on the legacy flow.
|
|
66
|
+
*/
|
|
67
|
+
paymentSession?: PaymentSessionConfig;
|
|
68
|
+
}
|
|
69
|
+
export interface PaymentSessionConfig {
|
|
70
|
+
enabled: boolean;
|
|
62
71
|
}
|
|
63
72
|
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/types/sdk.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,WAAW,OAAO;IACtB,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC7D,IAAI,CAAC,OAAO,E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C,MAAM,GAAG,IAAI,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,mBAAmB,CAAC,EAAE,2BAA2B,CAAC;IAClD,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,0BAA0B,CAAC,EAAE,gBAAgB,CAAC;IAC9C,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,oBAAoB,CAAC;CACvC;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
package/dist/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.10.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@munchi_oy/payments",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Munchi Payments SDK - Payment processing utilities",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"publishConfig": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"@types/jest": "^30.0.0",
|
|
33
33
|
"tsup": "^8.0.0",
|
|
34
34
|
"typescript": "^5.0.0",
|
|
35
|
-
"@munchi_oy/core": "1.9.
|
|
35
|
+
"@munchi_oy/core": "1.9.38"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "jest",
|
package/src/MunchiPaymentSDK.ts
CHANGED
|
@@ -4,13 +4,16 @@ import { version } from "../package.json";
|
|
|
4
4
|
import { PaymentErrorCode, PaymentSDKError } from "./error";
|
|
5
5
|
import type { IPaymentStrategy } from "./strategies/IPaymentStrategy";
|
|
6
6
|
import { StrategyExecutionMode } from "./strategies/IPaymentStrategy";
|
|
7
|
+
import { ManualSessionStrategy } from "./strategies/ManualSessionStrategy";
|
|
7
8
|
import { NetsStrategy } from "./strategies/NetsStrategy";
|
|
8
9
|
import { VivaAppToAppStrategy } from "./strategies/VivaAppToAppStrategy";
|
|
10
|
+
import { VivaSessionStrategy } from "./strategies/VivaSessionStrategy";
|
|
9
11
|
import { VivaStrategy } from "./strategies/VivaStrategy";
|
|
10
12
|
import { WorldlineStrategy } from "./strategies/WorldlineStrategy";
|
|
11
13
|
import {
|
|
12
14
|
type IMessagingAdapter,
|
|
13
15
|
type IMunchiPaymentSDK,
|
|
16
|
+
type ManualPaymentRequest,
|
|
14
17
|
PaymentInteractionState,
|
|
15
18
|
type PaymentResult,
|
|
16
19
|
type PaymentTerminalConfig,
|
|
@@ -18,8 +21,14 @@ import {
|
|
|
18
21
|
type PaymentRequest as SdkPaymentRequest,
|
|
19
22
|
SdkPaymentStatus,
|
|
20
23
|
type TransactionOptions,
|
|
24
|
+
type VoidRequest,
|
|
21
25
|
} from "./types/payment";
|
|
22
|
-
import type {
|
|
26
|
+
import type {
|
|
27
|
+
AppToAppConfig,
|
|
28
|
+
ILogger,
|
|
29
|
+
PaymentSessionConfig,
|
|
30
|
+
SDKOptions,
|
|
31
|
+
} from "./types/sdk";
|
|
23
32
|
|
|
24
33
|
type StateListener = (state: PaymentInteractionState) => void;
|
|
25
34
|
|
|
@@ -36,6 +45,8 @@ export class MunchiPaymentSDK implements IMunchiPaymentSDK {
|
|
|
36
45
|
private _autoResetTimer: ReturnType<typeof setTimeout> | undefined;
|
|
37
46
|
private autoResetOptions: SDKOptions["autoResetOnPaymentComplete"];
|
|
38
47
|
private appToAppConfig: AppToAppConfig | undefined;
|
|
48
|
+
private paymentSessionConfig: PaymentSessionConfig | undefined;
|
|
49
|
+
private manualStrategy: ManualSessionStrategy;
|
|
39
50
|
|
|
40
51
|
private static readonly TERMINAL_STATES = [
|
|
41
52
|
PaymentInteractionState.SUCCESS,
|
|
@@ -61,6 +72,8 @@ export class MunchiPaymentSDK implements IMunchiPaymentSDK {
|
|
|
61
72
|
this.timeoutMs = options.timeoutMs || 30000;
|
|
62
73
|
this.autoResetOptions = options.autoResetOnPaymentComplete;
|
|
63
74
|
this.appToAppConfig = options.appToApp;
|
|
75
|
+
this.paymentSessionConfig = options.paymentSession;
|
|
76
|
+
this.manualStrategy = new ManualSessionStrategy(axios, config);
|
|
64
77
|
this.strategy = strategy ?? this.resolveStrategy(config);
|
|
65
78
|
}
|
|
66
79
|
|
|
@@ -200,6 +213,9 @@ export class MunchiPaymentSDK implements IMunchiPaymentSDK {
|
|
|
200
213
|
this.appToAppConfig,
|
|
201
214
|
);
|
|
202
215
|
}
|
|
216
|
+
if (this.paymentSessionConfig?.enabled) {
|
|
217
|
+
return new VivaSessionStrategy(this.axios, this.messaging, config);
|
|
218
|
+
}
|
|
203
219
|
return new VivaStrategy(this.axios, this.messaging, config);
|
|
204
220
|
|
|
205
221
|
default:
|
|
@@ -645,4 +661,118 @@ export class MunchiPaymentSDK implements IMunchiPaymentSDK {
|
|
|
645
661
|
return errorResult;
|
|
646
662
|
}
|
|
647
663
|
};
|
|
664
|
+
|
|
665
|
+
public recordManualPayment = async (
|
|
666
|
+
params: ManualPaymentRequest,
|
|
667
|
+
options?: TransactionOptions,
|
|
668
|
+
): Promise<PaymentResult> => {
|
|
669
|
+
const callbacks = options ?? {};
|
|
670
|
+
this.logger?.info("Recording manual payment", {
|
|
671
|
+
orderRef: params.orderRef,
|
|
672
|
+
});
|
|
673
|
+
this._currentSessionId = undefined;
|
|
674
|
+
this._cancellationIntent = false;
|
|
675
|
+
|
|
676
|
+
if (!MunchiPaymentSDK.RESTING_STATES.includes(this._currentState)) {
|
|
677
|
+
return this.generateErrorResult(
|
|
678
|
+
params.orderRef,
|
|
679
|
+
PaymentErrorCode.UNKNOWN,
|
|
680
|
+
"A transaction is already in progress",
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
this.transitionTo(PaymentInteractionState.CONNECTING);
|
|
685
|
+
this.safeFireCallback(() =>
|
|
686
|
+
callbacks.onConnecting?.({
|
|
687
|
+
orderRef: params.orderRef,
|
|
688
|
+
refPaymentId: undefined,
|
|
689
|
+
}),
|
|
690
|
+
);
|
|
691
|
+
|
|
692
|
+
try {
|
|
693
|
+
const result = await this.manualStrategy.recordPayment(params);
|
|
694
|
+
this.settleSingleShot(result, params.orderRef, callbacks);
|
|
695
|
+
return result;
|
|
696
|
+
} catch (error) {
|
|
697
|
+
this.logger?.error("Manual payment failed", error);
|
|
698
|
+
return this.failSingleShot(
|
|
699
|
+
params.orderRef,
|
|
700
|
+
error,
|
|
701
|
+
"Manual payment failed",
|
|
702
|
+
callbacks,
|
|
703
|
+
);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
public voidManualPayment = async (
|
|
708
|
+
params: VoidRequest,
|
|
709
|
+
options?: TransactionOptions,
|
|
710
|
+
): Promise<PaymentResult> => {
|
|
711
|
+
const callbacks = options ?? {};
|
|
712
|
+
this.logger?.info("Voiding manual payment", { orderRef: params.orderRef });
|
|
713
|
+
this._currentSessionId = params.sessionId;
|
|
714
|
+
this._cancellationIntent = false;
|
|
715
|
+
|
|
716
|
+
if (!MunchiPaymentSDK.RESTING_STATES.includes(this._currentState)) {
|
|
717
|
+
return this.generateErrorResult(
|
|
718
|
+
params.orderRef,
|
|
719
|
+
PaymentErrorCode.UNKNOWN,
|
|
720
|
+
"A transaction is already in progress",
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
this.transitionTo(PaymentInteractionState.CONNECTING);
|
|
725
|
+
|
|
726
|
+
try {
|
|
727
|
+
const result = await this.manualStrategy.voidPayment(params);
|
|
728
|
+
this.settleSingleShot(result, params.orderRef, callbacks);
|
|
729
|
+
return result;
|
|
730
|
+
} catch (error) {
|
|
731
|
+
this.logger?.error("Manual void failed", error);
|
|
732
|
+
return this.failSingleShot(
|
|
733
|
+
params.orderRef,
|
|
734
|
+
error,
|
|
735
|
+
"Void failed",
|
|
736
|
+
callbacks,
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
|
|
741
|
+
private settleSingleShot(
|
|
742
|
+
result: PaymentResult,
|
|
743
|
+
orderRef: string,
|
|
744
|
+
callbacks: TransactionOptions,
|
|
745
|
+
): void {
|
|
746
|
+
if (result.success) {
|
|
747
|
+
this.transitionTo(PaymentInteractionState.SUCCESS);
|
|
748
|
+
this.safeFireCallback(() => callbacks.onSuccess?.(result));
|
|
749
|
+
} else if (result.status === SdkPaymentStatus.CANCELLED) {
|
|
750
|
+
this.transitionTo(PaymentInteractionState.FAILED);
|
|
751
|
+
this.safeFireCallback(() =>
|
|
752
|
+
callbacks.onCancelled?.({
|
|
753
|
+
orderRef,
|
|
754
|
+
refPaymentId: this._currentSessionId,
|
|
755
|
+
}),
|
|
756
|
+
);
|
|
757
|
+
} else {
|
|
758
|
+
this.transitionTo(PaymentInteractionState.FAILED);
|
|
759
|
+
this.safeFireCallback(() => callbacks.onError?.(result));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
private failSingleShot(
|
|
764
|
+
orderRef: string,
|
|
765
|
+
error: unknown,
|
|
766
|
+
fallbackMessage: string,
|
|
767
|
+
callbacks: TransactionOptions,
|
|
768
|
+
): PaymentResult {
|
|
769
|
+
const errorResult = this.generateErrorResult(
|
|
770
|
+
orderRef,
|
|
771
|
+
PaymentErrorCode.NETWORK_ERROR,
|
|
772
|
+
error instanceof Error ? error.message : fallbackMessage,
|
|
773
|
+
);
|
|
774
|
+
this.transitionTo(PaymentInteractionState.FAILED);
|
|
775
|
+
this.safeFireCallback(() => callbacks.onError?.(errorResult));
|
|
776
|
+
return errorResult;
|
|
777
|
+
}
|
|
648
778
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type CreateManualSessionDto,
|
|
3
|
+
PaymentSessionApi,
|
|
4
|
+
PaymentSessionStatus,
|
|
5
|
+
} from "@munchi_oy/core";
|
|
6
|
+
import type { AxiosInstance } from "axios";
|
|
7
|
+
|
|
8
|
+
import { PaymentErrorCode, PaymentSDKError } from "../error";
|
|
9
|
+
import {
|
|
10
|
+
type ManualPaymentRequest,
|
|
11
|
+
type PaymentResult,
|
|
12
|
+
type PaymentTerminalConfig,
|
|
13
|
+
SdkPaymentStatus,
|
|
14
|
+
type VoidRequest,
|
|
15
|
+
} from "../types/payment";
|
|
16
|
+
import { mapSessionResult } from "./sessionResult";
|
|
17
|
+
|
|
18
|
+
export class ManualSessionStrategy {
|
|
19
|
+
private sessionApi: PaymentSessionApi;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
axios: AxiosInstance,
|
|
23
|
+
private config: PaymentTerminalConfig,
|
|
24
|
+
) {
|
|
25
|
+
this.sessionApi = new PaymentSessionApi(undefined, "", axios);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async recordPayment(request: ManualPaymentRequest): Promise<PaymentResult> {
|
|
29
|
+
try {
|
|
30
|
+
const payload: CreateManualSessionDto = {
|
|
31
|
+
businessId: Number(this.config.storeId),
|
|
32
|
+
orderId: request.orderRef,
|
|
33
|
+
amount: request.amountCents,
|
|
34
|
+
paymethod: request.paymethod,
|
|
35
|
+
provider: this.config.provider,
|
|
36
|
+
};
|
|
37
|
+
if (request.tipAmount !== undefined) {
|
|
38
|
+
payload.tipAmount = request.tipAmount;
|
|
39
|
+
}
|
|
40
|
+
if (request.splitContext !== undefined) {
|
|
41
|
+
payload.splitContext = request.splitContext;
|
|
42
|
+
}
|
|
43
|
+
if (request.metadata !== undefined) {
|
|
44
|
+
payload.metadata = request.metadata;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { data } = await this.sessionApi.recordManualPayment(payload);
|
|
48
|
+
return mapSessionResult(data, request.orderRef);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw new PaymentSDKError(
|
|
51
|
+
PaymentErrorCode.NETWORK_ERROR,
|
|
52
|
+
"Failed to record manual payment",
|
|
53
|
+
error,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async voidPayment(request: VoidRequest): Promise<PaymentResult> {
|
|
59
|
+
try {
|
|
60
|
+
const { data } = await this.sessionApi.voidManualPayment({
|
|
61
|
+
sessionId: request.sessionId,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const isVoided =
|
|
65
|
+
data.status === PaymentSessionStatus.Voided ||
|
|
66
|
+
data.status === PaymentSessionStatus.Voiding;
|
|
67
|
+
|
|
68
|
+
const result: PaymentResult = {
|
|
69
|
+
success: isVoided,
|
|
70
|
+
status: isVoided ? SdkPaymentStatus.SUCCESS : SdkPaymentStatus.FAILED,
|
|
71
|
+
orderId: request.orderRef,
|
|
72
|
+
transactionId: data.providerTransactionId ?? data.sessionId,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
if (!isVoided) {
|
|
76
|
+
if (data.errorCode) {
|
|
77
|
+
result.errorCode = data.errorCode;
|
|
78
|
+
}
|
|
79
|
+
if (data.errorMessage) {
|
|
80
|
+
result.errorMessage = data.errorMessage;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new PaymentSDKError(
|
|
87
|
+
PaymentErrorCode.NETWORK_ERROR,
|
|
88
|
+
"Failed to void manual payment",
|
|
89
|
+
error,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -418,7 +418,6 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
418
418
|
request: RefundRequest,
|
|
419
419
|
): Promise<PaymentReferenceContext | undefined> {
|
|
420
420
|
try {
|
|
421
|
-
|
|
422
421
|
const payload = {
|
|
423
422
|
orderId: request.orderRef,
|
|
424
423
|
provider: PaymentProvider.Viva,
|
|
@@ -426,7 +425,8 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
426
425
|
businessId: request.businessId,
|
|
427
426
|
} satisfies GetPaymentReferenceDto;
|
|
428
427
|
|
|
429
|
-
const { data } =
|
|
428
|
+
const { data } =
|
|
429
|
+
await this.paymentApiWithReference.getPaymentReference(payload);
|
|
430
430
|
|
|
431
431
|
return this.extractPaymentReferenceContext(data);
|
|
432
432
|
} catch {
|
|
@@ -442,7 +442,11 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
const references = response.references;
|
|
445
|
-
if (
|
|
445
|
+
if (
|
|
446
|
+
!references ||
|
|
447
|
+
typeof references !== "object" ||
|
|
448
|
+
Array.isArray(references)
|
|
449
|
+
) {
|
|
446
450
|
return {
|
|
447
451
|
originalTransactionId: response.originalTransactionId,
|
|
448
452
|
};
|
|
@@ -461,9 +465,9 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
461
465
|
const referenceCode =
|
|
462
466
|
this.readReferenceValue(context.referenceCode) ??
|
|
463
467
|
this.readReferenceValue(context.orderCode);
|
|
464
|
-
const shortReferenceCode =
|
|
465
|
-
context.shortReferenceCode
|
|
466
|
-
|
|
468
|
+
const shortReferenceCode =
|
|
469
|
+
this.readReferenceValue(context.shortReferenceCode) ??
|
|
470
|
+
this.readReferenceValue(context.shortOrderCode);
|
|
467
471
|
const terminalId =
|
|
468
472
|
this.readReferenceValue(context.terminalId) ??
|
|
469
473
|
this.readReferenceValue(context.tid);
|
|
@@ -601,7 +605,9 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
601
605
|
return new URL(callbackUrl).protocol.replace(/:$/, "");
|
|
602
606
|
}
|
|
603
607
|
|
|
604
|
-
private matchesKnownTransactionId(
|
|
608
|
+
private matchesKnownTransactionId(
|
|
609
|
+
rawParams: Record<string, string>,
|
|
610
|
+
): boolean {
|
|
605
611
|
const knownIds = [
|
|
606
612
|
this.currentClientTransactionId,
|
|
607
613
|
this.currentIsvClientTransactionId,
|
|
@@ -673,9 +679,13 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
673
679
|
return !transactionType.includes("abort");
|
|
674
680
|
}
|
|
675
681
|
|
|
676
|
-
private isTransactionDetailsAction(
|
|
677
|
-
|
|
678
|
-
|
|
682
|
+
private isTransactionDetailsAction(
|
|
683
|
+
rawParams: Record<string, string>,
|
|
684
|
+
): boolean {
|
|
685
|
+
return (
|
|
686
|
+
(rawParams.action ?? "").toLowerCase() ===
|
|
687
|
+
VIVA_ACTION_TRANSACTION_DETAILS.toLowerCase()
|
|
688
|
+
);
|
|
679
689
|
}
|
|
680
690
|
|
|
681
691
|
private isCancelledCallback(rawParams: Record<string, string>): boolean {
|
|
@@ -711,16 +721,18 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
711
721
|
return match?.[1];
|
|
712
722
|
}
|
|
713
723
|
|
|
714
|
-
private mapCallbackToTransaction(
|
|
724
|
+
private mapCallbackToTransaction(
|
|
725
|
+
rawParams: VivaCallbackParams,
|
|
726
|
+
): TransactionDto {
|
|
715
727
|
const transactionId =
|
|
716
728
|
rawParams.transactionId ??
|
|
717
729
|
rawParams.orderCode ??
|
|
718
730
|
rawParams.clientTransactionId ??
|
|
719
731
|
"unknown";
|
|
720
732
|
const timestamp = normalizeTimestamp(rawParams.transactionDate);
|
|
721
|
-
const amount = parseInteger(rawParams.amount);
|
|
722
733
|
const tipAmount = parseInteger(rawParams.tipAmount);
|
|
723
734
|
const surchargeAmount = parseInteger(rawParams.surchargeAmount);
|
|
735
|
+
const amount = parseInteger(rawParams.amount) - tipAmount - surchargeAmount;
|
|
724
736
|
|
|
725
737
|
return {
|
|
726
738
|
amount,
|
|
@@ -746,8 +758,12 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
746
758
|
};
|
|
747
759
|
}
|
|
748
760
|
|
|
749
|
-
private getVivaPaymentMethodType(
|
|
750
|
-
|
|
761
|
+
private getVivaPaymentMethodType(
|
|
762
|
+
rawParams: VivaCallbackParams,
|
|
763
|
+
): PaymentMethod {
|
|
764
|
+
const applicationLabel = (rawParams.applicationLabel ?? "")
|
|
765
|
+
.toUpperCase()
|
|
766
|
+
.trim();
|
|
751
767
|
const maskedPan = rawParams.accountNumber ?? "";
|
|
752
768
|
const binPrefix = maskedPan.substring(0, 6);
|
|
753
769
|
const issuer = (rawParams.bankId ?? "").trim();
|
|
@@ -760,9 +776,7 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
760
776
|
return PaymentMethod.WoltBenefit;
|
|
761
777
|
}
|
|
762
778
|
|
|
763
|
-
if (
|
|
764
|
-
CREDIT_KEYWORDS.some((keyword) => applicationLabel.includes(keyword))
|
|
765
|
-
) {
|
|
779
|
+
if (CREDIT_KEYWORDS.some((keyword) => applicationLabel.includes(keyword))) {
|
|
766
780
|
return PaymentMethod.Credit;
|
|
767
781
|
}
|
|
768
782
|
|
|
@@ -835,25 +849,27 @@ export class VivaAppToAppStrategy implements IPaymentStrategy {
|
|
|
835
849
|
resolve(null);
|
|
836
850
|
}, VIVA_TRANSACTION_DETAILS_TIMEOUT_MS);
|
|
837
851
|
|
|
838
|
-
const unsubscribe = this.appToAppConfig.adapter.subscribe(
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
852
|
+
const unsubscribe = this.appToAppConfig.adapter.subscribe(
|
|
853
|
+
(callbackUrl) => {
|
|
854
|
+
if (settled) {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
842
857
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
858
|
+
const parsed = this.parseCallbackUrl(callbackUrl);
|
|
859
|
+
if (!parsed) {
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
847
862
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
863
|
+
if (!this.matchesKnownTransactionId(parsed.rawParams)) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
851
866
|
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
867
|
+
settled = true;
|
|
868
|
+
clearTimeout(timeoutId);
|
|
869
|
+
unsubscribe();
|
|
870
|
+
resolve(parsed.result);
|
|
871
|
+
},
|
|
872
|
+
);
|
|
857
873
|
|
|
858
874
|
this.appToAppConfig.adapter
|
|
859
875
|
.openUrl(
|