aba-payway 0.1.0 → 0.2.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/LICENSE +1 -1
- package/README.md +78 -5
- package/dist/index.cjs +258 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +184 -24
- package/dist/index.d.ts +184 -24
- package/dist/index.js +257 -26
- package/dist/index.js.map +1 -1
- package/package.json +5 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
type Environment = "sandbox" | "production";
|
|
1
2
|
interface PayWayConfig {
|
|
2
|
-
merchantId: string;
|
|
3
|
-
apiKey: string;
|
|
4
|
-
|
|
3
|
+
readonly merchantId: string;
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
/** Target environment. Default: `"sandbox"`. */
|
|
6
|
+
readonly environment?: Environment;
|
|
7
|
+
/** Override the base URL directly. Takes priority over `environment`. */
|
|
8
|
+
readonly baseUrl?: string;
|
|
9
|
+
/** Request timeout in milliseconds. Default: 30000 (30s). */
|
|
10
|
+
readonly timeout?: number;
|
|
5
11
|
}
|
|
6
12
|
type PaymentOption = "cards" | "abapay_khqr" | "abapay_khqr_deeplink" | "alipay" | "wechat" | "google_pay";
|
|
7
13
|
type Currency = "USD" | "KHR";
|
|
@@ -70,15 +76,13 @@ interface CheckoutParams {
|
|
|
70
76
|
view_type: string;
|
|
71
77
|
payment_gate: string;
|
|
72
78
|
}
|
|
73
|
-
interface CheckTransactionOptions {
|
|
74
|
-
transactionId: string;
|
|
75
|
-
}
|
|
76
79
|
interface ListTransactionsOptions {
|
|
77
80
|
fromDate?: string;
|
|
78
81
|
toDate?: string;
|
|
79
82
|
fromAmount?: number;
|
|
80
83
|
toAmount?: number;
|
|
81
|
-
status
|
|
84
|
+
/** Single status or comma-separated: e.g. `"APPROVED"` or `"APPROVED,DECLINED"` */
|
|
85
|
+
status?: TransactionStatus | (string & {});
|
|
82
86
|
page?: number;
|
|
83
87
|
pagination?: number;
|
|
84
88
|
}
|
|
@@ -99,24 +103,24 @@ interface CheckTransactionData {
|
|
|
99
103
|
refund_amount: number;
|
|
100
104
|
discount_amount: number;
|
|
101
105
|
payment_amount: number;
|
|
102
|
-
payment_currency:
|
|
106
|
+
payment_currency: Currency;
|
|
103
107
|
apv: string;
|
|
104
|
-
payment_status:
|
|
108
|
+
payment_status: TransactionStatus;
|
|
105
109
|
transaction_date: string;
|
|
106
110
|
}
|
|
107
111
|
interface TransactionListItem {
|
|
108
112
|
transaction_id: string;
|
|
109
113
|
transaction_date: string;
|
|
110
114
|
apv: string;
|
|
111
|
-
payment_status:
|
|
115
|
+
payment_status: TransactionStatus;
|
|
112
116
|
payment_status_code: number;
|
|
113
117
|
original_amount: number;
|
|
114
|
-
original_currency:
|
|
118
|
+
original_currency: Currency;
|
|
115
119
|
total_amount: number;
|
|
116
120
|
discount_amount: number;
|
|
117
121
|
refund_amount: number;
|
|
118
122
|
payment_amount: number;
|
|
119
|
-
payment_currency:
|
|
123
|
+
payment_currency: Currency;
|
|
120
124
|
first_name: string;
|
|
121
125
|
last_name: string;
|
|
122
126
|
email: string;
|
|
@@ -127,61 +131,217 @@ interface TransactionListItem {
|
|
|
127
131
|
card_source: string;
|
|
128
132
|
payment_type: string;
|
|
129
133
|
}
|
|
130
|
-
interface ListTransactionsData {
|
|
131
|
-
data: TransactionListItem[];
|
|
132
|
-
page: string;
|
|
133
|
-
pagination: string;
|
|
134
|
-
}
|
|
135
134
|
interface ListTransactionsResponse {
|
|
136
135
|
data: TransactionListItem[];
|
|
137
136
|
page: string;
|
|
138
137
|
pagination: string;
|
|
139
138
|
status: PayWayResponseStatus;
|
|
140
139
|
}
|
|
140
|
+
interface CloseTransactionResponse {
|
|
141
|
+
status: PayWayResponseStatus;
|
|
142
|
+
}
|
|
143
|
+
interface TransactionOperation {
|
|
144
|
+
status: string;
|
|
145
|
+
amount: number;
|
|
146
|
+
transaction_date: string;
|
|
147
|
+
bank_ref: string;
|
|
148
|
+
}
|
|
149
|
+
interface TransactionDetailData {
|
|
150
|
+
transaction_id: string;
|
|
151
|
+
payment_status_code: number;
|
|
152
|
+
payment_status: TransactionStatus;
|
|
153
|
+
original_amount: number;
|
|
154
|
+
original_currency: Currency;
|
|
155
|
+
payment_amount: number;
|
|
156
|
+
payment_currency: Currency;
|
|
157
|
+
total_amount: number;
|
|
158
|
+
refund_amount: number;
|
|
159
|
+
discount_amount: number;
|
|
160
|
+
apv: string;
|
|
161
|
+
transaction_date: string;
|
|
162
|
+
first_name: string;
|
|
163
|
+
last_name: string;
|
|
164
|
+
email: string;
|
|
165
|
+
phone: string;
|
|
166
|
+
bank_ref: string;
|
|
167
|
+
payment_type: string;
|
|
168
|
+
payer_account: string;
|
|
169
|
+
bank_name: string;
|
|
170
|
+
card_source: string;
|
|
171
|
+
transaction_operations: TransactionOperation[];
|
|
172
|
+
}
|
|
173
|
+
type ExchangeRateCurrency = "aud" | "sgd" | "eur" | "gbp" | "myr" | "thb" | "hkd" | "cny" | "cad" | "krw" | "jpy" | "vnd";
|
|
174
|
+
interface ExchangeRate {
|
|
175
|
+
sell: string;
|
|
176
|
+
buy: string;
|
|
177
|
+
}
|
|
178
|
+
interface ExchangeRateResponse {
|
|
179
|
+
status: PayWayResponseStatus;
|
|
180
|
+
exchange_rates: Partial<Record<ExchangeRateCurrency, ExchangeRate>>;
|
|
181
|
+
}
|
|
182
|
+
type QRPaymentOption = "abapay_khqr" | "wechat" | "alipay";
|
|
183
|
+
interface GenerateQROptions {
|
|
184
|
+
transactionId: string;
|
|
185
|
+
amount: number;
|
|
186
|
+
currency?: Currency;
|
|
187
|
+
paymentOption: QRPaymentOption;
|
|
188
|
+
lifetime?: number;
|
|
189
|
+
qrImageTemplate: string;
|
|
190
|
+
firstName?: string;
|
|
191
|
+
lastName?: string;
|
|
192
|
+
email?: string;
|
|
193
|
+
phone?: string;
|
|
194
|
+
purchaseType?: TransactionType;
|
|
195
|
+
items?: string;
|
|
196
|
+
callbackUrl?: string;
|
|
197
|
+
returnDeeplink?: string;
|
|
198
|
+
customFields?: string;
|
|
199
|
+
returnParams?: string;
|
|
200
|
+
payout?: string;
|
|
201
|
+
}
|
|
202
|
+
interface GenerateQRResponse {
|
|
203
|
+
status: PayWayResponseStatus & {
|
|
204
|
+
trace_id?: string;
|
|
205
|
+
};
|
|
206
|
+
amount: number;
|
|
207
|
+
currency: Currency;
|
|
208
|
+
qrString: string;
|
|
209
|
+
qrImage: string;
|
|
210
|
+
abapay_deeplink: string;
|
|
211
|
+
app_store: string;
|
|
212
|
+
play_store: string;
|
|
213
|
+
}
|
|
214
|
+
interface TransactionByRefItem {
|
|
215
|
+
transaction_id: string;
|
|
216
|
+
transaction_date: string;
|
|
217
|
+
apv: string;
|
|
218
|
+
payment_status: TransactionStatus;
|
|
219
|
+
payment_status_code: number;
|
|
220
|
+
original_amount: number;
|
|
221
|
+
original_currency: Currency;
|
|
222
|
+
total_amount: number;
|
|
223
|
+
discount_amount: number;
|
|
224
|
+
refund_amount: number;
|
|
225
|
+
payment_amount: number;
|
|
226
|
+
payment_currency: Currency;
|
|
227
|
+
bank_ref: string;
|
|
228
|
+
payer_account: string;
|
|
229
|
+
bank_name: string;
|
|
230
|
+
payment_type: string;
|
|
231
|
+
merchant_ref: string;
|
|
232
|
+
}
|
|
233
|
+
interface GetTransactionsByRefResponse {
|
|
234
|
+
data: TransactionByRefItem[];
|
|
235
|
+
status: PayWayResponseStatus;
|
|
236
|
+
}
|
|
141
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Main SDK client for ABA PayWay.
|
|
240
|
+
* Provides methods for creating transactions, checking status, and listing transactions.
|
|
241
|
+
*/
|
|
142
242
|
declare class PayWay {
|
|
143
243
|
private readonly merchantId;
|
|
144
244
|
private readonly apiKey;
|
|
145
245
|
private readonly baseUrl;
|
|
246
|
+
private readonly timeout;
|
|
247
|
+
/**
|
|
248
|
+
* @param config - Merchant credentials and environment selection.
|
|
249
|
+
* @throws {PayWayConfigError} If `merchantId` or `apiKey` is empty.
|
|
250
|
+
*/
|
|
146
251
|
constructor(config: PayWayConfig);
|
|
147
252
|
/**
|
|
148
253
|
* Generate checkout parameters for a transaction.
|
|
149
254
|
* Returns form params to be submitted from the browser via ABA's checkout JS SDK.
|
|
150
255
|
*/
|
|
151
256
|
createTransaction(options: CreateTransactionOptions): CheckoutParams;
|
|
257
|
+
/**
|
|
258
|
+
* Check the status of a transaction.
|
|
259
|
+
* @param transactionId - The unique transaction ID to look up.
|
|
260
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
261
|
+
*/
|
|
152
262
|
checkTransaction(transactionId: string): Promise<PayWayResponse<CheckTransactionData>>;
|
|
263
|
+
/**
|
|
264
|
+
* List transactions with optional filters. Max 3-day date range.
|
|
265
|
+
* @param options - Filter and pagination options.
|
|
266
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
267
|
+
*/
|
|
153
268
|
listTransactions(options?: ListTransactionsOptions): Promise<ListTransactionsResponse>;
|
|
269
|
+
/**
|
|
270
|
+
* Get detailed information about a transaction, including its operation history.
|
|
271
|
+
* @param transactionId - The unique transaction ID to look up.
|
|
272
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
273
|
+
*/
|
|
274
|
+
getTransactionDetails(transactionId: string): Promise<PayWayResponse<TransactionDetailData>>;
|
|
275
|
+
/**
|
|
276
|
+
* Close (cancel) a pending transaction.
|
|
277
|
+
* @param transactionId - The transaction ID to close.
|
|
278
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
279
|
+
*/
|
|
280
|
+
closeTransaction(transactionId: string): Promise<CloseTransactionResponse>;
|
|
281
|
+
/**
|
|
282
|
+
* Fetch the latest exchange rates from ABA Bank.
|
|
283
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
284
|
+
*/
|
|
285
|
+
getExchangeRate(): Promise<ExchangeRateResponse>;
|
|
286
|
+
/**
|
|
287
|
+
* Generate a QR code for payment via ABA KHQR, WeChat Pay, or Alipay.
|
|
288
|
+
* @param options - QR generation options.
|
|
289
|
+
* @throws {PayWayConfigError} If required options are missing or invalid.
|
|
290
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
291
|
+
*/
|
|
292
|
+
generateQR(options: GenerateQROptions): Promise<GenerateQRResponse>;
|
|
293
|
+
/**
|
|
294
|
+
* Get transactions by merchant reference. Returns up to the last 50 transactions.
|
|
295
|
+
* @param merchantRef - Your merchant reference number.
|
|
296
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
297
|
+
*/
|
|
298
|
+
getTransactionsByRef(merchantRef: string): Promise<GetTransactionsByRefResponse>;
|
|
154
299
|
private request;
|
|
155
300
|
}
|
|
156
301
|
|
|
157
|
-
declare const
|
|
158
|
-
declare const
|
|
302
|
+
declare const BASE_URLS: Record<Environment, string>;
|
|
303
|
+
declare const SANDBOX_BASE_URL: string;
|
|
304
|
+
declare const PRODUCTION_BASE_URL: string;
|
|
159
305
|
declare const ENDPOINTS: {
|
|
160
306
|
readonly purchase: "/api/payment-gateway/v1/payments/purchase";
|
|
161
307
|
readonly checkTransaction: "/api/payment-gateway/v1/payments/check-transaction-2";
|
|
162
308
|
readonly transactionList: "/api/payment-gateway/v1/payments/transaction-list-2";
|
|
309
|
+
readonly transactionDetail: "/api/payment-gateway/v1/payments/transaction-detail";
|
|
310
|
+
readonly closeTransaction: "/api/payment-gateway/v1/payments/close-transaction";
|
|
311
|
+
readonly exchangeRate: "/api/payment-gateway/v1/exchange-rate";
|
|
312
|
+
readonly generateQR: "/api/payment-gateway/v1/payments/generate-qr";
|
|
313
|
+
readonly getTransactionsByRef: "/api/payment-gateway/v1/payments/get-transactions-by-mc-ref";
|
|
163
314
|
};
|
|
164
315
|
|
|
316
|
+
/** Base error class for all PayWay SDK errors. */
|
|
165
317
|
declare class PayWayError extends Error {
|
|
166
|
-
constructor(message: string);
|
|
318
|
+
constructor(message: string, options?: ErrorOptions);
|
|
167
319
|
}
|
|
320
|
+
/** Thrown when the ABA PayWay API returns a non-2xx HTTP response. */
|
|
168
321
|
declare class PayWayAPIError extends PayWayError {
|
|
169
322
|
readonly statusCode: number;
|
|
170
323
|
readonly responseBody: unknown;
|
|
171
324
|
constructor(message: string, statusCode: number, responseBody?: unknown);
|
|
172
325
|
}
|
|
326
|
+
/** Thrown when the SDK is constructed with missing or invalid configuration. */
|
|
173
327
|
declare class PayWayConfigError extends PayWayError {
|
|
174
328
|
constructor(message: string);
|
|
175
329
|
}
|
|
330
|
+
/** Thrown when HMAC hash generation fails. */
|
|
176
331
|
declare class PayWayHashError extends PayWayError {
|
|
177
332
|
constructor(message: string);
|
|
178
333
|
}
|
|
179
334
|
|
|
180
|
-
|
|
335
|
+
/** Generate an HMAC-SHA512 hash from concatenated values, returned as a base64 string. */
|
|
336
|
+
declare function createHash(values: readonly string[], apiKey: string): string;
|
|
181
337
|
|
|
338
|
+
/** Format a Date as `yyyyMMddHHmmss` in UTC, used for ABA's `req_time` parameter. */
|
|
182
339
|
declare function formatRequestTime(date?: Date): string;
|
|
183
|
-
|
|
184
|
-
declare function
|
|
340
|
+
/** Build a FormData object from a record, skipping `undefined`, `null`, and empty string values. */
|
|
341
|
+
declare function buildFormData(params: object): FormData;
|
|
342
|
+
/** Format a numeric amount as a string: 2 decimal places for USD, rounded integer for KHR. */
|
|
343
|
+
declare function formatAmount(amount: number, currency?: Currency): string;
|
|
344
|
+
/** Base64-encode a string value using Node.js Buffer. */
|
|
185
345
|
declare function toBase64(value: string): string;
|
|
186
346
|
|
|
187
|
-
export { type CheckTransactionData, type
|
|
347
|
+
export { BASE_URLS, type CheckTransactionData, type CheckoutParams, type CloseTransactionResponse, type CreateTransactionOptions, type Currency, ENDPOINTS, type Environment, type ExchangeRate, type ExchangeRateCurrency, type ExchangeRateResponse, type GenerateQROptions, type GenerateQRResponse, type GetTransactionsByRefResponse, type ItemEntry, type ListTransactionsOptions, type ListTransactionsResponse, PRODUCTION_BASE_URL, PayWay, PayWayAPIError, type PayWayConfig, PayWayConfigError, PayWayError, PayWayHashError, type PayWayResponse, type PayWayResponseStatus, type PaymentOption, type QRPaymentOption, SANDBOX_BASE_URL, type TransactionByRefItem, type TransactionDetailData, type TransactionListItem, type TransactionOperation, type TransactionStatus, type TransactionType, buildFormData, createHash, formatAmount, formatRequestTime, toBase64 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
type Environment = "sandbox" | "production";
|
|
1
2
|
interface PayWayConfig {
|
|
2
|
-
merchantId: string;
|
|
3
|
-
apiKey: string;
|
|
4
|
-
|
|
3
|
+
readonly merchantId: string;
|
|
4
|
+
readonly apiKey: string;
|
|
5
|
+
/** Target environment. Default: `"sandbox"`. */
|
|
6
|
+
readonly environment?: Environment;
|
|
7
|
+
/** Override the base URL directly. Takes priority over `environment`. */
|
|
8
|
+
readonly baseUrl?: string;
|
|
9
|
+
/** Request timeout in milliseconds. Default: 30000 (30s). */
|
|
10
|
+
readonly timeout?: number;
|
|
5
11
|
}
|
|
6
12
|
type PaymentOption = "cards" | "abapay_khqr" | "abapay_khqr_deeplink" | "alipay" | "wechat" | "google_pay";
|
|
7
13
|
type Currency = "USD" | "KHR";
|
|
@@ -70,15 +76,13 @@ interface CheckoutParams {
|
|
|
70
76
|
view_type: string;
|
|
71
77
|
payment_gate: string;
|
|
72
78
|
}
|
|
73
|
-
interface CheckTransactionOptions {
|
|
74
|
-
transactionId: string;
|
|
75
|
-
}
|
|
76
79
|
interface ListTransactionsOptions {
|
|
77
80
|
fromDate?: string;
|
|
78
81
|
toDate?: string;
|
|
79
82
|
fromAmount?: number;
|
|
80
83
|
toAmount?: number;
|
|
81
|
-
status
|
|
84
|
+
/** Single status or comma-separated: e.g. `"APPROVED"` or `"APPROVED,DECLINED"` */
|
|
85
|
+
status?: TransactionStatus | (string & {});
|
|
82
86
|
page?: number;
|
|
83
87
|
pagination?: number;
|
|
84
88
|
}
|
|
@@ -99,24 +103,24 @@ interface CheckTransactionData {
|
|
|
99
103
|
refund_amount: number;
|
|
100
104
|
discount_amount: number;
|
|
101
105
|
payment_amount: number;
|
|
102
|
-
payment_currency:
|
|
106
|
+
payment_currency: Currency;
|
|
103
107
|
apv: string;
|
|
104
|
-
payment_status:
|
|
108
|
+
payment_status: TransactionStatus;
|
|
105
109
|
transaction_date: string;
|
|
106
110
|
}
|
|
107
111
|
interface TransactionListItem {
|
|
108
112
|
transaction_id: string;
|
|
109
113
|
transaction_date: string;
|
|
110
114
|
apv: string;
|
|
111
|
-
payment_status:
|
|
115
|
+
payment_status: TransactionStatus;
|
|
112
116
|
payment_status_code: number;
|
|
113
117
|
original_amount: number;
|
|
114
|
-
original_currency:
|
|
118
|
+
original_currency: Currency;
|
|
115
119
|
total_amount: number;
|
|
116
120
|
discount_amount: number;
|
|
117
121
|
refund_amount: number;
|
|
118
122
|
payment_amount: number;
|
|
119
|
-
payment_currency:
|
|
123
|
+
payment_currency: Currency;
|
|
120
124
|
first_name: string;
|
|
121
125
|
last_name: string;
|
|
122
126
|
email: string;
|
|
@@ -127,61 +131,217 @@ interface TransactionListItem {
|
|
|
127
131
|
card_source: string;
|
|
128
132
|
payment_type: string;
|
|
129
133
|
}
|
|
130
|
-
interface ListTransactionsData {
|
|
131
|
-
data: TransactionListItem[];
|
|
132
|
-
page: string;
|
|
133
|
-
pagination: string;
|
|
134
|
-
}
|
|
135
134
|
interface ListTransactionsResponse {
|
|
136
135
|
data: TransactionListItem[];
|
|
137
136
|
page: string;
|
|
138
137
|
pagination: string;
|
|
139
138
|
status: PayWayResponseStatus;
|
|
140
139
|
}
|
|
140
|
+
interface CloseTransactionResponse {
|
|
141
|
+
status: PayWayResponseStatus;
|
|
142
|
+
}
|
|
143
|
+
interface TransactionOperation {
|
|
144
|
+
status: string;
|
|
145
|
+
amount: number;
|
|
146
|
+
transaction_date: string;
|
|
147
|
+
bank_ref: string;
|
|
148
|
+
}
|
|
149
|
+
interface TransactionDetailData {
|
|
150
|
+
transaction_id: string;
|
|
151
|
+
payment_status_code: number;
|
|
152
|
+
payment_status: TransactionStatus;
|
|
153
|
+
original_amount: number;
|
|
154
|
+
original_currency: Currency;
|
|
155
|
+
payment_amount: number;
|
|
156
|
+
payment_currency: Currency;
|
|
157
|
+
total_amount: number;
|
|
158
|
+
refund_amount: number;
|
|
159
|
+
discount_amount: number;
|
|
160
|
+
apv: string;
|
|
161
|
+
transaction_date: string;
|
|
162
|
+
first_name: string;
|
|
163
|
+
last_name: string;
|
|
164
|
+
email: string;
|
|
165
|
+
phone: string;
|
|
166
|
+
bank_ref: string;
|
|
167
|
+
payment_type: string;
|
|
168
|
+
payer_account: string;
|
|
169
|
+
bank_name: string;
|
|
170
|
+
card_source: string;
|
|
171
|
+
transaction_operations: TransactionOperation[];
|
|
172
|
+
}
|
|
173
|
+
type ExchangeRateCurrency = "aud" | "sgd" | "eur" | "gbp" | "myr" | "thb" | "hkd" | "cny" | "cad" | "krw" | "jpy" | "vnd";
|
|
174
|
+
interface ExchangeRate {
|
|
175
|
+
sell: string;
|
|
176
|
+
buy: string;
|
|
177
|
+
}
|
|
178
|
+
interface ExchangeRateResponse {
|
|
179
|
+
status: PayWayResponseStatus;
|
|
180
|
+
exchange_rates: Partial<Record<ExchangeRateCurrency, ExchangeRate>>;
|
|
181
|
+
}
|
|
182
|
+
type QRPaymentOption = "abapay_khqr" | "wechat" | "alipay";
|
|
183
|
+
interface GenerateQROptions {
|
|
184
|
+
transactionId: string;
|
|
185
|
+
amount: number;
|
|
186
|
+
currency?: Currency;
|
|
187
|
+
paymentOption: QRPaymentOption;
|
|
188
|
+
lifetime?: number;
|
|
189
|
+
qrImageTemplate: string;
|
|
190
|
+
firstName?: string;
|
|
191
|
+
lastName?: string;
|
|
192
|
+
email?: string;
|
|
193
|
+
phone?: string;
|
|
194
|
+
purchaseType?: TransactionType;
|
|
195
|
+
items?: string;
|
|
196
|
+
callbackUrl?: string;
|
|
197
|
+
returnDeeplink?: string;
|
|
198
|
+
customFields?: string;
|
|
199
|
+
returnParams?: string;
|
|
200
|
+
payout?: string;
|
|
201
|
+
}
|
|
202
|
+
interface GenerateQRResponse {
|
|
203
|
+
status: PayWayResponseStatus & {
|
|
204
|
+
trace_id?: string;
|
|
205
|
+
};
|
|
206
|
+
amount: number;
|
|
207
|
+
currency: Currency;
|
|
208
|
+
qrString: string;
|
|
209
|
+
qrImage: string;
|
|
210
|
+
abapay_deeplink: string;
|
|
211
|
+
app_store: string;
|
|
212
|
+
play_store: string;
|
|
213
|
+
}
|
|
214
|
+
interface TransactionByRefItem {
|
|
215
|
+
transaction_id: string;
|
|
216
|
+
transaction_date: string;
|
|
217
|
+
apv: string;
|
|
218
|
+
payment_status: TransactionStatus;
|
|
219
|
+
payment_status_code: number;
|
|
220
|
+
original_amount: number;
|
|
221
|
+
original_currency: Currency;
|
|
222
|
+
total_amount: number;
|
|
223
|
+
discount_amount: number;
|
|
224
|
+
refund_amount: number;
|
|
225
|
+
payment_amount: number;
|
|
226
|
+
payment_currency: Currency;
|
|
227
|
+
bank_ref: string;
|
|
228
|
+
payer_account: string;
|
|
229
|
+
bank_name: string;
|
|
230
|
+
payment_type: string;
|
|
231
|
+
merchant_ref: string;
|
|
232
|
+
}
|
|
233
|
+
interface GetTransactionsByRefResponse {
|
|
234
|
+
data: TransactionByRefItem[];
|
|
235
|
+
status: PayWayResponseStatus;
|
|
236
|
+
}
|
|
141
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Main SDK client for ABA PayWay.
|
|
240
|
+
* Provides methods for creating transactions, checking status, and listing transactions.
|
|
241
|
+
*/
|
|
142
242
|
declare class PayWay {
|
|
143
243
|
private readonly merchantId;
|
|
144
244
|
private readonly apiKey;
|
|
145
245
|
private readonly baseUrl;
|
|
246
|
+
private readonly timeout;
|
|
247
|
+
/**
|
|
248
|
+
* @param config - Merchant credentials and environment selection.
|
|
249
|
+
* @throws {PayWayConfigError} If `merchantId` or `apiKey` is empty.
|
|
250
|
+
*/
|
|
146
251
|
constructor(config: PayWayConfig);
|
|
147
252
|
/**
|
|
148
253
|
* Generate checkout parameters for a transaction.
|
|
149
254
|
* Returns form params to be submitted from the browser via ABA's checkout JS SDK.
|
|
150
255
|
*/
|
|
151
256
|
createTransaction(options: CreateTransactionOptions): CheckoutParams;
|
|
257
|
+
/**
|
|
258
|
+
* Check the status of a transaction.
|
|
259
|
+
* @param transactionId - The unique transaction ID to look up.
|
|
260
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
261
|
+
*/
|
|
152
262
|
checkTransaction(transactionId: string): Promise<PayWayResponse<CheckTransactionData>>;
|
|
263
|
+
/**
|
|
264
|
+
* List transactions with optional filters. Max 3-day date range.
|
|
265
|
+
* @param options - Filter and pagination options.
|
|
266
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
267
|
+
*/
|
|
153
268
|
listTransactions(options?: ListTransactionsOptions): Promise<ListTransactionsResponse>;
|
|
269
|
+
/**
|
|
270
|
+
* Get detailed information about a transaction, including its operation history.
|
|
271
|
+
* @param transactionId - The unique transaction ID to look up.
|
|
272
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
273
|
+
*/
|
|
274
|
+
getTransactionDetails(transactionId: string): Promise<PayWayResponse<TransactionDetailData>>;
|
|
275
|
+
/**
|
|
276
|
+
* Close (cancel) a pending transaction.
|
|
277
|
+
* @param transactionId - The transaction ID to close.
|
|
278
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
279
|
+
*/
|
|
280
|
+
closeTransaction(transactionId: string): Promise<CloseTransactionResponse>;
|
|
281
|
+
/**
|
|
282
|
+
* Fetch the latest exchange rates from ABA Bank.
|
|
283
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
284
|
+
*/
|
|
285
|
+
getExchangeRate(): Promise<ExchangeRateResponse>;
|
|
286
|
+
/**
|
|
287
|
+
* Generate a QR code for payment via ABA KHQR, WeChat Pay, or Alipay.
|
|
288
|
+
* @param options - QR generation options.
|
|
289
|
+
* @throws {PayWayConfigError} If required options are missing or invalid.
|
|
290
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
291
|
+
*/
|
|
292
|
+
generateQR(options: GenerateQROptions): Promise<GenerateQRResponse>;
|
|
293
|
+
/**
|
|
294
|
+
* Get transactions by merchant reference. Returns up to the last 50 transactions.
|
|
295
|
+
* @param merchantRef - Your merchant reference number.
|
|
296
|
+
* @throws {PayWayAPIError} If the API returns a non-2xx response.
|
|
297
|
+
*/
|
|
298
|
+
getTransactionsByRef(merchantRef: string): Promise<GetTransactionsByRefResponse>;
|
|
154
299
|
private request;
|
|
155
300
|
}
|
|
156
301
|
|
|
157
|
-
declare const
|
|
158
|
-
declare const
|
|
302
|
+
declare const BASE_URLS: Record<Environment, string>;
|
|
303
|
+
declare const SANDBOX_BASE_URL: string;
|
|
304
|
+
declare const PRODUCTION_BASE_URL: string;
|
|
159
305
|
declare const ENDPOINTS: {
|
|
160
306
|
readonly purchase: "/api/payment-gateway/v1/payments/purchase";
|
|
161
307
|
readonly checkTransaction: "/api/payment-gateway/v1/payments/check-transaction-2";
|
|
162
308
|
readonly transactionList: "/api/payment-gateway/v1/payments/transaction-list-2";
|
|
309
|
+
readonly transactionDetail: "/api/payment-gateway/v1/payments/transaction-detail";
|
|
310
|
+
readonly closeTransaction: "/api/payment-gateway/v1/payments/close-transaction";
|
|
311
|
+
readonly exchangeRate: "/api/payment-gateway/v1/exchange-rate";
|
|
312
|
+
readonly generateQR: "/api/payment-gateway/v1/payments/generate-qr";
|
|
313
|
+
readonly getTransactionsByRef: "/api/payment-gateway/v1/payments/get-transactions-by-mc-ref";
|
|
163
314
|
};
|
|
164
315
|
|
|
316
|
+
/** Base error class for all PayWay SDK errors. */
|
|
165
317
|
declare class PayWayError extends Error {
|
|
166
|
-
constructor(message: string);
|
|
318
|
+
constructor(message: string, options?: ErrorOptions);
|
|
167
319
|
}
|
|
320
|
+
/** Thrown when the ABA PayWay API returns a non-2xx HTTP response. */
|
|
168
321
|
declare class PayWayAPIError extends PayWayError {
|
|
169
322
|
readonly statusCode: number;
|
|
170
323
|
readonly responseBody: unknown;
|
|
171
324
|
constructor(message: string, statusCode: number, responseBody?: unknown);
|
|
172
325
|
}
|
|
326
|
+
/** Thrown when the SDK is constructed with missing or invalid configuration. */
|
|
173
327
|
declare class PayWayConfigError extends PayWayError {
|
|
174
328
|
constructor(message: string);
|
|
175
329
|
}
|
|
330
|
+
/** Thrown when HMAC hash generation fails. */
|
|
176
331
|
declare class PayWayHashError extends PayWayError {
|
|
177
332
|
constructor(message: string);
|
|
178
333
|
}
|
|
179
334
|
|
|
180
|
-
|
|
335
|
+
/** Generate an HMAC-SHA512 hash from concatenated values, returned as a base64 string. */
|
|
336
|
+
declare function createHash(values: readonly string[], apiKey: string): string;
|
|
181
337
|
|
|
338
|
+
/** Format a Date as `yyyyMMddHHmmss` in UTC, used for ABA's `req_time` parameter. */
|
|
182
339
|
declare function formatRequestTime(date?: Date): string;
|
|
183
|
-
|
|
184
|
-
declare function
|
|
340
|
+
/** Build a FormData object from a record, skipping `undefined`, `null`, and empty string values. */
|
|
341
|
+
declare function buildFormData(params: object): FormData;
|
|
342
|
+
/** Format a numeric amount as a string: 2 decimal places for USD, rounded integer for KHR. */
|
|
343
|
+
declare function formatAmount(amount: number, currency?: Currency): string;
|
|
344
|
+
/** Base64-encode a string value using Node.js Buffer. */
|
|
185
345
|
declare function toBase64(value: string): string;
|
|
186
346
|
|
|
187
|
-
export { type CheckTransactionData, type
|
|
347
|
+
export { BASE_URLS, type CheckTransactionData, type CheckoutParams, type CloseTransactionResponse, type CreateTransactionOptions, type Currency, ENDPOINTS, type Environment, type ExchangeRate, type ExchangeRateCurrency, type ExchangeRateResponse, type GenerateQROptions, type GenerateQRResponse, type GetTransactionsByRefResponse, type ItemEntry, type ListTransactionsOptions, type ListTransactionsResponse, PRODUCTION_BASE_URL, PayWay, PayWayAPIError, type PayWayConfig, PayWayConfigError, PayWayError, PayWayHashError, type PayWayResponse, type PayWayResponseStatus, type PaymentOption, type QRPaymentOption, SANDBOX_BASE_URL, type TransactionByRefItem, type TransactionDetailData, type TransactionListItem, type TransactionOperation, type TransactionStatus, type TransactionType, buildFormData, createHash, formatAmount, formatRequestTime, toBase64 };
|