@munchi_oy/payments 1.6.10 → 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/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/package.json +2 -2
- package/src/MunchiPaymentSDK.ts +131 -1
- package/src/strategies/ManualSessionStrategy.ts +93 -0
- 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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PaymentFailureCode,
|
|
3
|
+
PaymentSessionStatus,
|
|
4
|
+
type PaymentSessionViewDto,
|
|
5
|
+
} from "@munchi_oy/core";
|
|
6
|
+
|
|
7
|
+
import { PaymentErrorCode, PaymentSDKError } from "../error";
|
|
8
|
+
import { type PaymentResult, SdkPaymentStatus } from "../types/payment";
|
|
9
|
+
|
|
10
|
+
function assertNever(value: never): never {
|
|
11
|
+
throw new PaymentSDKError(
|
|
12
|
+
PaymentErrorCode.UNKNOWN,
|
|
13
|
+
`Unhandled payment session status: ${String(value)}`,
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function pendingResult(orderId: string): PaymentResult {
|
|
18
|
+
return {
|
|
19
|
+
success: false,
|
|
20
|
+
status: SdkPaymentStatus.PENDING,
|
|
21
|
+
orderId,
|
|
22
|
+
errorCode: "",
|
|
23
|
+
errorMessage: "",
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function mapSessionResult(
|
|
28
|
+
data: PaymentSessionViewDto,
|
|
29
|
+
orderId: string,
|
|
30
|
+
): PaymentResult {
|
|
31
|
+
switch (data.status) {
|
|
32
|
+
case PaymentSessionStatus.Initiated:
|
|
33
|
+
case PaymentSessionStatus.Processing:
|
|
34
|
+
case PaymentSessionStatus.Voiding:
|
|
35
|
+
case PaymentSessionStatus.Refunding:
|
|
36
|
+
return pendingResult(orderId);
|
|
37
|
+
|
|
38
|
+
case PaymentSessionStatus.Success:
|
|
39
|
+
case PaymentSessionStatus.Closed: {
|
|
40
|
+
const result: PaymentResult = {
|
|
41
|
+
success: true,
|
|
42
|
+
status: SdkPaymentStatus.SUCCESS,
|
|
43
|
+
orderId,
|
|
44
|
+
errorCode: "",
|
|
45
|
+
errorMessage: "",
|
|
46
|
+
};
|
|
47
|
+
if (data.providerTransactionId) {
|
|
48
|
+
result.transactionId = data.providerTransactionId;
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case PaymentSessionStatus.VoidFailed:
|
|
54
|
+
case PaymentSessionStatus.Failed: {
|
|
55
|
+
const result: PaymentResult = {
|
|
56
|
+
success: false,
|
|
57
|
+
status: SdkPaymentStatus.FAILED,
|
|
58
|
+
orderId,
|
|
59
|
+
errorCode: data.errorCode || PaymentFailureCode.SystemUnknown,
|
|
60
|
+
errorMessage:
|
|
61
|
+
data.errorMessage || "Transaction failed without error details",
|
|
62
|
+
};
|
|
63
|
+
if (data.providerTransactionId) {
|
|
64
|
+
result.transactionId = data.providerTransactionId;
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
case PaymentSessionStatus.Cancelled:
|
|
70
|
+
case PaymentSessionStatus.Voided:
|
|
71
|
+
case PaymentSessionStatus.Refunded: {
|
|
72
|
+
const result: PaymentResult = {
|
|
73
|
+
success: false,
|
|
74
|
+
status: SdkPaymentStatus.CANCELLED,
|
|
75
|
+
orderId,
|
|
76
|
+
};
|
|
77
|
+
if (data.errorCode) {
|
|
78
|
+
result.errorCode = data.errorCode;
|
|
79
|
+
}
|
|
80
|
+
if (data.errorMessage) {
|
|
81
|
+
result.errorMessage = data.errorMessage;
|
|
82
|
+
}
|
|
83
|
+
if (data.providerTransactionId) {
|
|
84
|
+
result.transactionId = data.providerTransactionId;
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
default:
|
|
90
|
+
return assertNever(data.status);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/types/payment.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
CurrencyCode,
|
|
3
|
+
PaymentProvider,
|
|
4
|
+
ProviderEnum,
|
|
5
|
+
SplitContextDto,
|
|
6
|
+
TransactionDto,
|
|
6
7
|
} from "@munchi_oy/core";
|
|
7
8
|
|
|
8
9
|
export type TransactionDetails = Omit<
|
|
@@ -63,6 +64,12 @@ export interface PaymentRequest {
|
|
|
63
64
|
currency: CurrencyCode;
|
|
64
65
|
displayId: string;
|
|
65
66
|
options?: VivaOptions | NetsOptions | WorldlineOptions;
|
|
67
|
+
/**
|
|
68
|
+
* Split context for the payment-session flow. Omit for a full-cart payment,
|
|
69
|
+
* or send { mode, partId|seatId } for a split. Must match the order's
|
|
70
|
+
* checkoutModel. Only consumed by VivaSessionStrategy.
|
|
71
|
+
*/
|
|
72
|
+
splitContext?: SplitContextDto;
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
export interface RefundRequest {
|
|
@@ -83,9 +90,28 @@ export interface RefundRequest {
|
|
|
83
90
|
options?: VivaRefundOptions | NetsRefundOptions | WorldlineRefundOptions;
|
|
84
91
|
}
|
|
85
92
|
|
|
93
|
+
export interface ManualPaymentRequest {
|
|
94
|
+
orderRef: string;
|
|
95
|
+
amountCents: number;
|
|
96
|
+
paymethod: string;
|
|
97
|
+
tipAmount?: number;
|
|
98
|
+
splitContext?: SplitContextDto;
|
|
99
|
+
/**
|
|
100
|
+
* Arbitrary client metadata persisted on the session (e.g. voucher code,
|
|
101
|
+
* gift card id, employee id, external reference, notes). Surfaced to
|
|
102
|
+
* reconciliation when building the order paymentEvent.
|
|
103
|
+
*/
|
|
104
|
+
metadata?: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface VoidRequest {
|
|
108
|
+
orderRef: string;
|
|
109
|
+
sessionId: string;
|
|
110
|
+
}
|
|
111
|
+
|
|
86
112
|
export interface PaymentTerminalConfig {
|
|
87
|
-
channel: ProviderEnum
|
|
88
|
-
provider
|
|
113
|
+
channel: ProviderEnum;
|
|
114
|
+
provider: PaymentProvider;
|
|
89
115
|
kioskId: string;
|
|
90
116
|
storeId: string;
|
|
91
117
|
}
|
|
@@ -102,13 +128,28 @@ export interface PaymentResult {
|
|
|
102
128
|
}
|
|
103
129
|
|
|
104
130
|
export interface TransactionOptions {
|
|
105
|
-
onConnecting?: (ctx: {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
131
|
+
onConnecting?: (ctx: {
|
|
132
|
+
orderRef: string;
|
|
133
|
+
refPaymentId?: string | undefined;
|
|
134
|
+
}) => void;
|
|
135
|
+
onRequiresInput?: (ctx: {
|
|
136
|
+
orderRef: string;
|
|
137
|
+
refPaymentId?: string | undefined;
|
|
138
|
+
}) => void;
|
|
139
|
+
onProcessing?: (ctx: {
|
|
140
|
+
orderRef: string;
|
|
141
|
+
refPaymentId?: string | undefined;
|
|
142
|
+
}) => void;
|
|
143
|
+
onVerifying?: (ctx: {
|
|
144
|
+
orderRef: string;
|
|
145
|
+
refPaymentId?: string | undefined;
|
|
146
|
+
}) => void;
|
|
109
147
|
onSuccess?: (result: PaymentResult) => void;
|
|
110
148
|
onError?: (result: PaymentResult) => void;
|
|
111
|
-
onCancelled?: (ctx: {
|
|
149
|
+
onCancelled?: (ctx: {
|
|
150
|
+
orderRef: string;
|
|
151
|
+
refPaymentId?: string | undefined;
|
|
152
|
+
}) => void;
|
|
112
153
|
}
|
|
113
154
|
|
|
114
155
|
export interface IMessagingAdapter {
|
|
@@ -129,6 +170,17 @@ export interface IMunchiPaymentSDK {
|
|
|
129
170
|
options?: TransactionOptions,
|
|
130
171
|
): Promise<PaymentResult>;
|
|
131
172
|
cancel(): Promise<boolean>;
|
|
132
|
-
refund(
|
|
173
|
+
refund(
|
|
174
|
+
params: RefundRequest,
|
|
175
|
+
options?: TransactionOptions,
|
|
176
|
+
): Promise<PaymentResult>;
|
|
177
|
+
recordManualPayment(
|
|
178
|
+
params: ManualPaymentRequest,
|
|
179
|
+
options?: TransactionOptions,
|
|
180
|
+
): Promise<PaymentResult>;
|
|
181
|
+
voidManualPayment(
|
|
182
|
+
params: VoidRequest,
|
|
183
|
+
options?: TransactionOptions,
|
|
184
|
+
): Promise<PaymentResult>;
|
|
133
185
|
reset(): void;
|
|
134
186
|
}
|
package/src/types/sdk.ts
CHANGED
|
@@ -57,4 +57,14 @@ export interface SDKOptions {
|
|
|
57
57
|
*/
|
|
58
58
|
autoResetOnPaymentComplete?: AutoResetOptions;
|
|
59
59
|
appToApp?: AppToAppConfig;
|
|
60
|
+
/**
|
|
61
|
+
* Routes POS Viva payments through the backend payment-session flow
|
|
62
|
+
* (VivaSessionStrategy) instead of the legacy v4 VivaStrategy. Kiosk/handheld
|
|
63
|
+
* leave this unset and stay on the legacy flow.
|
|
64
|
+
*/
|
|
65
|
+
paymentSession?: PaymentSessionConfig;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export interface PaymentSessionConfig {
|
|
69
|
+
enabled: boolean;
|
|
60
70
|
}
|
package/src/version.ts
CHANGED