@crediblemark/buayar 0.8.0 → 0.8.2

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/docs/ipaymu.md ADDED
@@ -0,0 +1,295 @@
1
+ # Panduan Integrasi iPaymu di Buayar
2
+
3
+ Dokumentasi lengkap mengenai integrasi payment gateway **iPaymu API v2** pada SDK Buayar, mencakup transaksi langsung (Direct API), halaman pembayaran (Redirect Checkout), Split Payment, logistik COD, pengecekan saldo, riwayat mutasi, dan panduan simulasi sandbox.
4
+
5
+ ---
6
+
7
+ ## 1. Konfigurasi Lingkungan (.env)
8
+
9
+ Buayar menggunakan konfigurasi terpadu berbasis prefix `BUAYAR_*`:
10
+
11
+ ```env
12
+ # Provider aktif
13
+ BUAYAR_PROVIDER=ipaymu
14
+
15
+ # Kredensial iPaymu (dapat dilihat di dashboard iPaymu menu Integrasi)
16
+ BUAYAR_MERCHANT_CODE=000000xxxxxxxxxx # Nomor Virtual Account (VA) Utama Merchant
17
+ BUAYAR_API_KEY=SANDBOXxxxxxxxxxxxxxxxx # API Key iPaymu
18
+
19
+ # Mode Sandbox (true untuk development, false untuk production)
20
+ BUAYAR_SANDBOX=true
21
+
22
+ # URL Notifikasi Webhook (opsional, dapat di-override di setiap invoice)
23
+ BUAYAR_CALLBACK_URL=https://domain-anda.com/api/payment/webhook
24
+ BUAYAR_RETURN_URL=https://domain-anda.com/payment/success
25
+ ```
26
+
27
+ ---
28
+
29
+ ## 2. Inisialisasi SDK
30
+
31
+ ```typescript
32
+ import { Buayar } from "buayar";
33
+
34
+ // Otomatis membaca dari process.env:
35
+ const buayar = new Buayar();
36
+
37
+ // Atau inisialisasi eksplisit:
38
+ const buayar = new Buayar({
39
+ provider: "ipaymu",
40
+ merchantCode: "000000xxxxxxxxxx",
41
+ apiKey: "SANDBOXxxxxxxxxxxxxxxxx",
42
+ sandbox: true,
43
+ });
44
+ ```
45
+
46
+ ---
47
+
48
+ ## 3. Mengambil Metode Pembayaran Aktif (100% Dinamis)
49
+
50
+ Buayar menembak endpoint resmi `GET /api/v2/payment-channels` secara dinamis tanpa data statis/dummy:
51
+
52
+ ```typescript
53
+ const result = await buayar.getPaymentMethods();
54
+
55
+ if (result.success) {
56
+ console.log("Total channel aktif:", result.methods.length);
57
+
58
+ // methods sudah dikelompokkan per kategori untuk UI Accordion:
59
+ console.log(result.categories);
60
+ // Output kategori: Virtual Account, QRIS, Retail / Gerai, Kartu Kredit, Paylater / Cicilan, COD
61
+
62
+ // Contoh struktur channel:
63
+ console.log(result.methods[0]);
64
+ /*
65
+ {
66
+ paymentMethod: "bag_va",
67
+ code: "bag_va",
68
+ paymentName: "VA BAG",
69
+ paymentImage: "https://sandbox.ipaymu.com/asset/images/...",
70
+ totalFee: "IDR 3,500",
71
+ category: "Virtual Account",
72
+ extra: {
73
+ healthStatus: "online",
74
+ featureStatus: "active",
75
+ instructionsDoc: "https://...",
76
+ feeDetail: { ActualFee: 3500, ActualFeeType: "FLAT", AdditionalFee: 0 }
77
+ }
78
+ }
79
+ */
80
+ }
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 4. Pembuatan Tagihan (Invoice)
86
+
87
+ ### A. Direct Payment (Custom Native UI)
88
+ Menghasilkan nomor VA, kode bayar, atau QRIS langsung tanpa mengalihkan pembeli keluar dari aplikasi Anda.
89
+
90
+ ```typescript
91
+ const invoice = await buayar.createInvoice({
92
+ orderId: `INV-${Date.now()}`,
93
+ amount: 100000,
94
+ paymentMethod: "bca_va", // Canonical code: bca_va, mandiri_va, bri_va, bni_va, cimb_va, qris, alfamart, indomaret, dll.
95
+ productDetails: "Langganan Premium 1 Bulan",
96
+ customer: {
97
+ name: "Budi Santoso",
98
+ email: "budi@mail.com",
99
+ phone: "081234567890",
100
+ },
101
+ // Opsi Tambahan iPaymu:
102
+ feeDirection: "BUYER", // "BUYER" (bebankan fee ke pembeli) atau "MERCHANT" (potong omset)
103
+ escrow: false, // true untuk rekening bersama iPaymu
104
+ });
105
+
106
+ if (invoice.success) {
107
+ console.log("Transaction ID (Trx ID):", invoice.reference); // Contoh: "229432"
108
+ console.log("Nomor Virtual Account:", invoice.vaNumber); // Contoh: "3811800034705407"
109
+ console.log("Expired:", invoice.expiresAt);
110
+ }
111
+ ```
112
+
113
+ ### B. Redirect Payment (Hosted Payment Page)
114
+ Cukup kosongkan `paymentMethod` untuk menggunakan halaman checkout bawaan iPaymu:
115
+
116
+ ```typescript
117
+ const invoice = await buayar.createInvoice({
118
+ orderId: `ORDER-${Date.now()}`,
119
+ amount: 250000,
120
+ productDetails: "Sepatu Olahraga",
121
+ customer: {
122
+ name: "Siti Rahma",
123
+ email: "siti@mail.com",
124
+ phone: "081999888777",
125
+ },
126
+ returnUrl: "https://toko-anda.com/checkout/success",
127
+ });
128
+
129
+ // Arahkan browser pembeli ke URL pembayaran:
130
+ console.log("Redirect URL:", invoice.paymentUrl);
131
+ ```
132
+
133
+ ---
134
+
135
+ ## 5. Split Payment (Bagi Hasil Realtime Otomatis)
136
+
137
+ Layanan Split Payment iPaymu digunakan untuk mendistribusikan dana transaksi secara realtime ke akun reseller, mitra cabang, atau affiliate (biaya Rp 150/split, minimal split Rp 500).
138
+
139
+ ### Langkah 1: Daftarkan Mitra Baru (*Single Register API*)
140
+ ```typescript
141
+ const client = buayar.getIpaymuClient();
142
+
143
+ const reg = await client.registerUser({
144
+ name: "Mitra Cabang Surabaya",
145
+ email: "cabang.surabaya@mitra.com",
146
+ phone: "081233445566",
147
+ });
148
+
149
+ console.log("VA Child Account:", reg.Data.Va);
150
+ // Output: "0000001233445566"
151
+ ```
152
+
153
+ ### Langkah 2: Buat Transaksi Menggunakan Parameter `subAccountId`
154
+ ```typescript
155
+ const invoice = await buayar.createInvoice({
156
+ orderId: `SPLIT-${Date.now()}`,
157
+ amount: 500000,
158
+ paymentMethod: "bca_va",
159
+ productDetails: "Paket Reseller",
160
+ customer: { name: "Pelanggan", email: "pelanggan@mail.com" },
161
+ // Kirim VA Child Account tujuan split:
162
+ subAccountId: "0000001233445566",
163
+ });
164
+
165
+ // Pembayaran otomatis terbagi dan dicatat atas nama rekening mitra
166
+ ```
167
+
168
+ ---
169
+
170
+ ## 6. Logistik COD (Cash On Delivery)
171
+
172
+ iPaymu mendukung pembayaran COD terintegrasi dengan ekspedisi pengiriman (SAP, SiCepat, SPX, RPX, dll.).
173
+
174
+ ```typescript
175
+ const client = buayar.getIpaymuClient();
176
+
177
+ // 1. Cari Kode Area Berdasarkan Nama Kota / Kecamatan
178
+ const areaResult = await client.getCodArea("denpasar");
179
+ const areaList = areaResult.data;
180
+ // Contoh: { id: 26027, label: "DAUH PURI, DENPASAR BARAT, DENPASAR, 80113", zip_code: "80113" }
181
+
182
+ // 2. Hitung Estimasi Ongkir COD
183
+ const rates = await client.getCodRate({
184
+ pickup_area_id: areaList[0].id,
185
+ destination_area_id: areaList[1].id,
186
+ weight: 1, // Dalam kilogram
187
+ amount: 150000, // Nilai barang COD
188
+ });
189
+ console.log("Opsi Ekspedisi:", rates.data);
190
+ // [ { shipping_name: "SICEPAT", service_name: "REG", shipping_fee: 11500 }, ... ]
191
+
192
+ // 3. Request Penjemputan Paket (Pickup)
193
+ const pickup = await client.getCodPickup({
194
+ transaction_id: invoice.reference,
195
+ pickup_date: "2026-09-05",
196
+ pickup_time: "14:00",
197
+ pickup_vehicle: "Motor", // "Motor" | "Mobil"
198
+ });
199
+
200
+ // 4. Unduh Label Resi Pengiriman
201
+ const label = await client.getCodAwb(invoice.reference);
202
+
203
+ // 5. Lacak Status Pengiriman (Tracking)
204
+ const tracking = await client.getCodTracking({
205
+ awb: "AWB1234567890",
206
+ transaction_id: invoice.reference,
207
+ });
208
+ ```
209
+
210
+ ---
211
+
212
+ ## 7. Public Area API (Wilayah Administratif Indonesia)
213
+
214
+ Pencarian wilayah administratif Indonesia (read-only publik tanpa signature):
215
+
216
+ ```typescript
217
+ const client = buayar.getIpaymuClient();
218
+
219
+ const provinces = await client.getAreasProvince();
220
+ const cities = await client.getAreasCity(51); // ID Provinsi Bali
221
+ const districts = await client.getAreasDistrict(5171); // ID Kota Denpasar
222
+ const villages = await client.getAreasVillage(517101); // ID Kecamatan
223
+ ```
224
+
225
+ ---
226
+
227
+ ## 8. Cek Saldo & Riwayat Transaksi
228
+
229
+ ```typescript
230
+ const client = buayar.getIpaymuClient();
231
+
232
+ // Cek saldo merchant aktif:
233
+ const balance = await client.checkBalance();
234
+ console.log("Saldo Merchant: IDR", balance.balance);
235
+
236
+ // Riwayat mutasi berpaginasi:
237
+ const history = await client.getHistory({
238
+ page: 1,
239
+ limit: 10,
240
+ status: 1, // 1 = Berhasil, 0 = Pending, -2 = Expired
241
+ });
242
+ console.log("Total Transaksi:", history.Data.Total);
243
+
244
+ // Daftar seluruh kode bank nasional di Indonesia:
245
+ const banks = await client.getBankList();
246
+ ```
247
+
248
+ ---
249
+
250
+ ## 9. Webhook & Verifikasi Notifikasi Callback
251
+
252
+ Saat pembeli menyelesaikan pembayaran, iPaymu mengirimkan HTTP POST request ke `notifyUrl`:
253
+
254
+ ```typescript
255
+ // Di handler Express.js / Next.js API route:
256
+ app.post("/api/payment/webhook", (req, res) => {
257
+ const result = buayar.verifyCallback(req.body);
258
+
259
+ if (result.isValid && result.isPaid) {
260
+ console.log("Pembayaran Berhasil untuk Order ID:", result.orderId);
261
+ console.log("Nominal Diterima:", result.amount);
262
+ // Jalankan logika bisnis: update database status pesanan menjadi PAID
263
+ }
264
+
265
+ // Wajib kirim response status 200 ke iPaymu
266
+ res.status(200).send("OK");
267
+ });
268
+ ```
269
+
270
+ ---
271
+
272
+ ## 10. Panduan Pengujian di Simulator Sandbox
273
+
274
+ ### Cara Mendapatkan Transaction ID
275
+ `Transaction ID` resmi dari iPaymu otomatis disimpan di **`invoice.reference`** saat memanggil `buayar.createInvoice()`:
276
+ ```typescript
277
+ console.log(invoice.reference); // Contoh: "229432"
278
+ ```
279
+
280
+ ### Melakukan Simulasi Pembayaran
281
+ 1. Buka dan login ke **[https://sandbox.ipaymu.com](https://sandbox.ipaymu.com)**.
282
+ 2. Klik menu **"Tes Notify"** di bagian atas dashboard.
283
+ 3. Masukkan **Transaction ID** dari invoice Anda (misal `229432`).
284
+ 4. Klik tombol **"Kirim" / "Test"**.
285
+ 5. Server iPaymu Sandbox akan mengubah status transaksi menjadi **Berhasil** dan otomatis mengirimkan webhook notifikasi ke `notifyUrl` Anda.
286
+
287
+ ### Mengecek Status Transaksi via Kode
288
+ ```typescript
289
+ const check = await buayar.checkTransaction({
290
+ merchantOrderId: invoice.reference, // Transaction ID iPaymu
291
+ });
292
+
293
+ console.log("Status:", check.rawResponse.Data.StatusDesc);
294
+ // Output: "Berhasil"
295
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crediblemark/buayar",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "Unified Payment Gateway SDK for Node.js & TypeScript — 19 providers (Midtrans, Xendit, Duitku, Stripe, PayPal, Adyen, Razorpay, Square, Checkout.com, PayU, Braintree, 2Checkout, DOKU, iPaymu, PrismaLink, Faspay, Finpay, Nicepay, OY!) with zero-code switching via .env",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",