@litepos/payment 1.0.12 → 1.0.15

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/client.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse } from './interfaces';
1
+ import type { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse, VoidResponse } from './interfaces';
2
2
  import { PaymentStatus } from './types/status';
3
3
  export declare function validateConfig(method: string, config: unknown): void;
4
4
  export declare class LitePosPayment {
@@ -6,8 +6,9 @@ export declare class LitePosPayment {
6
6
  queryPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<PaymentResponse>;
7
7
  cancelPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<CancelResponse>;
8
8
  refund(method: string, transactionId: string, config: Record<string, unknown>, amount?: number): Promise<RefundResponse>;
9
+ voidPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<VoidResponse>;
9
10
  queryRefund(method: string, refundId: string, config: Record<string, unknown>): Promise<RefundResponse>;
10
11
  simulateCharge(request: PaymentRequest): PaymentResponse;
11
- simulateQuery(transactionId: string, status: PaymentStatus): PaymentResponse;
12
+ simulateQuery(transactionId: string, status: PaymentStatus, amount?: number, currency?: string): PaymentResponse;
12
13
  private getGatewayName;
13
14
  }
package/dist/client.js CHANGED
@@ -1,4 +1,4 @@
1
- import { cancelPayment as cancelFiuuPayment, chargeCard, chargeQrCode, queryPayment, refund, validateConfig as validateFiuuConfig } from '@litepos/payment-fiuu';
1
+ import { cancelPayment as cancelFiuuPayment, chargeCard, chargeQrCode, queryPayment, refund, validateConfig as validateFiuuConfig, voidPayment as voidFiuuPayment } from '@litepos/payment-fiuu';
2
2
  import { ValidationError } from './types/error';
3
3
  import { PaymentStatus } from './types/status';
4
4
  import { logError, logInfo } from './utils/logger';
@@ -23,6 +23,10 @@ const CANCEL_ROUTING = {
23
23
  'FIUU': cancelFiuuPayment,
24
24
  'fiuu-qrcode': cancelFiuuPayment,
25
25
  };
26
+ const VOID_ROUTING = {
27
+ 'FIUU': voidFiuuPayment,
28
+ 'fiuu-qrcode': voidFiuuPayment,
29
+ };
26
30
  // Config validation routing
27
31
  const VALIDATE_ROUTING = {
28
32
  'FIUU': validateFiuuConfig,
@@ -92,6 +96,20 @@ export class LitePosPayment {
92
96
  throw error;
93
97
  }
94
98
  }
99
+ async voidPayment(method, transactionId, config) {
100
+ const handler = VOID_ROUTING[method];
101
+ if (!handler)
102
+ throw new ValidationError(`Payment method not supported: ${method}`, method);
103
+ try {
104
+ const response = await handler(transactionId, config);
105
+ logInfo(`${this.getGatewayName(method)}: Void payment, Transaction ID ${transactionId}, Void ID ${response.voidId}, Status ${response.status}`, { transactionId, response });
106
+ return response;
107
+ }
108
+ catch (error) {
109
+ logError(`${this.getGatewayName(method)}: Void payment failed, Transaction ID ${transactionId}`, { transactionId, error });
110
+ throw error;
111
+ }
112
+ }
95
113
  async queryRefund(method, refundId, config) {
96
114
  const handler = REFUND_QUERY_ROUTING[method];
97
115
  if (!handler)
@@ -108,25 +126,118 @@ export class LitePosPayment {
108
126
  }
109
127
  // Simulation methods (for testing, returns mock data without calling adapters)
110
128
  simulateCharge(request) {
111
- const transactionId = `SIM-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
129
+ const transactionId = `SIM-${Date.now()}`;
130
+ const isQrCode = request.method.includes('qrcode');
131
+ const paymentChannel = isQrCode ? (request.metadata?.paymentChannel || 'tng') : 'Mastercard';
132
+ const cardLabel = isQrCode ? '' : 'Mastercard';
133
+ const cardNo = isQrCode ? '' : '************2066';
134
+ const now = new Date();
135
+ const invNo = now.toISOString().replace(/[-:T]/g, '').slice(0, 14);
112
136
  return {
113
137
  transactionId,
114
138
  status: PaymentStatus.Pending,
115
139
  amount: request.amount,
116
140
  currency: request.currency,
117
- qrCodeData: request.method.includes('qrcode') ? `QR_${request.orderId}` : undefined,
118
- metadata: { simulated: true, ...request.metadata },
119
- raw: { simulated: true, request },
141
+ qrCodeData: isQrCode ? `QR_${request.orderId}` : undefined,
142
+ payment_source_method: cardLabel || paymentChannel,
143
+ payment_source_last4: isQrCode ? '' : '2066',
144
+ payment_source_charge_ref: transactionId,
145
+ metadata: {
146
+ responseCode: '00',
147
+ responseText: 'Approved',
148
+ paymentChannel,
149
+ invNo,
150
+ tid: '00000001',
151
+ mid: '000000000000001',
152
+ cardNo,
153
+ entryMode: 'contactless',
154
+ cardLabel,
155
+ },
156
+ raw: {
157
+ transType: 'sale',
158
+ posId: 'SIM_POS_ID',
159
+ deviceId: 'SIM_DEVICE_ID',
160
+ referenceLabel: request.orderId.slice(0, 10),
161
+ apiVersion: 'v1',
162
+ statusCode: '00',
163
+ responseCode: '00',
164
+ responseText: 'Approved',
165
+ terminalSn: 'SIM_TERMINAL',
166
+ softwareVersion: 'Version 1.0.0',
167
+ transData: {
168
+ cardNo,
169
+ entryMode: 'contactless',
170
+ rrn: '000000000001',
171
+ tvr: '0000008001',
172
+ appCrypt: 'simulated',
173
+ aid: 'A0000000041010',
174
+ cvmType: '00',
175
+ cardLabel,
176
+ paymentChannel,
177
+ transAmt: request.amount.toFixed(2),
178
+ transDateTime: now.toISOString().slice(0, 19),
179
+ transId: transactionId,
180
+ invNo,
181
+ batchNo: '',
182
+ tid: '00000001',
183
+ mid: '000000000000001',
184
+ currency: request.currency,
185
+ apprCode: '000001',
186
+ },
187
+ referenceId: `SIM-${Date.now()}`,
188
+ signature: 'simulated',
189
+ },
120
190
  };
121
191
  }
122
- simulateQuery(transactionId, status) {
192
+ simulateQuery(transactionId, status, amount = 0, currency = 'SGD') {
193
+ const now = new Date();
194
+ const invNo = now.toISOString().replace(/[-:T]/g, '').slice(0, 14);
123
195
  return {
124
196
  transactionId,
125
197
  status,
126
- amount: 0,
127
- currency: 'MYR',
128
- metadata: { simulated: true },
129
- raw: { simulated: true },
198
+ amount,
199
+ currency,
200
+ payment_source_method: 'Mastercard',
201
+ payment_source_last4: '2066',
202
+ payment_source_charge_ref: transactionId,
203
+ metadata: {
204
+ responseCode: '00',
205
+ responseText: 'Approved',
206
+ paymentChannel: 'Mastercard',
207
+ invNo,
208
+ tid: '00000001',
209
+ mid: '000000000000001',
210
+ cardNo: '************2066',
211
+ entryMode: 'contactless',
212
+ cardLabel: 'Mastercard',
213
+ },
214
+ raw: {
215
+ transType: 'sale',
216
+ posId: 'SIM_POS_ID',
217
+ deviceId: 'SIM_DEVICE_ID',
218
+ apiVersion: 'v1',
219
+ statusCode: '00',
220
+ responseCode: '00',
221
+ responseText: 'Approved',
222
+ terminalSn: 'SIM_TERMINAL',
223
+ softwareVersion: 'Version 1.0.0',
224
+ transData: {
225
+ cardNo: '************2066',
226
+ entryMode: 'contactless',
227
+ rrn: '000000000001',
228
+ cardLabel: 'Mastercard',
229
+ paymentChannel: 'Mastercard',
230
+ transAmt: amount.toFixed(2),
231
+ transDateTime: now.toISOString().slice(0, 19),
232
+ transId: transactionId,
233
+ invNo,
234
+ tid: '00000001',
235
+ mid: '000000000000001',
236
+ currency,
237
+ },
238
+ referenceId: `SIM-${Date.now()}`,
239
+ signature: 'simulated',
240
+ },
130
241
  };
131
242
  }
132
243
  getGatewayName(method) {
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { LitePosPayment, validateConfig } from './client';
2
- export { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse, ValidationResult, } from './interfaces';
2
+ export { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse, ValidationResult, VoidResponse, } from './interfaces';
3
3
  export { Simulator } from './simulator';
4
4
  export type { PaymentConfig } from './types/config';
5
5
  export { PaymentError, ValidationError } from './types/error';
6
- export { CancelStatus, PaymentStatus, RefundStatus } from './types/status';
6
+ export { CancelStatus, PaymentStatus, RefundStatus, VoidStatus } from './types/status';
7
7
  export { logError, logInfo } from './utils/logger';
package/dist/index.js CHANGED
@@ -3,6 +3,6 @@ export { LitePosPayment, validateConfig } from './client';
3
3
  export { Simulator } from './simulator';
4
4
  export { PaymentError, ValidationError } from './types/error';
5
5
  // Type exports
6
- export { CancelStatus, PaymentStatus, RefundStatus } from './types/status';
6
+ export { CancelStatus, PaymentStatus, RefundStatus, VoidStatus } from './types/status';
7
7
  // Logger exports
8
8
  export { logError, logInfo } from './utils/logger';
@@ -1,4 +1,4 @@
1
- import type { CancelStatus, PaymentStatus, RefundStatus } from './types/status';
1
+ import type { CancelStatus, PaymentStatus, RefundStatus, VoidStatus } from './types/status';
2
2
  export interface PaymentRequest {
3
3
  method: string;
4
4
  amount: number;
@@ -35,6 +35,16 @@ export interface CancelResponse {
35
35
  metadata?: Record<string, unknown>;
36
36
  raw?: unknown;
37
37
  }
38
+ export interface VoidResponse {
39
+ voidId: string;
40
+ transactionId: string;
41
+ status: VoidStatus;
42
+ amount: number;
43
+ currency: string;
44
+ voidedAt?: Date;
45
+ metadata?: Record<string, unknown>;
46
+ raw?: unknown;
47
+ }
38
48
  export interface ValidationResult {
39
49
  valid: boolean;
40
50
  errors?: string[];
@@ -13,3 +13,8 @@ export declare enum CancelStatus {
13
13
  Success = "success",
14
14
  Failed = "failed"
15
15
  }
16
+ export declare enum VoidStatus {
17
+ Pending = "pending",
18
+ Success = "success",
19
+ Failed = "failed"
20
+ }
@@ -19,3 +19,10 @@ export var CancelStatus;
19
19
  CancelStatus["Success"] = "success";
20
20
  CancelStatus["Failed"] = "failed";
21
21
  })(CancelStatus || (CancelStatus = {}));
22
+ // Void status enumeration
23
+ export var VoidStatus;
24
+ (function (VoidStatus) {
25
+ VoidStatus["Pending"] = "pending";
26
+ VoidStatus["Success"] = "success";
27
+ VoidStatus["Failed"] = "failed";
28
+ })(VoidStatus || (VoidStatus = {}));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@litepos/payment",
3
3
  "type": "module",
4
- "version": "1.0.12",
4
+ "version": "1.0.15",
5
5
  "description": "LitePOS payment gateway SDK - Core package",
6
6
  "author": "",
7
7
  "license": "MIT",
@@ -25,7 +25,7 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@litepos/payment-fiuu": "1.0.12"
28
+ "@litepos/payment-fiuu": "1.0.15"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.9.2",