vxgate 2.0.2 → 2.0.4

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.
Files changed (3) hide show
  1. package/README.md +176 -6
  2. package/package.json +1 -1
  3. package/src/index.js +1 -1
package/README.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  Violetics Payment Gateway SDK — terima pembayaran QRIS via Orderkuota dengan 3 baris kode.
4
4
 
5
+ ## Get API Key
6
+
7
+ 1. Daftar di **[pg.vltcx.eu.cc/register](https://pg.vltcx.eu.cc/register)**
8
+ 2. Verifikasi akun kamu
9
+ 3. Buka **Dashboard → API Keys** → Generate key baru
10
+ 4. Copy key dengan format `vlt_xxx` — siap dipakai
11
+
5
12
  ## Install
6
13
 
7
14
  ```bash
@@ -15,22 +22,185 @@ import { VXGatePayment } from 'vxgate';
15
22
 
16
23
  const pay = new VXGatePayment('vlt_YOUR_API_KEY');
17
24
 
18
- // Buat order + tampilkan QR + tunggu lunas
19
- const payment = await pay.create({
25
+ // Buat order + poll sampai lunas
26
+ const { payment, result } = await pay.createAndWait({
20
27
  amount: 15000,
21
28
  referenceId: `ORDER-${Date.now()}`,
29
+ description: 'Pembelian Premium',
22
30
  expireMinutes: 30,
23
31
  });
24
32
 
25
- console.log(payment.qrisUrl); // tampilkan ke customer
33
+ if (result.paid) {
34
+ console.log(`✅ Lunas via ${result.payerBrand}`);
35
+ console.log(`📱 QR URL: ${payment.qrisUrl}`);
36
+ }
37
+ ```
38
+
39
+ ## API
40
+
41
+ ### `new VXGatePayment(apiKey, [baseUrl])`
42
+
43
+ | Param | Type | Description |
44
+ |-------|------|-------------|
45
+ | `apiKey` | string | API Key kamu (format `vlt_xxx`) |
46
+ | `baseUrl` | string | Custom base URL (default: `https://pg.vltcx.eu.cc/api`) |
47
+
48
+ ### `.create(opts)` → `Promise<PaymentData>`
49
+
50
+ Buat order pembayaran baru.
51
+
52
+ ```js
53
+ const payment = await pay.create({
54
+ amount: 15000, // wajib, nominal dalam Rupiah
55
+ referenceId: 'ORDER-001', // opsional, auto-generate jika kosong
56
+ description: 'Premium Plan', // opsional
57
+ expireMinutes: 60, // opsional, default 60 menit
58
+ });
59
+
60
+ // payment.qrisUrl → URL gambar QR siap tampil ke customer
61
+ // payment.amount → nominal actual (mungkin ada suffix unik +1 s/d +500)
62
+ // payment.referenceId → simpan ini untuk check/poll
63
+ // payment.expiresAtHuman → "2026-06-03 15:00:00"
64
+ ```
65
+
66
+ ### `.check(referenceId)` → `Promise<PaymentResult>`
67
+
68
+ Cek status pembayaran satu kali.
69
+
70
+ ```js
71
+ const result = await pay.check('ORDER-001');
72
+ // result.status → 'pending' | 'paid' | 'expired'
73
+ // result.paid → boolean shortcut
74
+ // result.payerBrand → 'GOPAY' | 'OVO' | 'DANA' | ...
75
+ // result.paidAt → "2026-06-03 14:42:17"
76
+ ```
77
+
78
+ ### `.poll(referenceId, [opts])` → `Promise<PaymentResult>`
79
+
80
+ Poll sampai paid/expired atau timeout.
81
+
82
+ ```js
83
+ const result = await pay.poll('ORDER-001', {
84
+ intervalMs: 3000, // cek tiap 3 detik (default: 5000)
85
+ timeoutMs: 600_000, // timeout 10 menit (default: 300000)
86
+ onPoll: (n, status) => console.log(`[#${n}] ${status}`),
87
+ });
88
+ ```
89
+
90
+ ### `.createAndWait(paymentOpts, [pollOpts])` → `Promise<{payment, result}>`
91
+
92
+ Shortcut: buat + poll sekaligus. Return object `{ payment, result }` — `payment` berisi data QR dan `result` berisi status akhir.
93
+
94
+ ```js
95
+ const { payment, result } = await pay.createAndWait(
96
+ { amount: 15000, referenceId: 'ORDER-001' },
97
+ { intervalMs: 3000, timeoutMs: 300_000 }
98
+ );
99
+
100
+ // Data QR & order ada di `payment`:
101
+ console.log(payment.qrisUrl); // URL gambar QR → tampilkan ke customer
102
+ console.log(payment.qrisString); // string QRIS raw (untuk generate QR sendiri)
103
+ console.log(payment.referenceId); // reference ID order
104
+ console.log(payment.amount); // nominal actual (bisa ada suffix unik)
105
+
106
+ // Status pembayaran ada di `result`:
107
+ console.log(result.paid); // true jika lunas
108
+ console.log(result.payerBrand); // 'GOPAY' | 'OVO' | 'DANA' | ...
109
+ ```
110
+
111
+ > **Catatan:** `createAndWait` akan **menunggu** sampai pembayaran `paid` atau `expired`. QR sudah tersedia di `payment` segera setelah fungsi mulai polling — tapi kalau kamu perlu **menampilkan QR dulu** sebelum menunggu, gunakan `.create()` + `.poll()` secara terpisah:
112
+ >
113
+ > ```js
114
+ > // Pattern: tampilkan QR dulu, baru poll
115
+ > const payment = await pay.create({ amount: 15000 });
116
+ > tampilkanQR(payment.qrisUrl); // langsung tampilkan ke user
117
+ >
118
+ > const result = await pay.poll(payment.referenceId, {
119
+ > onPoll: (n, status) => console.log(`[#${n}] ${status}`),
120
+ > });
121
+ > if (result.paid) console.log('Lunas!');
122
+ > ```
123
+
124
+ ### `.list([opts])` → `Promise<Transaction[]>`
125
+
126
+ Daftar transaksi.
127
+
128
+ ```js
129
+ const txs = await pay.list({ limit: 20, offset: 0 });
130
+ ```
131
+
132
+ ### `.requestOtp(username, password)` / `.verifyOtp(otp)`
133
+
134
+ Login Orderkuota via API.
135
+
136
+ ```js
137
+ await pay.requestOtp('08xxxx', 'password');
138
+ await pay.verifyOtp('123456');
139
+ ```
140
+
141
+ ### `.setWebhook(url)` → `Promise<{webhookUrl, webhookSecret}>`
142
+
143
+ Konfigurasi webhook URL.
144
+
145
+ ```js
146
+ const { webhookSecret } = await pay.setWebhook('https://yourapp.com/webhook');
147
+ // Simpan webhookSecret untuk verifikasi signature
148
+ ```
149
+
150
+ ### `VXGatePayment.verifyWebhook(rawBody, signature, secret)` → `boolean`
151
+
152
+ Verifikasi HMAC-SHA256 webhook signature (Node.js).
153
+
154
+ ```js
155
+ // Express handler
156
+ app.post('/webhook', express.raw({ type: '*/*' }), (req, res) => {
157
+ const sig = req.headers['x-vxgate-signature'];
158
+ if (!VXGatePayment.verifyWebhook(req.body, sig, process.env.WEBHOOK_SECRET))
159
+ return res.sendStatus(401);
160
+
161
+ const event = JSON.parse(req.body);
162
+ if (event.event === 'payment.success') {
163
+ fulfillOrder(event.reference_id);
164
+ }
165
+ res.sendStatus(200);
166
+ });
167
+ ```
168
+
169
+ ### `VXGatePayment.verifyWebhookAsync(rawBody, signature, secret)` → `Promise<boolean>`
170
+
171
+ Verifikasi webhook (browser-compatible, Web Crypto API).
172
+
173
+ ## Error Handling
174
+
175
+ ```js
176
+ import { VXGatePayment, VXGateError, VXGateTimeoutError } from 'vxgate';
177
+
178
+ try {
179
+ const result = await pay.poll('ORDER-001', { timeoutMs: 60_000 });
180
+ } catch (err) {
181
+ if (err instanceof VXGateTimeoutError) {
182
+ console.log('Payment belum masuk setelah 60 detik');
183
+ } else if (err instanceof VXGateError) {
184
+ console.log(`API Error ${err.statusCode}: ${err.message}`);
185
+ }
186
+ }
187
+ ```
188
+
189
+ ## ESM & CJS
190
+
191
+ Package support keduanya:
192
+
193
+ ```js
194
+ // ESM
195
+ import { VXGatePayment } from 'vxgate';
26
196
 
