@litepos/payment 1.0.15 → 1.0.18

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,14 +1,14 @@
1
1
  import type { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse, VoidResponse } from './interfaces';
2
- import { PaymentStatus } from './types/status';
2
+ import type { PaymentStatus } from './types/status';
3
3
  export declare function validateConfig(method: string, config: unknown): void;
4
4
  export declare class LitePosPayment {
5
+ private getRoute;
5
6
  charge(request: PaymentRequest): Promise<PaymentResponse>;
6
7
  queryPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<PaymentResponse>;
7
8
  cancelPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<CancelResponse>;
8
- refund(method: string, transactionId: string, config: Record<string, unknown>, amount?: number): Promise<RefundResponse>;
9
+ refund(method: string, transactionId: string, config: Record<string, unknown>, amount?: number, refundRequestNo?: string): Promise<RefundResponse>;
9
10
  voidPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<VoidResponse>;
10
11
  queryRefund(method: string, refundId: string, config: Record<string, unknown>): Promise<RefundResponse>;
11
12
  simulateCharge(request: PaymentRequest): PaymentResponse;
12
- simulateQuery(transactionId: string, status: PaymentStatus, amount?: number, currency?: string): PaymentResponse;
13
- private getGatewayName;
13
+ simulateQuery(method: string, transactionId: string, status: PaymentStatus, amount?: number, currency?: string): PaymentResponse;
14
14
  }
package/dist/client.js CHANGED
@@ -1,248 +1,158 @@
1
- import { cancelPayment as cancelFiuuPayment, chargeCard, chargeQrCode, queryPayment, refund, validateConfig as validateFiuuConfig, voidPayment as voidFiuuPayment } from '@litepos/payment-fiuu';
1
+ import { cancelPayment as cancelFiuuPayment, chargeCard, chargeQrCode, simulateCharge as fiuuSimulateCharge, simulateQuery as fiuuSimulateQuery, queryPayment, refund, validateConfig as validateFiuuConfig, voidPayment as voidFiuuPayment, } from '@litepos/payment-fiuu';
2
+ import {
3
+ // chargeAlipay as sqbChargeAlipay, // ALPH disabled
4
+ chargeCard as sqbChargeCard,
5
+ // chargeWechat as sqbChargeWechat, // WCPH disabled
6
+ queryPayment as sqbQueryPayment, refund as sqbRefund, simulateCharge as sqbSimulateCharge, simulateQuery as sqbSimulateQuery, validateConfig as validateSqbConfig, } from '@litepos/payment-shouqianba';
2
7
  import { ValidationError } from './types/error';
3
- import { PaymentStatus } from './types/status';
4
8
  import { logError, logInfo } from './utils/logger';
