@munchi_oy/payments 1.2.5

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.
Files changed (43) hide show
  1. package/README.md +28 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +1 -0
  5. package/dist/index.mjs +1 -0
  6. package/dist/src/MunchiPaymentSDK.d.ts +42 -0
  7. package/dist/src/MunchiPaymentSDK.d.ts.map +1 -0
  8. package/dist/src/error.d.ts +18 -0
  9. package/dist/src/error.d.ts.map +1 -0
  10. package/dist/src/strategies/IPaymentStrategy.d.ts +12 -0
  11. package/dist/src/strategies/IPaymentStrategy.d.ts.map +1 -0
  12. package/dist/src/strategies/MockStrategy.d.ts +13 -0
  13. package/dist/src/strategies/MockStrategy.d.ts.map +1 -0
  14. package/dist/src/strategies/NetsStrategy.d.ts +24 -0
  15. package/dist/src/strategies/NetsStrategy.d.ts.map +1 -0
  16. package/dist/src/strategies/VivaStrategy.d.ts +24 -0
  17. package/dist/src/strategies/VivaStrategy.d.ts.map +1 -0
  18. package/dist/src/test-link.d.ts +2 -0
  19. package/dist/src/test-link.d.ts.map +1 -0
  20. package/dist/src/types/device.d.ts +15 -0
  21. package/dist/src/types/device.d.ts.map +1 -0
  22. package/dist/src/types/index.d.ts +4 -0
  23. package/dist/src/types/index.d.ts.map +1 -0
  24. package/dist/src/types/payment.d.ts +109 -0
  25. package/dist/src/types/payment.d.ts.map +1 -0
  26. package/dist/src/types/sdk.d.ts +48 -0
  27. package/dist/src/types/sdk.d.ts.map +1 -0
  28. package/dist/src/version.d.ts +2 -0
  29. package/dist/src/version.d.ts.map +1 -0
  30. package/index.ts +3 -0
  31. package/package.json +51 -0
  32. package/src/MunchiPaymentSDK.ts +532 -0
  33. package/src/error.ts +26 -0
  34. package/src/strategies/IPaymentStrategy.ts +22 -0
  35. package/src/strategies/MockStrategy.ts +55 -0
  36. package/src/strategies/NetsStrategy.ts +336 -0
  37. package/src/strategies/VivaStrategy.ts +319 -0
  38. package/src/test-link.ts +0 -0
  39. package/src/types/device.ts +15 -0
  40. package/src/types/index.ts +3 -0
  41. package/src/types/payment.ts +123 -0
  42. package/src/types/sdk.ts +42 -0
  43. package/src/version.ts +3 -0
