@crediblemark/buayar 0.8.4 → 0.8.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/docs/ipaymu.md CHANGED
@@ -85,6 +85,38 @@ if (result.success) {
85
85
  > atau `HealthStatus` selain `"online"` (mis. `offline`, `maintenance`) **otomatis dibuang** dari daftar.
86
86
  > Jadi metode yang muncul selalu berasal dari data real-time iPaymu, bukan asumsi.
87
87
 
88
+ ### 3a. Deskriptor Kanonikal Siap-Render (`getPaymentMethodDescriptors`)
89
+
90
+ Untuk konsumen UI/snapshot yang butuh bentuk seragam tanpa mapping manual per provider, gunakan `getPaymentMethodDescriptors()`:
91
+
92
+ ```typescript
93
+ const snap = await buayar.getPaymentMethodDescriptors({ amount: 100000 });
94
+
95
+ if (snap.success) {
96
+ console.log("Provider:", snap.provider);
97
+ console.log("Dibuat pada:", snap.generatedAt);
98
+ console.log("Total:", snap.descriptors.length);
99
+
100
+ // Contoh: siap disimpan sebagai JSON flipbook oleh frontend
101
+ console.log(snap.descriptors[0]);
102
+ /*
103
+ {
104
+ id: "BCA_VA",
105
+ name: "Virtual Account BCA",
106
+ type: "va",
107
+ icon: "🏦",
108
+ badge: "Otomatis 24 Jam • Fee 0.7%",
109
+ image: "https://my.ipaymu.com/images/banks/bca.png",
110
+ category: "Virtual Account",
111
+ coming_soon: false,
112
+ totalFee: "0.7%"
113
+ }
114
+ */
115
+ }
116
+ ```
117
+
118
+ `type` adalah salah satu dari `qris | va | ewallet | retail | card | paylater | other`, siap dipakai untuk ikon/badge. Mapping kategori → tipe dilakukan sentral di `buildPaymentMethodDescriptors()` (ekspor dari `core/descriptor`), jadi semua konsumen mendapat hasil identik.
119
+
88
120
  ---
89
121
 
90
122
  ## 4. Pembuatan Tagihan (Invoice)
@@ -101,7 +133,7 @@ const invoice = await buayar.createInvoice({
101
133
  customer: {
102
134
  name: "Budi Santoso",
103
135
  email: "budi@mail.com",
104
- phone: "081234567890",
136
+ phone: "081234567890", // Opsional per dokumentasi resmi iPaymu v2 (hanya dikirim jika ada)
105
137
  },
106
138
  // Opsi Tambahan iPaymu:
107
139
  feeDirection: "BUYER", // "BUYER" (bebankan fee ke pembeli) atau "MERCHANT" (potong omset)
@@ -109,12 +141,14 @@ const invoice = await buayar.createInvoice({
109
141
  });
110
142
 
111
143
  if (invoice.success) {
112
- console.log("Transaction ID (Trx ID):", invoice.reference); // Contoh: "229432"
144
+ console.log("Transaction ID (Trx ID):", invoice.reference); // Contoh: "229432" (simpan ini untuk checkTransaction)
113
145
  console.log("Nomor Virtual Account:", invoice.vaNumber); // Contoh: "3811800034705407"
114
146
  console.log("Expired:", invoice.expiresAt);
115
147
  }
116
148
  ```
117
149
 
150
+ > 💡 **Parameter `customer.phone` Opsional:** Sesuai dokumentasi resmi iPaymu v2, parameter `phone` bersifat opsional. Buayar tidak lagi menyisipkan nomor fallback buatan — field `phone` hanya disertakan jika memang diisi oleh pembeli/merchant.
151
+
118
152
  ### B. Redirect Payment (Hosted Payment Page)
119
153
  Cukup kosongkan `paymentMethod` untuk menggunakan halaman checkout bawaan iPaymu:
120
154
 
@@ -126,7 +160,7 @@ const invoice = await buayar.createInvoice({
126
160
  customer: {
127
161
  name: "Siti Rahma",
128
162
  email: "siti@mail.com",
129
- phone: "081999888777",
163
+ phone: "081999888777", // Opsional
130
164
  },
131
165
  returnUrl: "https://toko-anda.com/checkout/success",
132
166
  });
@@ -260,6 +294,8 @@ Callback **harus** membawa header `X-Signature`; Buayar memverifikasinya dengan
260
294
  menggunakan **Merchant VA** sebagai secret key. Callback tanpa `X-Signature` yang sah
261
295
  akan selalu ditolak (`isValid === false`).
262
296
 
297
+ Sesuai dokumentasi resmi iPaymu, payload notifikasi membawa field `reference_id` (berisi nomor order merchant yang dikirim saat `createInvoice`). Buayar otomatis memetakannya ke **`result.orderId`**.
298
+
263
299
  ```typescript
264
300
  // Di handler Express.js / Next.js API route + REST framework apapun (Elysia/Hono/...):
265
301
  app.post("/api/payment/webhook", (req, res) => {
@@ -267,6 +303,7 @@ app.post("/api/payment/webhook", (req, res) => {
267
303
  const result = buayar.verifyWebhook(req.body, req.headers);
268
304
 
269
305
  if (result.isValid && result.isPaid) {
306
+ // result.orderId otomatis diambil dari `reference_id` iPaymu (order ID merchant Anda)
270
307
  console.log("Pembayaran Berhasil untuk Order ID:", result.orderId);
271
308
  console.log("Nominal Diterima:", result.amount);
272
309
  // Jalankan logika bisnis: update database status pesanan menjadi PAID
@@ -294,12 +331,22 @@ console.log(invoice.reference); // Contoh: "229432"
294
331
  4. Klik tombol **"Kirim" / "Test"**.
295
332
  5. Server iPaymu Sandbox akan mengubah status transaksi menjadi **Berhasil** dan otomatis mengirimkan webhook notifikasi ke `notifyUrl` Anda.
296
333
 
297
- ### Mengecek Status Transaksi via Kode
334
+ ### Mengecek Status Transaksi via Kode (`checkTransaction`)
335
+
336
+ > ⚠️ **PENTING — Kontrak Resmi Endpoint `/transaction`:**
337
+ > Dokumentasi resmi iPaymu API v2 menegaskan bahwa endpoint `/api/v2/transaction` **hanya menerima `transactionId` numerik** yang diterbitkan iPaymu (`invoice.reference`), **BUKAN** `order_number` atau string `orderId` merchant.
338
+ >
339
+ > Jika aplikasi Anda melakukan polling status, pastikan selalu menyimpan `invoice.reference` di database dan operasikan nilai tersebut ke parameter `merchantOrderId`:
340
+
298
341
  ```typescript
299
342
  const check = await buayar.checkTransaction({
300
- merchantOrderId: invoice.reference, // Transaction ID iPaymu
343
+ // WAJIB: Gunakan invoice.reference (TransactionId numerik dari iPaymu),
344
+ // BUKAN nomor invoice/order_number string toko Anda!
345
+ merchantOrderId: invoice.reference, // misal "229432"
301
346
  });
302
347
 
303
- console.log("Status:", check.rawResponse.Data.StatusDesc);
304
- // Output: "Berhasil"
348
+ if (check.success) {
349
+ console.log("Status Transaksi:", check.status); // "paid" | "pending" | "failed"
350
+ console.log("Status Desc:", check.rawResponse.Data.StatusDesc); // "Berhasil"
351
+ }
305
352
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crediblemark/buayar",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
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",