5
- // Fixed payment method routing
6
- const CHARGE_ROUTING = {
7
- 'FIUU': chargeCard,
8
- 'fiuu-qrcode': chargeQrCode,
9
+ const ROUTING = {
10
+ 'FIUU': {
11
+ charge: chargeCard,
12
+ query: queryPayment,
13
+ refund: refund,
14
+ refundQuery: queryPayment,
15
+ cancel: cancelFiuuPayment,
16
+ void: voidFiuuPayment,
17
+ simulateCharge: fiuuSimulateCharge,
18
+ simulateQuery: fiuuSimulateQuery,
19
+ validate: validateFiuuConfig,
20
+ name: 'Fiuu',
21
+ },
22
+ 'fiuu-qrcode': {
23
+ charge: chargeQrCode,
24
+ query: queryPayment,
25
+ refund: refund,
26
+ refundQuery: queryPayment,
27
+ cancel: cancelFiuuPayment,
28
+ void: voidFiuuPayment,
29
+ simulateCharge: fiuuSimulateCharge,
30
+ simulateQuery: fiuuSimulateQuery,
31
+ validate: validateFiuuConfig,
32
+ name: 'Fiuu',
33
+ },
34
+ 'SQBP': {
35
+ charge: sqbChargeCard,
36
+ query: sqbQueryPayment,
37
+ refund: sqbRefund,
38
+ refundQuery: sqbQueryPayment,
39
+ // cancel: not in SQB docs
40
+ // void: not in SQB docs
41
+ simulateCharge: sqbSimulateCharge,
42
+ simulateQuery: (txId, s, a, c) => sqbSimulateQuery(txId, s, a, c, 'SQBP'),
43
+ validate: validateSqbConfig,
44
+ name: 'Shouqianba',
45
+ },
46
+ // 'WCPH': { charge: sqbChargeWechat, ... }, // WeChat Pay C扫B - disabled
47
+ // 'ALPH': { charge: sqbChargeAlipay, ... }, // Alipay C扫B - disabled
9
48
  };
10
- const QUERY_ROUTING = {
11
- 'FIUU': queryPayment,
12
- 'fiuu-qrcode': queryPayment,
13
- };
14
- const REFUND_ROUTING = {
15
- 'FIUU': refund,
16
- 'fiuu-qrcode': refund,
17
- };
18
- const REFUND_QUERY_ROUTING = {
19
- 'FIUU': queryPayment,
20
- 'fiuu-qrcode': queryPayment,
21
- };
22
- const CANCEL_ROUTING = {
23
- 'FIUU': cancelFiuuPayment,
24
- 'fiuu-qrcode': cancelFiuuPayment,
25
- };
26
- const VOID_ROUTING = {
27
- 'FIUU': voidFiuuPayment,
28
- 'fiuu-qrcode': voidFiuuPayment,
29
- };
30
- // Config validation routing
31
- const VALIDATE_ROUTING = {
32
- 'FIUU': validateFiuuConfig,
33
- 'fiuu-qrcode': validateFiuuConfig,
34
- };
35
- // Validate payment method configuration
36
49
  export function validateConfig(method, config) {
37
- const validator = VALIDATE_ROUTING[method];
38
- if (!validator)
50
+ const route = ROUTING[method];
51
+ if (!route)
39
52
  throw new ValidationError(`Payment method not supported: ${method}`, method);
40
- validator(config);
53
+ route.validate(config);
41
54
  }
42
55
  export class LitePosPayment {
56
+ getRoute(method) {
57
+ const route = ROUTING[method];
58
+ if (!route)
59
+ throw new ValidationError(`Payment method not supported: ${method}`, method);
60
+ return route;
61
+ }
43
62
  async charge(request) {
44
- const handler = CHARGE_ROUTING[request.method];
45
- if (!handler)
46
- throw new ValidationError(`Payment method not supported: ${request.method}`, request.method);
63
+ const route = this.getRoute(request.method);
64
+ if (!route.charge)
65
+ throw new ValidationError(`Charge not supported for method: ${request.method}`, request.method);
47
66
  try {
48
- const response = await handler(request);
49
- logInfo(`${this.getGatewayName(request.method)}: Charge payment, Order ID ${request.orderId}, Transaction ID ${response.transactionId}, Status ${response.status}`, { request, response });
67
+ const response = await route.charge(request);
68
+ logInfo(`${route.name}: Charge payment, Order ID ${request.orderId}, Transaction ID ${response.transactionId}, Status ${response.status}`, { request, response });
50
69
  return response;
51
70
  }
52
71
  catch (error) {
53
- logError(`${this.getGatewayName(request.method)}: Charge payment failed, Order ID ${request.orderId}`, { request, error });
72
+ logError(`${route.name}: Charge payment failed, Order ID ${request.orderId}`, { request, error });
54
73
  throw error;
55
74
  }
56
75
  }
57
76
  async queryPayment(method, transactionId, config) {
58
- const handler = QUERY_ROUTING[method];
59
- if (!handler)
60
- throw new ValidationError(`Payment method not supported: ${method}`, method);
77
+ const route = this.getRoute(method);
78
+ if (!route.query)
79
+ throw new ValidationError(`Query not supported for method: ${method}`, method);
61
80
  try {
62
- const response = await handler(transactionId, config);
63
- logInfo(`${this.getGatewayName(method)}: Query payment, Transaction ID ${transactionId}, Status ${response.status}`, { transactionId, response });
81
+ const response = await route.query(transactionId, config);
82
+ logInfo(`${route.name}: Query payment, Transaction ID ${transactionId}, Status ${response.status}`, { transactionId, response });
64
83
  return response;
65
84
  }
66
85
  catch (error) {
67
- logError(`${this.getGatewayName(method)}: Query payment failed, Transaction ID ${transactionId}`, { transactionId, error });
86
+ logError(`${route.name}: Query payment failed, Transaction ID ${transactionId}`, { transactionId, error });
68
87
  throw error;
69
88
  }
70
89
  }
71
90
  async cancelPayment(method, transactionId, config) {
72
- const handler = CANCEL_ROUTING[method];
73
- if (!handler)
74
- throw new ValidationError(`Payment method not supported: ${method}`, method);
91
+ const route = this.getRoute(method);
92
+ if (!route.cancel)
93
+ throw new ValidationError(`Cancel not supported for method: ${method}`, method);
75
94
  try {
76
- const response = await handler(transactionId, config);
77
- logInfo(`${this.getGatewayName(method)}: Cancel payment, Transaction ID ${transactionId}, Status ${response.status}`, { transactionId, response });
95
+ const response = await route.cancel(transactionId, config);
96
+ logInfo(`${route.name}: Cancel payment, Transaction ID ${transactionId}, Status ${response.status}`, { transactionId, response });
78
97
  return response;
79
98
  }
80
99
  catch (error) {
81
- logError(`${this.getGatewayName(method)}: Cancel payment failed, Transaction ID ${transactionId}`, { transactionId, error });
100
+ logError(`${route.name}: Cancel payment failed, Transaction ID ${transactionId}`, { transactionId, error });
82
101
  throw error;
83
102
  }
84
103
  }
85
- async refund(method, transactionId, config, amount) {
86
- const handler = REFUND_ROUTING[method];
87
- if (!handler)
88
- throw new ValidationError(`Payment method not supported: ${method}`, method);
104
+ async refund(method, transactionId, config, amount, refundRequestNo) {
105
+ const route = this.getRoute(method);
106
+ if (!route.refund)
107
+ throw new ValidationError(`Refund not supported for method: ${method}`, method);
89
108
  try {
90
- const response = await handler(transactionId, config, amount);
91
- logInfo(`${this.getGatewayName(method)}: Refund payment, Transaction ID ${transactionId}, Refund ID ${response.refundId}, Status ${response.status}`, { transactionId, amount, response });
109
+ const response = await route.refund(transactionId, config, amount, refundRequestNo);
110
+ logInfo(`${route.name}: Refund payment, Transaction ID ${transactionId}, Refund ID ${response.refundId}, Status ${response.status}`, { transactionId, amount, response });
92
111
  return response;
93
112
  }
94
113
  catch (error) {
95
- logError(`${this.getGatewayName(method)}: Refund payment failed, Transaction ID ${transactionId}`, { transactionId, amount, error });
114
+ logError(`${route.name}: Refund payment failed, Transaction ID ${transactionId}`, { transactionId, amount, error });
96
115
  throw error;
97
116
  }
98
117
  }
99
118
  async voidPayment(method, transactionId, config) {
100
- const handler = VOID_ROUTING[method];
101
- if (!handler)
102
- throw new ValidationError(`Payment method not supported: ${method}`, method);
119
+ const route = this.getRoute(method);
120
+ if (!route.void)
121
+ throw new ValidationError(`Void not supported for method: ${method}`, method);
103
122
  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 });
123
+ const response = await route.void(transactionId, config);
124
+ logInfo(`${route.name}: Void payment, Transaction ID ${transactionId}, Void ID ${response.voidId}, Status ${response.status}`, { transactionId, response });
106
125
  return response;
107
126
  }
108
127
  catch (error) {
109
- logError(`${this.getGatewayName(method)}: Void payment failed, Transaction ID ${transactionId}`, { transactionId, error });
128
+ logError(`${route.name}: Void payment failed, Transaction ID ${transactionId}`, { transactionId, error });
110
129
  throw error;
111
130
  }
112
131
  }