@@ -0,0 +1,123 @@
1
+ import type {
2
+ CurrencyCode,
3
+ PaymentProvider,
4
+ ProviderEnum,
5
+ TransactionDto,
6
+ } from "@munchi_oy/core";
7
+
8
+ export type TransactionDetails = Omit<
9
+ TransactionDto,
10
+ "id" | "createdAt" | "provider"
11
+ >;
12
+
13
+ export enum SdkPaymentStatus {
14
+ PENDING = "PENDING",
15
+ SUCCESS = "SUCCESS",
16
+ APPROVED = "APPROVED",
17
+ FAILED = "FAILED",
18
+ CANCELLED = "CANCELLED",
19
+ ERROR = "ERROR",
20
+ }
21
+
22
+ export enum PaymentInteractionState {
23
+ IDLE = "IDLE",
24
+ CONNECTING = "CONNECTING",
25
+ REQUIRES_INPUT = "REQUIRES_INPUT",
26
+ PROCESSING = "PROCESSING",
27
+ SUCCESS = "SUCCESS",
28
+ FAILED = "FAILED",
29
+ INTERNAL_ERROR = "INTERNAL_ERROR",
30
+ VERIFYING = "VERIFYING",
31
+ }
32
+
33
+ export interface VivaOptions {
34
+ installments?: number;
35
+ tipAmount?: number;
36
+ sourceCode?: string;
37
+ }
38
+
39
+ export interface NetsOptions {
40
+ vatAmount?: number;
41
+ operatorId?: string;
42
+ }
43
+
44
+ export interface VivaRefundOptions extends VivaOptions {
45
+ // Viva specific extensions if needed
46
+ }
47
+
48
+ export interface NetsRefundOptions extends NetsOptions {
49
+ allowPinBypass?: boolean;
50
+ }
51
+
52
+ export interface PaymentRequest {
53
+ orderRef: string;
54
+ amountCents: number;
55
+ currency: CurrencyCode;
56
+ displayId: string;
57
+ options?: VivaOptions | NetsOptions;
58
+ }
59
+
60
+ export interface RefundRequest {
61
+ amountCents: number;
62
+ orderRef: string;
63
+ currency: CurrencyCode;
64
+ displayId: string;
65
+ /**
66
+ * The ID of the original payment transaction.
67
+ * Maps to:
68
+ * - Viva: parentSessionId
69
+ * - Nets: preAuthorizationInfo (or reference)
70
+ */
71
+ originalTransactionId: string;
72
+ options?: VivaRefundOptions | NetsRefundOptions;
73
+ }
74
+
75
+ export interface PaymentTerminalConfig {
76
+ channel: ProviderEnum,
77
+ provider?: PaymentProvider | null;
78
+ kioskId: string;
79
+ storeId: string;
80
+ }
81
+
82
+ export interface PaymentResult {
83
+ success: boolean;
84
+ status: SdkPaymentStatus;
85
+ orderId: string;
86
+ transactionId?: string;
87
+ errorReference?: string;
88
+ errorCode?: string;
89
+ errorMessage?: string;
90
+ transaction?: TransactionDto;
91
+ }
92
+
93
+ export interface TransactionOptions {
94
+ onConnecting?: (ctx: { orderRef: string; refPaymentId?: string | undefined }) => void;
95
+ onRequiresInput?: (ctx: { orderRef: string; refPaymentId?: string | undefined }) => void;
96
+ onProcessing?: (ctx: { orderRef: string; refPaymentId?: string | undefined }) => void;
97
+ onVerifying?: (ctx: { orderRef: string; refPaymentId?: string | undefined }) => void;
98
+ onSuccess?: (result: PaymentResult) => void;
99
+ onError?: (result: PaymentResult) => void;
100
+ onCancelled?: (ctx: { orderRef: string; refPaymentId?: string | undefined }) => void;
101
+ }
102
+
103
+ export interface IMessagingAdapter {
104
+ subscribe<T>(
105
+ channel: string,
106
+ event: string,
107
+ onMessage: (data: T) => void,
108
+ ): () => void;
109
+ }
110
+
111
+ export interface IMunchiPaymentSDK {
112
+ readonly version: string;
113
+ readonly currentState: PaymentInteractionState;
114
+ readonly nextAutoResetAt: number | undefined;
115
+ subscribe(listener: (state: PaymentInteractionState) => void): () => void;
116
+ initiateTransaction(
117
+ params: PaymentRequest,
118
+ options?: TransactionOptions,
119
+ ): Promise<PaymentResult>;
120
+ cancel(): Promise<boolean>;
121
+ refund(params: RefundRequest, options?: TransactionOptions): Promise<PaymentResult>;
122
+ reset(): void;
123
+ }
@@ -0,0 +1,42 @@
1
+ import type { PaymentResult } from "./payment";
2
+
3
+ export interface ILogger {
4
+ debug(message: string, meta?: Record<string, unknown>): void;
5
+ info(message: string, meta?: Record<string, unknown>): void;
6
+ error(message: string, error?: unknown, meta?: Record<string, unknown>): void;
7
+ warn(message: string, meta?: Record<string, unknown>): void;
8
+ }
9
+
10
+ export interface PaymentCallbacks {
11
+ onConnecting?: (ctx: { orderRef: string }) => void;
12
+ onRequiresInput?: (ctx: { orderRef: string }) => void;
13
+ onProcessing?: (ctx: { orderRef: string }) => void;
14
+ onVerifying?: (ctx: { orderRef: string }) => void;
15
+ onSuccess?: (result: PaymentResult) => void;
16
+ onError?: (result: PaymentResult) => void;
17
+ onCancelled?: (ctx: { orderRef: string }) => void;
18
+ }
19
+
20
+ export interface AutoResetOptions {
21
+ /**
22
+ * Delay in milliseconds before resetting to IDLE after a successful transaction.
23
+ * Defaults to 5000ms if not specified.
24
+ */
25
+ successDelayMs?: number;
26
+
27
+ /**
28
+ * Delay in milliseconds before resetting to IDLE after a failed transaction.
29
+ * Defaults to 5000ms if not specified.
30
+ */
31
+ failureDelayMs?: number;
32
+ }
33
+
34
+ export interface SDKOptions {
35
+ timeoutMs?: number;
36
+ logger?: ILogger;
37
+ /**
38
+ * Configuration for automatically resetting the SDK state to IDLE.
39
+ * If provided (even as an empty object), auto-reset is enabled.
40
+ */
41
+ autoResetOnPaymentComplete?: AutoResetOptions;
42
+ }
package/src/version.ts ADDED
@@ -0,0 +1,3 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ // Run 'pnpm version:sync' to update this file.
3
+ export const VERSION = "1.2.5";