@litepos/payment 1.0.6
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/LICENSE.md +21 -0
- package/README.md +69 -0
- package/dist/client.d.ts +8 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +70 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +33 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/interfaces.js +3 -0
- package/dist/interfaces.js.map +1 -0
- package/dist/simulator.d.ts +8 -0
- package/dist/simulator.d.ts.map +1 -0
- package/dist/simulator.js +35 -0
- package/dist/simulator.js.map +1 -0
- package/dist/types/error.d.ts +10 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/error.js +23 -0
- package/dist/types/error.js.map +1 -0
- package/dist/types/status.d.ts +12 -0
- package/dist/types/status.d.ts.map +1 -0
- package/dist/types/status.js +19 -0
- package/dist/types/status.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +50 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +31 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-PRESENT Anthony Fu <https://github.com/antfu>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# @litepos/payment
|
|
2
|
+
|
|
3
|
+
LitePOS Payment Gateway SDK - Core package
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is the core package of LitePOS payment gateway SDK. It provides unified interfaces and types for payment gateway integrations.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Unified payment interface for multiple gateways
|
|
12
|
+
- Type-safe payment operations
|
|
13
|
+
- Configuration validation
|
|
14
|
+
- Built-in simulator for testing
|
|
15
|
+
- Extensible adapter system
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @litepos/payment
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { LitePosPayment } from '@litepos/payment'
|
|
27
|
+
|
|
28
|
+
const payment = new LitePosPayment({
|
|
29
|
+
// Configuration will be added when integrations are implemented
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Charge payment
|
|
33
|
+
const result = await payment.charge({
|
|
34
|
+
method: 'fiuu-card',
|
|
35
|
+
amount: 100,
|
|
36
|
+
currency: 'MYR',
|
|
37
|
+
orderId: 'ORDER-001'
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
// Query payment status
|
|
41
|
+
const status = await payment.queryPayment('fiuu-card', result.transactionId)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Architecture
|
|
45
|
+
|
|
46
|
+
This package provides:
|
|
47
|
+
- Core interfaces (`IPaymentAdapter`)
|
|
48
|
+
- Type definitions (`PaymentRequest`, `PaymentResponse`, etc.)
|
|
49
|
+
- Simulator for testing
|
|
50
|
+
- Main client class (`LitePosPayment`) with built-in routing
|
|
51
|
+
|
|
52
|
+
Payment gateway specific implementations are provided by adapter packages (e.g., `@litepos/payment-fiuu`).
|
|
53
|
+
|
|
54
|
+
## Development
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
# 在当前包目录
|
|
58
|
+
pnpm build # Build package
|
|
59
|
+
pnpm test # Run tests
|
|
60
|
+
|
|
61
|
+
# 从根目录运行
|
|
62
|
+
pnpm test # 测试所有包
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Status
|
|
66
|
+
|
|
67
|
+
Current version: 0.0.0 (Initial development)
|
|
68
|
+
|
|
69
|
+
The core package is ready. Payment gateway integrations will be added as separate adapter packages.
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PaymentRequest, PaymentResponse, RefundResponse } from './interfaces';
|
|
2
|
+
export declare class LitePosPayment {
|
|
3
|
+
charge(request: PaymentRequest): Promise<PaymentResponse>;
|
|
4
|
+
queryPayment(method: string, transactionId: string, config: Record<string, unknown>): Promise<PaymentResponse>;
|
|
5
|
+
refund(method: string, transactionId: string, config: Record<string, unknown>, amount?: number): Promise<RefundResponse>;
|
|
6
|
+
private getGatewayName;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AA0BnF,qBAAa,cAAc;IACnB,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,CAAC;IAgBzD,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC;IAgB9G,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB9H,OAAO,CAAC,cAAc;CAKvB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LitePosPayment = void 0;
|
|
4
|
+
const payment_fiuu_1 = require("@litepos/payment-fiuu");
|
|
5
|
+
const error_1 = require("./types/error");
|
|
6
|
+
const logger_1 = require("./utils/logger");
|
|
7
|
+
// Fixed payment method routing
|
|
8
|
+
const CHARGE_ROUTING = {
|
|
9
|
+
'SPCD': payment_fiuu_1.chargeCard,
|
|
10
|
+
'fiuu-qrcode': payment_fiuu_1.chargeQrCode,
|
|
11
|
+
};
|
|
12
|
+
const QUERY_ROUTING = {
|
|
13
|
+
'SPCD': payment_fiuu_1.queryPayment,
|
|
14
|
+
'fiuu-qrcode': payment_fiuu_1.queryPayment,
|
|
15
|
+
};
|
|
16
|
+
const REFUND_ROUTING = {
|
|
17
|
+
'SPCD': payment_fiuu_1.refund,
|
|
18
|
+
'fiuu-qrcode': payment_fiuu_1.refund,
|
|
19
|
+
};
|
|
20
|
+
class LitePosPayment {
|
|
21
|
+
async charge(request) {
|
|
22
|
+
const handler = CHARGE_ROUTING[request.method];
|
|
23
|
+
if (!handler)
|
|
24
|
+
throw new error_1.ValidationError(`Payment method not supported: ${request.method}`, request.method);
|
|
25
|
+
try {
|
|
26
|
+
const response = await handler(request);
|
|
27
|
+
(0, logger_1.logInfo)(`${this.getGatewayName(request.method)}: Charge payment, Order ID ${request.orderId}, Transaction ID ${response.transactionId}, Status ${response.status}`);
|
|
28
|
+
return response;
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
(0, logger_1.logError)(`${this.getGatewayName(request.method)}: Charge payment failed, Order ID ${request.orderId}`, error);
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async queryPayment(method, transactionId, config) {
|
|
36
|
+
const handler = QUERY_ROUTING[method];
|
|
37
|
+
if (!handler)
|
|
38
|
+
throw new error_1.ValidationError(`Payment method not supported: ${method}`, method);
|
|
39
|
+
try {
|
|
40
|
+
const response = await handler(transactionId, config);
|
|
41
|
+
(0, logger_1.logInfo)(`${this.getGatewayName(method)}: Query payment, Transaction ID ${transactionId}, Status ${response.status}`);
|
|
42
|
+
return response;
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
(0, logger_1.logError)(`${this.getGatewayName(method)}: Query payment failed, Transaction ID ${transactionId}`, error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async refund(method, transactionId, config, amount) {
|
|
50
|
+
const handler = REFUND_ROUTING[method];
|
|
51
|
+
if (!handler)
|
|
52
|
+
throw new error_1.ValidationError(`Payment method not supported: ${method}`, method);
|
|
53
|
+
try {
|
|
54
|
+
const response = await handler(transactionId, config, amount);
|
|
55
|
+
(0, logger_1.logInfo)(`${this.getGatewayName(method)}: Refund payment, Transaction ID ${transactionId}, Refund ID ${response.refundId}, Status ${response.status}`);
|
|
56
|
+
return response;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
(0, logger_1.logError)(`${this.getGatewayName(method)}: Refund payment failed, Transaction ID ${transactionId}`, error);
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getGatewayName(method) {
|
|
64
|
+
if (method === 'SPCD' || method === 'fiuu-qrcode')
|
|
65
|
+
return 'Fiuu';
|
|
66
|
+
return method;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.LitePosPayment = LitePosPayment;
|
|
70
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"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"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { LitePosPayment } from './client';
|
|
2
|
+
export { PaymentRequest, PaymentResponse, RefundResponse, ValidationResult, } from './interfaces';
|
|
3
|
+
export { Simulator } from './simulator';
|
|
4
|
+
export { PaymentError, ValidationError } from './types/error';
|
|
5
|
+
export { PaymentStatus, RefundStatus } from './types/status';
|
|
6
|
+
export { logError, logInfo } from './utils/logger';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAEzC,OAAO,EACL,cAAc,EACd,eAAe,EACf,cAAc,EACd,gBAAgB,GACjB,MAAM,cAAc,CAAA;AAErB,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAG7D,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG5D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logInfo = exports.logError = exports.RefundStatus = exports.PaymentStatus = exports.ValidationError = exports.PaymentError = exports.Simulator = exports.LitePosPayment = void 0;
|
|
4
|
+
// Main exports
|
|
5
|
+
var client_1 = require("./client");
|
|
6
|
+
Object.defineProperty(exports, "LitePosPayment", { enumerable: true, get: function () { return client_1.LitePosPayment; } });
|
|
7
|
+
var simulator_1 = require("./simulator");
|
|
8
|
+
Object.defineProperty(exports, "Simulator", { enumerable: true, get: function () { return simulator_1.Simulator; } });
|
|
9
|
+
var error_1 = require("./types/error");
|
|
10
|
+
Object.defineProperty(exports, "PaymentError", { enumerable: true, get: function () { return error_1.PaymentError; } });
|
|
11
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return error_1.ValidationError; } });
|
|
12
|
+
// Type exports
|
|
13
|
+
var status_1 = require("./types/status");
|
|
14
|
+
Object.defineProperty(exports, "PaymentStatus", { enumerable: true, get: function () { return status_1.PaymentStatus; } });
|
|
15
|
+
Object.defineProperty(exports, "RefundStatus", { enumerable: true, get: function () { return status_1.RefundStatus; } });
|
|
16
|
+
// Logger exports
|
|
17
|
+
var logger_1 = require("./utils/logger");
|
|
18
|
+
Object.defineProperty(exports, "logError", { enumerable: true, get: function () { return logger_1.logError; } });
|
|
19
|
+
Object.defineProperty(exports, "logInfo", { enumerable: true, get: function () { return logger_1.logInfo; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACf,mCAAyC;AAAhC,wGAAA,cAAc,OAAA;AASvB,yCAAuC;AAA9B,sGAAA,SAAS,OAAA;AAClB,uCAA6D;AAApD,qGAAA,YAAY,OAAA;AAAE,wGAAA,eAAe,OAAA;AAEtC,eAAe;AACf,yCAA4D;AAAnD,uGAAA,aAAa,OAAA;AAAE,sGAAA,YAAY,OAAA;AAEpC,iBAAiB;AACjB,yCAAkD;AAAzC,kGAAA,QAAQ,OAAA;AAAE,iGAAA,OAAO,OAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { PaymentStatus, RefundStatus } from './types/status';
|
|
2
|
+
export interface PaymentRequest {
|
|
3
|
+
method: string;
|
|
4
|
+
amount: number;
|
|
5
|
+
currency: string;
|
|
6
|
+
orderId: string;
|
|
7
|
+
config: Record<string, unknown>;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface PaymentResponse {
|
|
11
|
+
transactionId: string;
|
|
12
|
+
status: PaymentStatus;
|
|
13
|
+
amount: number;
|
|
14
|
+
currency: string;
|
|
15
|
+
qrCodeData?: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
raw?: unknown;
|
|
18
|
+
}
|
|
19
|
+
export interface RefundResponse {
|
|
20
|
+
refundId: string;
|
|
21
|
+
transactionId: string;
|
|
22
|
+
status: RefundStatus;
|
|
23
|
+
amount: number;
|
|
24
|
+
currency: string;
|
|
25
|
+
refundedAt?: Date;
|
|
26
|
+
metadata?: Record<string, unknown>;
|
|
27
|
+
raw?: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface ValidationResult {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
errors?: string[];
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=interfaces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAGjE,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAGD,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,aAAa,CAAA;IACrB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAGD,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,YAAY,CAAA;IACpB,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,IAAI,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAClC,GAAG,CAAC,EAAE,OAAO,CAAA;CACd;AAGD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
8
|
+
//# sourceMappingURL=simulator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulator.d.ts","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG9C,qBAAa,SAAS;IAEpB,OAAO,CAAC,qBAAqB;IAK7B,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,eAAe;IAaxD,aAAa,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,GAAG,eAAe;CAS7E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Simulator = void 0;
|
|
4
|
+
const status_1 = require("./types/status");
|
|
5
|
+
// Payment simulator for testing
|
|
6
|
+
class Simulator {
|
|
7
|
+
// Generate transaction ID
|
|
8
|
+
generateTransactionId() {
|
|
9
|
+
return `txn_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
10
|
+
}
|
|
11
|
+
// Simulate charge payment
|
|
12
|
+
simulateCharge(request) {
|
|
13
|
+
return {
|
|
14
|
+
transactionId: this.generateTransactionId(),
|
|
15
|
+
status: status_1.PaymentStatus.Pending,
|
|
16
|
+
amount: request.amount,
|
|
17
|
+
currency: request.currency,
|
|
18
|
+
qrCodeData: request.method.includes('qrcode') ? `QR_${request.orderId}` : undefined,
|
|
19
|
+
metadata: request.metadata,
|
|
20
|
+
raw: { simulated: true, request },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// Simulate query payment
|
|
24
|
+
simulateQuery(transactionId, status) {
|
|
25
|
+
return {
|
|
26
|
+
transactionId,
|
|
27
|
+
status,
|
|
28
|
+
amount: 0,
|
|
29
|
+
currency: 'MYR',
|
|
30
|
+
raw: { simulated: true },
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.Simulator = Simulator;
|
|
35
|
+
//# sourceMappingURL=simulator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"simulator.js","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAE9C,gCAAgC;AAChC,MAAa,SAAS;IACpB,0BAA0B;IAClB,qBAAqB;QAC3B,OAAO,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAA;IACvE,CAAC;IAED,0BAA0B;IAC1B,cAAc,CAAC,OAAuB;QACpC,OAAO;YACL,aAAa,EAAE,IAAI,CAAC,qBAAqB,EAAE;YAC3C,MAAM,EAAE,sBAAa,CAAC,OAAO;YAC7B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS;YACnF,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;SAClC,CAAA;IACH,CAAC;IAED,yBAAyB;IACzB,aAAa,CAAC,aAAqB,EAAE,MAAqB;QACxD,OAAO;YACL,aAAa;YACb,MAAM;YACN,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,KAAK;YACf,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;SACzB,CAAA;IACH,CAAC;CACF;AA7BD,8BA6BC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class PaymentError extends Error {
|
|
2
|
+
code: string;
|
|
3
|
+
method: string;
|
|
4
|
+
originalError?: any | undefined;
|
|
5
|
+
constructor(code: string, message: string, method: string, originalError?: any | undefined);
|
|
6
|
+
}
|
|
7
|
+
export declare class ValidationError extends PaymentError {
|
|
8
|
+
constructor(message: string, method: string, originalError?: any);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":"AACA,qBAAa,YAAa,SAAQ,KAAK;IAE5B,IAAI,EAAE,MAAM;IAEZ,MAAM,EAAE,MAAM;IACd,aAAa,CAAC,EAAE,GAAG;gBAHnB,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACR,MAAM,EAAE,MAAM,EACd,aAAa,CAAC,EAAE,GAAG,YAAA;CAK7B;AAGD,qBAAa,eAAgB,SAAQ,YAAY;gBACnC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,GAAG;CAIjE"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationError = exports.PaymentError = void 0;
|
|
4
|
+
// Base error class for payment errors
|
|
5
|
+
class PaymentError extends Error {
|
|
6
|
+
constructor(code, message, method, originalError) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.code = code;
|
|
9
|
+
this.method = method;
|
|
10
|
+
this.originalError = originalError;
|
|
11
|
+
this.name = 'PaymentError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.PaymentError = PaymentError;
|
|
15
|
+
// Validation errors
|
|
16
|
+
class ValidationError extends PaymentError {
|
|
17
|
+
constructor(message, method, originalError) {
|
|
18
|
+
super('VALIDATION_ERROR', message, method, originalError);
|
|
19
|
+
this.name = 'ValidationError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.ValidationError = ValidationError;
|
|
23
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,MAAa,YAAa,SAAQ,KAAK;IACrC,YACS,IAAY,EACnB,OAAe,EACR,MAAc,EACd,aAAmB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAA;QALP,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAQ;QACd,kBAAa,GAAb,aAAa,CAAM;QAG1B,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF;AAVD,oCAUC;AAED,oBAAoB;AACpB,MAAa,eAAgB,SAAQ,YAAY;IAC/C,YAAY,OAAe,EAAE,MAAc,EAAE,aAAmB;QAC9D,KAAK,CAAC,kBAAkB,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,CAAA;QACzD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAA;IAC/B,CAAC;CACF;AALD,0CAKC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum PaymentStatus {
|
|
2
|
+
Pending = "pending",
|
|
3
|
+
Success = "success",
|
|
4
|
+
Failed = "failed",
|
|
5
|
+
Cancelled = "cancelled"
|
|
6
|
+
}
|
|
7
|
+
export declare enum RefundStatus {
|
|
8
|
+
Pending = "pending",
|
|
9
|
+
Success = "success",
|
|
10
|
+
Failed = "failed"
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/types/status.ts"],"names":[],"mappings":"AACA,oBAAY,aAAa;IACvB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,SAAS,cAAc;CACxB;AAGD,oBAAY,YAAY;IACtB,OAAO,YAAY;IACnB,OAAO,YAAY;IACnB,MAAM,WAAW;CAClB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RefundStatus = exports.PaymentStatus = void 0;
|
|
4
|
+
// Payment status enumeration
|
|
5
|
+
var PaymentStatus;
|
|
6
|
+
(function (PaymentStatus) {
|
|
7
|
+
PaymentStatus["Pending"] = "pending";
|
|
8
|
+
PaymentStatus["Success"] = "success";
|
|
9
|
+
PaymentStatus["Failed"] = "failed";
|
|
10
|
+
PaymentStatus["Cancelled"] = "cancelled";
|
|
11
|
+
})(PaymentStatus || (exports.PaymentStatus = PaymentStatus = {}));
|
|
12
|
+
// Refund status enumeration
|
|
13
|
+
var RefundStatus;
|
|
14
|
+
(function (RefundStatus) {
|
|
15
|
+
RefundStatus["Pending"] = "pending";
|
|
16
|
+
RefundStatus["Success"] = "success";
|
|
17
|
+
RefundStatus["Failed"] = "failed";
|
|
18
|
+
})(RefundStatus || (exports.RefundStatus = RefundStatus = {}));
|
|
19
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/types/status.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,IAAY,aAKX;AALD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,oCAAmB,CAAA;IACnB,kCAAiB,CAAA;IACjB,wCAAuB,CAAA;AACzB,CAAC,EALW,aAAa,6BAAb,aAAa,QAKxB;AAED,4BAA4B;AAC5B,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,mCAAmB,CAAA;IACnB,mCAAmB,CAAA;IACnB,iCAAiB,CAAA;AACnB,CAAC,EAJW,YAAY,4BAAZ,YAAY,QAIvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AA2BA,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAEzE;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,IAAI,CAe3D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logInfo = logInfo;
|
|
7
|
+
exports.logError = logError;
|
|
8
|
+
const node_process_1 = __importDefault(require("node:process"));
|
|
9
|
+
// Fixed logger configuration
|
|
10
|
+
const LOG_ENDPOINT = 'https://logs.xposhq.com/';
|
|
11
|
+
const LOG_API_KEY = 'nRXpIXTQ2TVIAHaSntyjfvQB90LI3LGYgXayDe7URGvXkQfGiR';
|
|
12
|
+
const LOG_SERVICE = 'litepos-integrations';
|
|
13
|
+
function sendLog(data) {
|
|
14
|
+
const logPayload = {
|
|
15
|
+
message: data.message || '',
|
|
16
|
+
...data,
|
|
17
|
+
ddsource: 'node.js',
|
|
18
|
+
service: LOG_SERVICE,
|
|
19
|
+
env: node_process_1.default.env.NODE_ENV || 'development',
|
|
20
|
+
timestamp: new Date().toISOString(),
|
|
21
|
+
};
|
|
22
|
+
fetch(LOG_ENDPOINT, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
'Authorization': `Bearer ${LOG_API_KEY}`,
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify(logPayload),
|
|
29
|
+
}).catch(() => { });
|
|
30
|
+
}
|
|
31
|
+
function logInfo(message, info) {
|
|
32
|
+
sendLog({ message, level: 'info', ...info });
|
|
33
|
+
}
|
|
34
|
+
function logError(message, error) {
|
|
35
|
+
const errorData = { message, level: 'error', status: 'error' };
|
|
36
|
+
if (error) {
|
|
37
|
+
if (error instanceof Error) {
|
|
38
|
+
errorData.error = {
|
|
39
|
+
name: error.name,
|
|
40
|
+
message: error.message,
|
|
41
|
+
stack: error.stack,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
errorData.error = error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
sendLog(errorData);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;;;AA2BA,0BAEC;AAED,4BAeC;AA9CD,gEAAkC;AAElC,6BAA6B;AAC7B,MAAM,YAAY,GAAG,0BAA0B,CAAA;AAC/C,MAAM,WAAW,GAAG,oDAAoD,CAAA;AACxE,MAAM,WAAW,GAAG,sBAAsB,CAAA;AAE1C,SAAS,OAAO,CAAC,IAAyB;IACxC,MAAM,UAAU,GAAG;QACjB,OAAO,EAAE,IAAI,CAAC,OAAO,IAAI,EAAE;QAC3B,GAAG,IAAI;QACP,QAAQ,EAAE,SAAS;QACnB,OAAO,EAAE,WAAW;QACpB,GAAG,EAAE,sBAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa;QAC1C,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACpC,CAAA;IAED,KAAK,CAAC,YAAY,EAAE;QAClB,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,UAAU,WAAW,EAAE;SACzC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;KACjC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAA;AACpB,CAAC;AAED,SAAgB,OAAO,CAAC,OAAe,EAAE,IAA0B;IACjE,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,CAAA;AAC9C,CAAC;AAED,SAAgB,QAAQ,CAAC,OAAe,EAAE,KAAW;IACnD,MAAM,SAAS,GAAwB,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAA;IACnF,IAAI,KAAK,EAAE,CAAC;QACV,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,SAAS,CAAC,KAAK,GAAG;gBAChB,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,CAAA;QACH,CAAC;aACI,CAAC;YACJ,SAAS,CAAC,KAAK,GAAG,KAAK,CAAA;QACzB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,SAAS,CAAC,CAAA;AACpB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@litepos/payment",
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "LitePOS payment gateway SDK - Core package",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"litepos",
|
|
9
|
+
"payment",
|
|
10
|
+
"gateway",
|
|
11
|
+
"sdk"
|
|
12
|
+
],
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@litepos/payment-fiuu": "1.0.6"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"typescript": "^5.9.2",
|
|
23
|
+
"vitest": "^3.2.4"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"clean": "rimraf dist",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"typecheck": "tsc --noEmit"
|
|
30
|
+
}
|
|
31
|
+
}
|