@crediblemark/buayar 0.1.6 → 0.1.8
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/README.md +56 -175
- package/dist/index.d.mts +78 -1
- package/dist/index.d.ts +78 -1
- package/dist/index.js +713 -0
- package/dist/index.mjs +711 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -3,26 +3,41 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@crediblemark/buayar)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
**`@crediblemark/buayar`** adalah Unified Payment Gateway SDK untuk Node.js dan TypeScript yang dirancang untuk mempermudah integrasi berbagai gerbang pembayaran (Payment Gateway)
|
|
6
|
+
**`@crediblemark/buayar`** adalah Unified Payment Gateway SDK untuk Node.js dan TypeScript yang dirancang untuk mempermudah integrasi berbagai gerbang pembayaran (Payment Gateway) di Indonesia menggunakan satu struktur API yang seragam.
|
|
7
7
|
|
|
8
|
-
Dengan SDK ini, Anda cukup menulis kode satu kali menggunakan struktur API yang konsisten untuk mengelola pembuatan
|
|
8
|
+
Dengan SDK ini, Anda cukup menulis kode satu kali menggunakan struktur API yang konsisten untuk mengelola pembuatan transaksi, pengecekan status transaksi, query metode pembayaran, serta verifikasi callback webhook dari berbagai penyedia layanan payment gateway.
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
12
12
|
## 🚀 Fitur Utama
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
- 🔄 **Unified API**: Satu antarmuka (interface) terpadu untuk semua provider payment gateway.
|
|
15
|
-
- ⚡ **Direct Payment Support**: Otomatis mendeteksi `paymentMethod` dan beralih ke Direct Inquiry API
|
|
16
|
-
- 🏷️ **Pre-Categorization (Accordion Ready)**: Menyediakan pengelompokan pembayaran bawaan (`Virtual Account`, `QRIS`, `E-Wallet`, `Retail / Gerai`, `Lainnya`) langsung dari API response untuk memudahkan implementasi UI accordion.
|
|
15
|
+
- ⚡ **Direct Payment Support**: Otomatis mendeteksi `paymentMethod` dan beralih ke Direct Inquiry API Duitku atau Core API Midtrans untuk mengembalikan `vaNumber`, `qrString` (EMVCo), dan `paymentCode` secara instan tanpa redirect eksternal.
|
|
16
|
+
- 🏷️ **Pre-Categorization (Accordion Ready)**: Menyediakan pengelompokan pembayaran bawaan (`Virtual Account`, `QRIS`, `E-Wallet`, `Retail / Gerai`, `Kartu Kredit`, `Paylater / Cicilan`, `Lainnya`) langsung dari API response untuk memudahkan implementasi UI accordion.
|
|
17
17
|
- 🎨 **Headless SDK Philosophy**: Dirancang murni sebagai core logic & data manager tanpa overhead UI/styling. Memberikan kebebasan penuh bagi pengembang untuk mendesain UI/Tailwind/dark mode di tingkat aplikasi.
|
|
18
18
|
- 🛡️ **Tipe Data Kuat (TypeScript)**: Dilengkapi dengan deklarasi tipe data lengkap untuk mencegah *runtime error*.
|
|
19
|
-
- 🇮🇩 **Dukungan Lokal**: Siap digunakan untuk transaksi di Indonesia (seperti Duitku).
|
|
20
19
|
- ⚙️ **Modular & Dapat Diperluas**: Memungkinkan penambahan provider baru dengan mewarisi kelas base yang disediakan.
|
|
21
|
-
- 🔒 **Otomatisasi Signature**: Keamanan transaksi terjamin dengan pembuatan *hash* signature (MD5, SHA-256) otomatis secara internal.
|
|
22
|
-
|
|
20
|
+
- 🔒 **Otomatisasi Signature**: Keamanan transaksi terjamin dengan pembuatan *hash* signature (MD5, SHA-256, SHA-512) otomatis secara internal.
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 📦 Provider yang Didukung
|
|
25
|
+
|
|
26
|
+
SDK ini mendukung beberapa provider payment gateway terkemuka di Indonesia. Silakan merujuk ke dokumentasi detail untuk masing-masing provider:
|
|
27
|
+
|
|
28
|
+
* 🏛️ **[Integrasi Duitku (docs/duitku.md)](file:///media/rasyiqi/PROJECT/credibuild-project/buayar/docs/duitku.md)**
|
|
29
|
+
* Mendukung Redirect Checkout & Direct Inquiry (VA, QRIS, Retail Code langsung).
|
|
30
|
+
* Verifikasi callback otomatis (signature MD5).
|
|
31
|
+
* Penelusuran status transaksi & query metode pembayaran dinamis.
|
|
32
|
+
|
|
33
|
+
* 🏛️ **[Integrasi Midtrans (docs/midtrans.md)](file:///media/rasyiqi/PROJECT/credibuild-project/buayar/docs/midtrans.md)**
|
|
34
|
+
* Mendukung Snap API (Redirect Checkout) & Core API (Direct Charge VA, QRIS, E-Wallet, Retail, Kartu Kredit, Paylater).
|
|
35
|
+
* Verifikasi callback otomatis (signature SHA-512).
|
|
36
|
+
* Dilengkapi ekstensi `MidtransClient` untuk fitur transaksi pasca-bayar (refund, cancel, subscription recurring, balance check, payment link, gopay tokenization, invoicing).
|
|
37
|
+
|
|
23
38
|
---
|
|
24
39
|
|
|
25
|
-
##
|
|
40
|
+
## ⚙️ Instalasi
|
|
26
41
|
|
|
27
42
|
Instal package menggunakan manajer paket pilihan Anda:
|
|
28
43
|
|
|
@@ -40,6 +55,23 @@ yarn add @crediblemark/buayar
|
|
|
40
55
|
pnpm add @crediblemark/buayar
|
|
41
56
|
```
|
|
42
57
|
|
|
58
|
+
### Instalasi dari GitHub Packages (Alternatif)
|
|
59
|
+
|
|
60
|
+
Package ini juga tersedia di [GitHub Packages](https://github.com/crediblemark-official/Buayar/packages). Buat file `.npmrc` di root project Anda:
|
|
61
|
+
|
|
62
|
+
```ini
|
|
63
|
+
@crediblemark:registry=https://npm.pkg.github.com/
|
|
64
|
+
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Kemudian install seperti biasa:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
bun add @crediblemark/buayar
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> **Catatan:** Anda memerlukan GitHub Personal Access Token (PAT) dengan scope `read:packages` yang di-set sebagai environment variable `GITHUB_TOKEN`.
|
|
74
|
+
|
|
43
75
|
---
|
|
44
76
|
|
|
45
77
|
## 🗺️ Alur Proses Pembayaran
|
|
@@ -50,15 +82,15 @@ sequenceDiagram
|
|
|
50
82
|
actor Customer as 👤 Pelanggan
|
|
51
83
|
participant App as 💻 Aplikasi Anda (Backend)
|
|
52
84
|
participant SDK as 💳 @crediblemark/buayar
|
|
53
|
-
participant PG as 🏛️ Payment Gateway (
|
|
85
|
+
participant PG as 🏛️ Payment Gateway (Duitku / Midtrans)
|
|
54
86
|
|
|
55
87
|
Customer->>App: 1. Checkout Order
|
|
56
88
|
App->>SDK: 2. createInvoice(provider, params, config)
|
|
57
|
-
SDK->>SDK: 3.
|
|
58
|
-
SDK->>PG: 4. Inquiry Request (API)
|
|
59
|
-
PG-->>SDK: 5. Kembalikan Payment URL
|
|
89
|
+
SDK->>SDK: 3. signature Generation & Calculation
|
|
90
|
+
SDK->>PG: 4. Inquiry / Charge Request (API)
|
|
91
|
+
PG-->>SDK: 5. Kembalikan Payment URL / VA / QRIS / Ref
|
|
60
92
|
SDK-->>App: 6. Response (InvoiceResponse)
|
|
61
|
-
App-->>Customer: 7. Redirect ke
|
|
93
|
+
App-->>Customer: 7. Tampilkan Detail VA/QRIS atau Redirect ke Payment URL
|
|
62
94
|
Customer->>PG: 8. Selesaikan Pembayaran
|
|
63
95
|
PG->>App: 9. Webhook Callback (Notifikasi Pembayaran)
|
|
64
96
|
App->>SDK: 10. verifyCallback(provider, body, config)
|
|
@@ -68,135 +100,6 @@ sequenceDiagram
|
|
|
68
100
|
|
|
69
101
|
---
|
|
70
102
|
|
|
71
|
-
## 🛠️ Integrasi & Penggunaan
|
|
72
|
-
|
|
73
|
-
### 1. Inisialisasi & Membuat Transaksi (Invoice)
|
|
74
|
-
|
|
75
|
-
Berikut adalah contoh pembuatan transaksi menggunakan provider **Duitku**:
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { paymentManager } from "@crediblemark/buayar";
|
|
79
|
-
|
|
80
|
-
const providerName = "duitku";
|
|
81
|
-
|
|
82
|
-
// Konfigurasi Kredensial Provider
|
|
83
|
-
const providerConfig = {
|
|
84
|
-
merchantCode: "DXXXX", // Merchant Code dari Duitku
|
|
85
|
-
apiKey: "xxxxxxxxxxxxxxxx", // API Key / Merchant Key Anda
|
|
86
|
-
sandbox: true, // Set true untuk development / testing
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// Parameter Invoice / Pembayaran
|
|
90
|
-
const invoiceParams = {
|
|
91
|
-
orderId: "ORDER-100249",
|
|
92
|
-
amount: 150000, // Nominal transaksi (Rupiah)
|
|
93
|
-
productDetails: "Pembelian Template Landing Page Premium",
|
|
94
|
-
customer: {
|
|
95
|
-
name: "Rasyiqi Crediblemark",
|
|
96
|
-
email: "rasyiqi@crediblemark.com",
|
|
97
|
-
phone: "081234567890", // Opsional
|
|
98
|
-
},
|
|
99
|
-
returnUrl: "https://situsbisnis.com/payment/success",
|
|
100
|
-
callbackUrl: "https://api.situsbisnis.com/v1/payment/callback",
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
async function handleCheckout() {
|
|
104
|
-
try {
|
|
105
|
-
const result = await paymentManager.createInvoice(
|
|
106
|
-
providerName,
|
|
107
|
-
invoiceParams,
|
|
108
|
-
providerConfig
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
if (result.success) {
|
|
112
|
-
console.log("Invoice Berhasil Dibuat! 🎉");
|
|
113
|
-
console.log("URL Pembayaran:", result.paymentUrl);
|
|
114
|
-
console.log("Referensi Gateway:", result.reference);
|
|
115
|
-
|
|
116
|
-
// Redirect pelanggan ke paymentUrl
|
|
117
|
-
// response.redirect(result.paymentUrl);
|
|
118
|
-
} else {
|
|
119
|
-
console.error("Gagal membuat invoice:", result.error);
|
|
120
|
-
}
|
|
121
|
-
} catch (error) {
|
|
122
|
-
console.error("Terjadi kesalahan:", error);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
handleCheckout();
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### 2. Verifikasi Callback / Webhook Notifikasi
|
|
130
|
-
|
|
131
|
-
Gunakan fungsi ini di endpoint API callback/webhook untuk memastikan data notifikasi yang dikirim oleh Payment Gateway valid dan tidak dimanipulasi:
|
|
132
|
-
|
|
133
|
-
```typescript
|
|
134
|
-
import { paymentManager } from "@crediblemark/buayar";
|
|
135
|
-
|
|
136
|
-
// Endpoint API Webhook Handler
|
|
137
|
-
async function handlePaymentCallback(req: any, res: any) {
|
|
138
|
-
const providerName = "duitku";
|
|
139
|
-
const callbackPayload = req.body; // Payload POST dari gateway
|
|
140
|
-
|
|
141
|
-
const providerConfig = {
|
|
142
|
-
merchantCode: "DXXXX",
|
|
143
|
-
apiKey: "xxxxxxxxxxxxxxxx",
|
|
144
|
-
sandbox: true,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
try {
|
|
148
|
-
const verification = await paymentManager.verifyCallback(
|
|
149
|
-
providerName,
|
|
150
|
-
callbackPayload,
|
|
151
|
-
providerConfig
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
if (verification.isValid) {
|
|
155
|
-
console.log(`Signature valid untuk Order: ${verification.orderId}`);
|
|
156
|
-
|
|
157
|
-
if (verification.status === "paid") {
|
|
158
|
-
console.log("Status: PEMBAYARAN SELESAI & LUNAS! ✅");
|
|
159
|
-
// Update database Anda: ubah status order menjadi LUNAS
|
|
160
|
-
} else if (verification.status === "failed") {
|
|
161
|
-
console.log("Status: PEMBAYARAN GAGAL ❌");
|
|
162
|
-
// Update database: ubah status order menjadi GAGAL
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Kirim respon sukses ke Payment Gateway (Duitku meminta respon plaintext OK)
|
|
166
|
-
res.status(200).send("OK");
|
|
167
|
-
} else {
|
|
168
|
-
console.warn("Peringatan: Signature callback tidak valid! Potensi manipulasi data.");
|
|
169
|
-
res.status(400).send("Bad Signature");
|
|
170
|
-
}
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error("Gagal memproses callback:", error);
|
|
173
|
-
res.status(500).send("Internal Server Error");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
---
|
|
179
|
-
|
|
180
|
-
## 🗂️ Referensi API
|
|
181
|
-
|
|
182
|
-
### `PaymentManager`
|
|
183
|
-
|
|
184
|
-
#### `createInvoice(providerName, params, config)`
|
|
185
|
-
Membuat transaksi baru ke gerbang pembayaran tertentu.
|
|
186
|
-
- **`providerName`**: `string` - Nama provider payment gateway (contoh: `'duitku'`).
|
|
187
|
-
- **`params`**: `CreateInvoiceParams` - Data invoice dan detail pelanggan.
|
|
188
|
-
- **`config`**: `ProviderConfig` - Kredensial merchant dan API key.
|
|
189
|
-
- **Return**: `Promise<InvoiceResponse>`
|
|
190
|
-
|
|
191
|
-
#### `verifyCallback(providerName, body, config)`
|
|
192
|
-
Memvalidasi signature webhook callback dari payment gateway.
|
|
193
|
-
- **`providerName`**: `string` - Nama provider payment gateway (contoh: `'duitku'`).
|
|
194
|
-
- **`body`**: `any` - Payload callback mentah dari request body.
|
|
195
|
-
- **`config`**: `ProviderConfig` - Kredensial merchant dan API key.
|
|
196
|
-
- **Return**: `Promise<VerifyCallbackResult>`
|
|
197
|
-
|
|
198
|
-
---
|
|
199
|
-
|
|
200
103
|
## 📐 Spesifikasi Interface (TypeScript)
|
|
201
104
|
|
|
202
105
|
### `CreateInvoiceParams`
|
|
@@ -212,6 +115,8 @@ interface CreateInvoiceParams {
|
|
|
212
115
|
};
|
|
213
116
|
returnUrl: string;
|
|
214
117
|
callbackUrl: string;
|
|
118
|
+
paymentMethod?: string; // Opsional: Kode pembayaran untuk direct charge (contoh: "BCA", "bca_va", "qris")
|
|
119
|
+
providerParams?: any; // Opsional: Parameter tambahan spesifik provider
|
|
215
120
|
}
|
|
216
121
|
```
|
|
217
122
|
|
|
@@ -219,14 +124,14 @@ interface CreateInvoiceParams {
|
|
|
219
124
|
```typescript
|
|
220
125
|
interface InvoiceResponse {
|
|
221
126
|
success: boolean;
|
|
222
|
-
paymentUrl?: string;
|
|
223
|
-
reference?: string;
|
|
224
|
-
vaNumber?: string; // Nomor Virtual Account
|
|
225
|
-
qrString?: string; //
|
|
226
|
-
qrCodeUrl?: string; //
|
|
127
|
+
paymentUrl?: string; // URL checkout halaman pembayaran (jika menggunakan redirect)
|
|
128
|
+
reference?: string; // ID Referensi transaksi / token Snap dari gateway
|
|
129
|
+
vaNumber?: string; // Nomor Virtual Account jika menggunakan VA instan
|
|
130
|
+
qrString?: string; // Data string QRIS mentah (EMVCo) untuk scan QR langsung
|
|
131
|
+
qrCodeUrl?: string; // URL gambar QR Code
|
|
227
132
|
paymentCode?: string; // Kode pembayaran retail (Indomaret/Alfamart)
|
|
228
|
-
rawResponse: any;
|
|
229
|
-
error?: string;
|
|
133
|
+
rawResponse: any; // Payload respons mentah dari API gateway
|
|
134
|
+
error?: string; // Pesan kegagalan jika success = false
|
|
230
135
|
}
|
|
231
136
|
```
|
|
232
137
|
|
|
@@ -237,36 +142,12 @@ interface PaymentMethod {
|
|
|
237
142
|
paymentName: string;
|
|
238
143
|
paymentImage: string;
|
|
239
144
|
totalFee: string;
|
|
240
|
-
category: "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Lainnya";
|
|
241
|
-
}
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
### `VerifyCallbackResult`
|
|
245
|
-
```typescript
|
|
246
|
-
interface VerifyCallbackResult {
|
|
247
|
-
isValid: boolean;
|
|
248
|
-
orderId: string;
|
|
249
|
-
amount: number;
|
|
250
|
-
status: "paid" | "pending" | "failed";
|
|
251
|
-
rawPayload: any;
|
|
145
|
+
category: "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Kartu Kredit" | "Paylater / Cicilan" | "Lainnya";
|
|
252
146
|
}
|
|
253
147
|
```
|
|
254
148
|
|
|
255
149
|
---
|
|
256
150
|
|
|
257
|
-
## 🛠️ Utilitas Tambahan
|
|
258
|
-
|
|
259
|
-
### `getPaymentMethodCategory(code, name)`
|
|
260
|
-
Mengkategorikan kode dan nama metode pembayaran Duitku ke kategori terstandarisasi untuk UI Accordion.
|
|
261
|
-
```typescript
|
|
262
|
-
import { getPaymentMethodCategory } from "@crediblemark/buayar";
|
|
263
|
-
|
|
264
|
-
const cat = getPaymentMethodCategory("BT", "Permata VA");
|
|
265
|
-
// Output: "Virtual Account"
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
---
|
|
269
|
-
|
|
270
151
|
## 📄 Lisensi
|
|
271
152
|
|
|
272
153
|
Proyek ini dilisensikan di bawah **MIT License**. Hak Cipta © 2026 Rasyiqi Crediblemark.
|
package/dist/index.d.mts
CHANGED
|
@@ -11,6 +11,8 @@ interface CreateInvoiceParams {
|
|
|
11
11
|
callbackUrl: string;
|
|
12
12
|
/** Specific Duitku payment method code (e.g. "BCA", "I1", "OV"). If omitted, all methods are available via Duitku's redirect page. */
|
|
13
13
|
paymentMethod?: string;
|
|
14
|
+
/** Provider-specific parameters (e.g., token_id, billing details, custom headers/fields) */
|
|
15
|
+
providerParams?: any;
|
|
14
16
|
}
|
|
15
17
|
interface InvoiceResponse {
|
|
16
18
|
success: boolean;
|
|
@@ -84,6 +86,69 @@ declare abstract class BasePaymentProvider {
|
|
|
84
86
|
abstract verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
85
87
|
abstract getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
86
88
|
abstract checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
89
|
+
/** Probe/discover which payment methods are actually enabled/active for the merchant */
|
|
90
|
+
probePaymentMethods?(config: ProviderConfig): Promise<{
|
|
91
|
+
success: boolean;
|
|
92
|
+
enabled: string[];
|
|
93
|
+
error?: string;
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare class MidtransClient {
|
|
98
|
+
private apiKey;
|
|
99
|
+
private sandbox;
|
|
100
|
+
constructor(config: {
|
|
101
|
+
apiKey: string;
|
|
102
|
+
sandbox: boolean;
|
|
103
|
+
} | ProviderConfig);
|
|
104
|
+
private getApiBaseUrl;
|
|
105
|
+
request(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body: any): Promise<any>;
|
|
106
|
+
cancelTransaction(orderId: string): Promise<any>;
|
|
107
|
+
refundTransaction(orderId: string, payload: {
|
|
108
|
+
refund_key?: string;
|
|
109
|
+
amount?: number;
|
|
110
|
+
reason?: string;
|
|
111
|
+
}): Promise<any>;
|
|
112
|
+
expireTransaction(orderId: string): Promise<any>;
|
|
113
|
+
approveTransaction(orderId: string): Promise<any>;
|
|
114
|
+
denyTransaction(orderId: string): Promise<any>;
|
|
115
|
+
captureTransaction(transactionId: string, amount?: number): Promise<any>;
|
|
116
|
+
linkPayAccount(payload: any): Promise<any>;
|
|
117
|
+
getPayAccount(accountId: string): Promise<any>;
|
|
118
|
+
unbindPayAccount(accountId: string): Promise<any>;
|
|
119
|
+
getGoPayPromo(accountId: string, grossAmount: number, currency?: string): Promise<any>;
|
|
120
|
+
createSubscription(payload: any): Promise<any>;
|
|
121
|
+
getSubscription(subscriptionId: string): Promise<any>;
|
|
122
|
+
updateSubscription(subscriptionId: string, payload: any): Promise<any>;
|
|
123
|
+
disableSubscription(subscriptionId: string): Promise<any>;
|
|
124
|
+
enableSubscription(subscriptionId: string): Promise<any>;
|
|
125
|
+
createPaymentLink(payload: any): Promise<any>;
|
|
126
|
+
getPaymentLink(paymentLinkId: string): Promise<any>;
|
|
127
|
+
deletePaymentLink(paymentLinkId: string): Promise<any>;
|
|
128
|
+
getBalance(): Promise<any>;
|
|
129
|
+
createBillingInvoice(payload: any): Promise<any>;
|
|
130
|
+
getBillingInvoice(invoiceId: string): Promise<any>;
|
|
131
|
+
voidBillingInvoice(invoiceId: string): Promise<any>;
|
|
132
|
+
convertBillingInvoice(invoiceId: string): Promise<any>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class MidtransProvider extends BasePaymentProvider {
|
|
136
|
+
readonly name = "midtrans";
|
|
137
|
+
private getSnapBaseUrl;
|
|
138
|
+
private getApiBaseUrl;
|
|
139
|
+
createInvoice(params: CreateInvoiceParams, config: ProviderConfig): Promise<InvoiceResponse>;
|
|
140
|
+
verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
141
|
+
getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
142
|
+
checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Get an instance of MidtransClient to perform transaction actions, subscriptions, invoicing, etc.
|
|
145
|
+
*/
|
|
146
|
+
getClient(config: ProviderConfig): MidtransClient;
|
|
147
|
+
probePaymentMethods(config: ProviderConfig): Promise<{
|
|
148
|
+
success: boolean;
|
|
149
|
+
enabled: string[];
|
|
150
|
+
error?: string;
|
|
151
|
+
}>;
|
|
87
152
|
}
|
|
88
153
|
|
|
89
154
|
declare class DuitkuProvider extends BasePaymentProvider {
|
|
@@ -93,6 +158,11 @@ declare class DuitkuProvider extends BasePaymentProvider {
|
|
|
93
158
|
verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
94
159
|
getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
95
160
|
checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
161
|
+
probePaymentMethods(config: ProviderConfig): Promise<{
|
|
162
|
+
success: boolean;
|
|
163
|
+
enabled: string[];
|
|
164
|
+
error?: string;
|
|
165
|
+
}>;
|
|
96
166
|
}
|
|
97
167
|
|
|
98
168
|
declare function getPaymentMethodCategory(code: string, name?: string): "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Kartu Kredit" | "Paylater / Cicilan" | "Lainnya";
|
|
@@ -102,11 +172,18 @@ declare class PaymentManager {
|
|
|
102
172
|
constructor();
|
|
103
173
|
registerProvider(provider: BasePaymentProvider): void;
|
|
104
174
|
getProvider(name: string): BasePaymentProvider;
|
|
175
|
+
getMidtransProvider(): MidtransProvider;
|
|
176
|
+
getMidtransClient(config: ProviderConfig): MidtransClient;
|
|
105
177
|
createInvoice(providerName: string, params: CreateInvoiceParams, config: ProviderConfig): Promise<InvoiceResponse>;
|
|
106
178
|
verifyCallback(providerName: string, body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
107
179
|
getPaymentMethods(providerName: string, params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
108
180
|
checkTransaction(providerName: string, params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
181
|
+
probePaymentMethods(providerName: string, config: ProviderConfig): Promise<{
|
|
182
|
+
success: boolean;
|
|
183
|
+
enabled: string[];
|
|
184
|
+
error?: string;
|
|
185
|
+
}>;
|
|
109
186
|
}
|
|
110
187
|
declare const paymentManager: PaymentManager;
|
|
111
188
|
|
|
112
|
-
export { BasePaymentProvider, type CheckTransactionParams, type CheckTransactionResult, type CreateInvoiceParams, DuitkuProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, PaymentManager, type PaymentMethod, type ProviderConfig, type VerifyCallbackResult, getPaymentMethodCategory, paymentManager };
|
|
189
|
+
export { BasePaymentProvider, type CheckTransactionParams, type CheckTransactionResult, type CreateInvoiceParams, DuitkuProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, MidtransClient, MidtransProvider, PaymentManager, type PaymentMethod, type ProviderConfig, type VerifyCallbackResult, getPaymentMethodCategory, paymentManager };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface CreateInvoiceParams {
|
|
|
11
11
|
callbackUrl: string;
|
|
12
12
|
/** Specific Duitku payment method code (e.g. "BCA", "I1", "OV"). If omitted, all methods are available via Duitku's redirect page. */
|
|
13
13
|
paymentMethod?: string;
|
|
14
|
+
/** Provider-specific parameters (e.g., token_id, billing details, custom headers/fields) */
|
|
15
|
+
providerParams?: any;
|
|
14
16
|
}
|
|
15
17
|
interface InvoiceResponse {
|
|
16
18
|
success: boolean;
|
|
@@ -84,6 +86,69 @@ declare abstract class BasePaymentProvider {
|
|
|
84
86
|
abstract verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
85
87
|
abstract getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
86
88
|
abstract checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
89
|
+
/** Probe/discover which payment methods are actually enabled/active for the merchant */
|
|
90
|
+
probePaymentMethods?(config: ProviderConfig): Promise<{
|
|
91
|
+
success: boolean;
|
|
92
|
+
enabled: string[];
|
|
93
|
+
error?: string;
|
|
94
|
+
}>;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
declare class MidtransClient {
|
|
98
|
+
private apiKey;
|
|
99
|
+
private sandbox;
|
|
100
|
+
constructor(config: {
|
|
101
|
+
apiKey: string;
|
|
102
|
+
sandbox: boolean;
|
|
103
|
+
} | ProviderConfig);
|
|
104
|
+
private getApiBaseUrl;
|
|
105
|
+
request(method: "GET" | "POST" | "PATCH" | "DELETE", path: string, body: any): Promise<any>;
|
|
106
|
+
cancelTransaction(orderId: string): Promise<any>;
|
|
107
|
+
refundTransaction(orderId: string, payload: {
|
|
108
|
+
refund_key?: string;
|
|
109
|
+
amount?: number;
|
|
110
|
+
reason?: string;
|
|
111
|
+
}): Promise<any>;
|
|
112
|
+
expireTransaction(orderId: string): Promise<any>;
|
|
113
|
+
approveTransaction(orderId: string): Promise<any>;
|
|
114
|
+
denyTransaction(orderId: string): Promise<any>;
|
|
115
|
+
captureTransaction(transactionId: string, amount?: number): Promise<any>;
|
|
116
|
+
linkPayAccount(payload: any): Promise<any>;
|
|
117
|
+
getPayAccount(accountId: string): Promise<any>;
|
|
118
|
+
unbindPayAccount(accountId: string): Promise<any>;
|
|
119
|
+
getGoPayPromo(accountId: string, grossAmount: number, currency?: string): Promise<any>;
|
|
120
|
+
createSubscription(payload: any): Promise<any>;
|
|
121
|
+
getSubscription(subscriptionId: string): Promise<any>;
|
|
122
|
+
updateSubscription(subscriptionId: string, payload: any): Promise<any>;
|
|
123
|
+
disableSubscription(subscriptionId: string): Promise<any>;
|
|
124
|
+
enableSubscription(subscriptionId: string): Promise<any>;
|
|
125
|
+
createPaymentLink(payload: any): Promise<any>;
|
|
126
|
+
getPaymentLink(paymentLinkId: string): Promise<any>;
|
|
127
|
+
deletePaymentLink(paymentLinkId: string): Promise<any>;
|
|
128
|
+
getBalance(): Promise<any>;
|
|
129
|
+
createBillingInvoice(payload: any): Promise<any>;
|
|
130
|
+
getBillingInvoice(invoiceId: string): Promise<any>;
|
|
131
|
+
voidBillingInvoice(invoiceId: string): Promise<any>;
|
|
132
|
+
convertBillingInvoice(invoiceId: string): Promise<any>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class MidtransProvider extends BasePaymentProvider {
|
|
136
|
+
readonly name = "midtrans";
|
|
137
|
+
private getSnapBaseUrl;
|
|
138
|
+
private getApiBaseUrl;
|
|
139
|
+
createInvoice(params: CreateInvoiceParams, config: ProviderConfig): Promise<InvoiceResponse>;
|
|
140
|
+
verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
141
|
+
getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
142
|
+
checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Get an instance of MidtransClient to perform transaction actions, subscriptions, invoicing, etc.
|
|
145
|
+
*/
|
|
146
|
+
getClient(config: ProviderConfig): MidtransClient;
|
|
147
|
+
probePaymentMethods(config: ProviderConfig): Promise<{
|
|
148
|
+
success: boolean;
|
|
149
|
+
enabled: string[];
|
|
150
|
+
error?: string;
|
|
151
|
+
}>;
|
|
87
152
|
}
|
|
88
153
|
|
|
89
154
|
declare class DuitkuProvider extends BasePaymentProvider {
|
|
@@ -93,6 +158,11 @@ declare class DuitkuProvider extends BasePaymentProvider {
|
|
|
93
158
|
verifyCallback(body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
94
159
|
getPaymentMethods(params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
95
160
|
checkTransaction(params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
161
|
+
probePaymentMethods(config: ProviderConfig): Promise<{
|
|
162
|
+
success: boolean;
|
|
163
|
+
enabled: string[];
|
|
164
|
+
error?: string;
|
|
165
|
+
}>;
|
|
96
166
|
}
|
|
97
167
|
|
|
98
168
|
declare function getPaymentMethodCategory(code: string, name?: string): "Virtual Account" | "QRIS" | "E-Wallet" | "Retail / Gerai" | "Kartu Kredit" | "Paylater / Cicilan" | "Lainnya";
|
|
@@ -102,11 +172,18 @@ declare class PaymentManager {
|
|
|
102
172
|
constructor();
|
|
103
173
|
registerProvider(provider: BasePaymentProvider): void;
|
|
104
174
|
getProvider(name: string): BasePaymentProvider;
|
|
175
|
+
getMidtransProvider(): MidtransProvider;
|
|
176
|
+
getMidtransClient(config: ProviderConfig): MidtransClient;
|
|
105
177
|
createInvoice(providerName: string, params: CreateInvoiceParams, config: ProviderConfig): Promise<InvoiceResponse>;
|
|
106
178
|
verifyCallback(providerName: string, body: any, config: ProviderConfig): Promise<VerifyCallbackResult>;
|
|
107
179
|
getPaymentMethods(providerName: string, params: GetPaymentMethodsParams, config: ProviderConfig): Promise<GetPaymentMethodsResult>;
|
|
108
180
|
checkTransaction(providerName: string, params: CheckTransactionParams, config: ProviderConfig): Promise<CheckTransactionResult>;
|
|
181
|
+
probePaymentMethods(providerName: string, config: ProviderConfig): Promise<{
|
|
182
|
+
success: boolean;
|
|
183
|
+
enabled: string[];
|
|
184
|
+
error?: string;
|
|
185
|
+
}>;
|
|
109
186
|
}
|
|
110
187
|
declare const paymentManager: PaymentManager;
|
|
111
188
|
|
|
112
|
-
export { BasePaymentProvider, type CheckTransactionParams, type CheckTransactionResult, type CreateInvoiceParams, DuitkuProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, PaymentManager, type PaymentMethod, type ProviderConfig, type VerifyCallbackResult, getPaymentMethodCategory, paymentManager };
|
|
189
|
+
export { BasePaymentProvider, type CheckTransactionParams, type CheckTransactionResult, type CreateInvoiceParams, DuitkuProvider, type GetPaymentMethodsParams, type GetPaymentMethodsResult, type InvoiceResponse, MidtransClient, MidtransProvider, PaymentManager, type PaymentMethod, type ProviderConfig, type VerifyCallbackResult, getPaymentMethodCategory, paymentManager };
|