27
- const result = await pay.poll(payment.referenceId);
28
- if (result.paid) console.log(`Lunas via ${result.payerBrand}`);
197
+ // CJS
198
+ const { VXGatePayment } = require('vxgate');
29
199
  ```
30
200
 
31
201
  ## Links
32
202
 
33
203
  - [Register](https://pg.vltcx.eu.cc/register) — daftar & dapatkan API key
34
- - [Documentation](https://pg.vltcx.eu.cc/docs) — full API reference
204
+ - [Documentation](https://pg.vltcx.eu.cc/docs)
35
205
  - [Dashboard](https://pg.vltcx.eu.cc/dashboard)
36
206
  - [GitHub](https://github.com/cv3inx/VXGate)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vxgate",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "Violetics Payment Gateway SDK — QRIS payment via Orderkuota API",
5
5
  "keywords": ["qris", "payment", "orderkuota", "violetics", "indonesia", "payment-gateway"],
6
6
  "author": "Violetics",
package/src/index.js CHANGED
@@ -210,7 +210,7 @@ class VXGatePayment {
210
210
  /**
211
211
  * Verifikasi HMAC-SHA256 webhook signature.
212
212
  * @param {Buffer|string} rawBody - Raw request body
213
- * @param {string} signature - X-Violetics-Signature header value
213
+ * @param {string} signature - X-VXGate-Signature header value
214
214
  * @param {string} secret - Webhook secret dari setWebhook()
215
215
  * @returns {boolean}
216
216
  */