113
132
  async queryRefund(method, refundId, config) {
114
- const handler = REFUND_QUERY_ROUTING[method];
115
- if (!handler)
116
- throw new ValidationError(`Payment method not supported: ${method}`, method);
133
+ const route = this.getRoute(method);
134
+ if (!route.refundQuery)
135
+ throw new ValidationError(`Refund query not supported for method: ${method}`, method);
117
136
  try {
118
- const response = await handler(refundId, config);
119
- logInfo(`${this.getGatewayName(method)}: Query refund, Refund ID ${refundId}, Status ${response.status}`, { refundId, response });
137
+ const response = await route.refundQuery(refundId, config);
138
+ logInfo(`${route.name}: Query refund, Refund ID ${refundId}, Status ${response.status}`, { refundId, response });
120
139
  return response;
121
140
  }
122
141
  catch (error) {
123
- logError(`${this.getGatewayName(method)}: Query refund failed, Refund ID ${refundId}`, { refundId, error });
142
+ logError(`${route.name}: Query refund failed, Refund ID ${refundId}`, { refundId, error });
124
143
  throw error;
125
144
  }
126
145
  }
127
- // Simulation methods (for testing, returns mock data without calling adapters)
128
146
  simulateCharge(request) {
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);
136
- return {
137
- transactionId,
138
- status: PaymentStatus.Pending,
139
- amount: request.amount,
140
- currency: request.currency,
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
- },
190
- };
191
- }
192
- simulateQuery(transactionId, status, amount = 0, currency = 'SGD') {
193
- const now = new Date();
194
- const invNo = now.toISOString().replace(/[-:T]/g, '').slice(0, 14);
195
- return {
196
- transactionId,
197
- status,
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
- },
241
- };
147
+ const route = this.getRoute(request.method);
148
+ if (!route.simulateCharge)
149
+ throw new ValidationError(`Simulate charge not supported for method: ${request.method}`, request.method);
150
+ return route.simulateCharge(request);
242
151
  }
243
- getGatewayName(method) {
244
- if (method === 'FIUU' || method === 'fiuu-qrcode')
245
- return 'Fiuu';
246
- return method;
152
+ simulateQuery(method, transactionId, status, amount = 0, currency = 'SGD') {
153
+ const route = this.getRoute(method);
154
+ if (!route.simulateQuery)
155
+ throw new ValidationError(`Simulate query not supported for method: ${method}`, method);
156
+ return route.simulateQuery(transactionId, status, amount, currency);
247
157
  }
248
158
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export { LitePosPayment, validateConfig } from './client';
2
2
  export { CancelResponse, PaymentRequest, PaymentResponse, RefundResponse, ValidationResult, VoidResponse, } from './interfaces';
3
- export { Simulator } from './simulator';
4
3
  export type { PaymentConfig } from './types/config';
5
4
  export { PaymentError, ValidationError } from './types/error';
6
5
  export { CancelStatus, PaymentStatus, RefundStatus, VoidStatus } from './types/status';
package/dist/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  // Main exports
2
2
  export { LitePosPayment, validateConfig } from './client';
3
- export { Simulator } from './simulator';
4
3
  export { PaymentError, ValidationError } from './types/error';
5
4
  // Type exports
6
5
  export { CancelStatus, PaymentStatus, RefundStatus, VoidStatus } from './types/status';
package/dist/sqb.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { sqbCheckin } from '@litepos/payment-shouqianba/tools';
package/dist/sqb.js ADDED
@@ -0,0 +1 @@
1
+ export { sqbCheckin } from '@litepos/payment-shouqianba/tools';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@litepos/payment",
3
3
  "type": "module",
4
- "version": "1.0.15",
4
+ "version": "1.0.18",
5
5
  "description": "LitePOS payment gateway SDK - Core package",
6
6
  "author": "",
7
7
  "license": "MIT",
@@ -16,6 +16,11 @@
16
16
  "types": "./dist/index.d.ts",
17
17
  "import": "./dist/index.js",
18
18
  "default": "./dist/index.js"
19
+ },
20
+ "./sqb": {
21
+ "types": "./dist/sqb.d.ts",
22
+ "import": "./dist/sqb.js",
23
+ "default": "./dist/sqb.js"
19
24
  }
20
25
  },
21
26
  "main": "dist/index.js",
@@ -25,7 +30,8 @@
25
30
  "dist"
26
31
  ],
27
32
  "dependencies": {
28
- "@litepos/payment-fiuu": "1.0.15"
33
+ "@litepos/payment-fiuu": "1.0.18",
34
+ "@litepos/payment-shouqianba": "1.0.18"
29
35
  },
30
36
  "devDependencies": {
31
37
  "typescript": "^5.9.2",
@@ -1,7 +0,0 @@
1
- import type { PaymentRequest, PaymentResponse } from './interfaces';
2
- import { PaymentStatus } from './types/status';
3
- export declare class Simulator {
4
- private generateTransactionId;
5
- simulateCharge(request: PaymentRequest): PaymentResponse;
6
- simulateQuery(transactionId: string, status: PaymentStatus): PaymentResponse;
7
- }
package/dist/simulator.js DELETED
@@ -1,30 +0,0 @@
1
- import { PaymentStatus } from './types/status';
2
- // Payment simulator for testing
3
- export class Simulator {
4
- // Generate transaction ID
5
- generateTransactionId() {
6
- return `txn_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
7
- }
8
- // Simulate charge payment
9
- simulateCharge(request) {
10
- return {
11
- transactionId: this.generateTransactionId(),
12
- status: PaymentStatus.Pending,
13
- amount: request.amount,
14
- currency: request.currency,
15
- qrCodeData: request.method.includes('qrcode') ? `QR_${request.orderId}` : undefined,
16
- metadata: request.metadata,
17
- raw: { simulated: true, request },
18
- };
19
- }
20
- // Simulate query payment
21
- simulateQuery(transactionId, status) {
22
- return {
23
- transactionId,
24
- status,
25
- amount: 0,
26
- currency: 'MYR',
27
- raw: { simulated: true },
28
- };
29
- }
30
- }