wahdx-api 1.0.2 → 1.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.
package/README.md CHANGED
@@ -1,188 +1,217 @@
1
- # wahdx-api
2
-
3
- Package untuk generate QRIS dan cek payment status secara realtime dengan API OrderKuota dari [https://api.wahdx.co](https://api.wahdx.co).
4
-
5
- ## Fitur
6
-
7
- - Membaca dan ekstrak kode QR dari gambar
8
- - Generate kode QR dengan nominal tertentu
9
- - Cek status pembayaran secara realtime
10
- - Generate bukti transaksi (receipt)
11
-
12
- ## Instalasi
13
-
14
- ```bash
15
- npm install wahdx-api
16
- ```
17
-
18
- ## Konfigurasi
19
-
20
- Buat file `.env` di root project Anda:
21
-
22
- ```
23
- WAHDX_TOKENKEY=your_wahdx_token_key
24
- ORKUT_TOKEN_AUTH=your_orkut_token_auth
25
- ORKUT_USERNAME=your_orkut_username
26
- ```
27
-
28
- > **Catatan:** Untuk mendapatkan tokenKey, Anda bisa membelinya di halaman [https://api.wahdx.co](https://api.wahdx.co)
29
-
30
- ## Penggunaan
31
-
32
- ### Contoh Lengkap
33
-
34
- ```javascript
35
- import QRISPayment from 'wahdx-api';
36
- import '@dotenvx/dotenvx/config';
37
- import fs from 'fs';
38
-
39
- // Konfigurasi
40
- const config = {
41
- storeName: 'AHDX STORE',
42
- defaultQrPath: 'QRIS.png', // Path ke QRIS static yang didownload di merchant orderkuota
43
- tokenKey: process.env.WAHDX_TOKENKEY,
44
- auth_token: process.env.ORKUT_TOKEN_AUTH,
45
- auth_username: process.env.ORKUT_USERNAME
46
- };
47
-
48
- // Membuat instance QRISPayment
49
- const qrisPayment = new QRISPayment(config);
50
-
51
- async function main() {
52
- try {
53
- console.log('=== TEST REALTIME QRIS PAYMENT ===\n');
54
- const randomAmount = Math.floor(Math.random() * 99) + 1; // Random 1-99
55
- const amount = 100 + randomAmount; // Base 100 + random amount
56
- const reference = 'REF' + Date.now();
57
-
58
- // Generate QR code
59
- const { qrBuffer } = await qrisPayment.generateQRFromImage(amount);
60
-
61
- // Save QR code image
62
- fs.writeFileSync(`qr-${amount}.png`, qrBuffer);
63
-
64
- console.log('=== TRANSACTION DETAILS ===');
65
- console.log('Reference:', reference);
66
- console.log('Amount:', amount);
67
- console.log('QR Image:', `qr-${amount}.png`);
68
- console.log('\nSilakan scan QR code dan lakukan pembayaran');
69
- console.log('\nMenunggu pembayaran...\n');
70
-
71
- // Check payment status with 5 minutes timeout
72
- const startTime = Date.now();
73
- const timeout = 5 * 60 * 1000;
74
-
75
- while (Date.now() - startTime < timeout) {
76
- const result = await qrisPayment.checkPayment(reference, amount);
77
-
78
- if (result.success && result.data.status === 'PAID') {
79
- console.log(' Pembayaran berhasil!');
80
- if (result.receipt) {
81
- console.log(' Bukti transaksi:', result.receipt.filePath);
82
- }
83
- return;
84
- }
85
-
86
- await new Promise(resolve => setTimeout(resolve, 10000)); // delay 10 detik
87
- console.log('Menunggu pembayaran...');
88
- }
89
-
90
- throw new Error('Timeout: Pembayaran tidak diterima dalam 5 menit');
91
-
92
- } catch (error) {
93
- console.error('Error:', error.message);
94
- }
95
- }
96
-
97
- main();
98
- ```
99
-
100
- ### API Reference
101
-
102
- #### Inisialisasi
103
-
104
- ```javascript
105
- import QRISPayment from 'wahdx-api';
106
-
107
- const config = {
108
- storeName: 'NAMA TOKO',
109
- defaultQrPath: 'path/to/qris/template.png',
110
- tokenKey: 'your_wahdx_token_key',
111
- auth_token: 'your_orkut_token_auth',
112
- auth_username: 'your_orkut_username'
113
- };
114
-
115
- const qrisPayment = new QRISPayment(config);
116
- ```
117
-
118
- #### Generate QR dari Template
119
-
120
- ```javascript
121
- const amount = 10000; // Rp 10.000
122
- // Menggunakan default QR yang sudah diatur
123
- const { qrString, qrBuffer } = await qrisPayment.generateQRFromImage(amount);
124
- // Atau dengan path QR spesifik
125
- // const { qrString, qrBuffer } = await qrisPayment.generateQRFromImage(amount, 'path/to/qris/template.png');
126
-
127
- // Simpan QR ke file
128
- fs.writeFileSync('qr-output.png', qrBuffer);
129
- ```
130
-
131
- #### Cek Status Pembayaran
132
-
133
- ```javascript
134
- const reference = 'REF' + Date.now();
135
- const amount = 10000;
136
-
137
- const result = await qrisPayment.checkPayment(reference, amount);
138
- console.log(result);
139
- /*
140
- Output jika berhasil:
141
- {
142
- success: true,
143
- data: {
144
- status: 'PAID',
145
- amount: 10000,
146
- reference: 'REF1234567890',
147
- ...
148
- },
149
- receipt: {
150
- filePath: 'path/to/receipt.pdf',
151
- ...
152
- }
153
- }
154
- */
155
- ```
156
-
157
- ## FAQ
158
-
159
- ### Q: Bagaimana cara mendapatkan tokenKey agar bisa menggunakan module ini?
160
- A: Anda bisa membeli tokenKey di halaman utama [https://api.wahdx.co](https://api.wahdx.co)
161
-
162
- ### Q: Bagaimana cara mendapatkan kredensial API OrderKuota?
163
- A: Silahkan kunjungi dokumentasi api [https://api.wahdx.co/api-docs](https://api.wahdx.co/api-docs) untuk mendapatkan token pada akun orderkuota anda.
164
-
165
- ### Q: Apakah module ini bisa digunakan di project CommonJS?
166
- A: Ya! Package ini mendukung dual module system (ESM dan CommonJS). Anda bisa menggunakan dengan dua cara:
167
-
168
- 1. Dengan ES Modules (dalam file .js dengan `type: "module"` di package.json):
169
- ```javascript
170
- import QRISPayment from 'wahdx-api';
171
-
172
- const qrisPayment = new QRISPayment(config);
173
- // gunakan qrisPayment
174
- ```
175
-
176
- 2. Dengan CommonJS (dalam file .cjs atau project tanpa `type: "module"`):
177
- ```javascript
178
- const QRISPayment = require('wahdx-api');
179
-
180
- const qrisPayment = new QRISPayment(config);
181
- // gunakan qrisPayment
182
- ```
183
-
184
- Package secara otomatis mendeteksi format yang digunakan dan menyediakan versi yang sesuai.
185
-
186
- ## Lisensi
187
-
1
+ # wahdx-api
2
+
3
+ Package untuk generate QRIS dan cek payment status secara realtime dengan API OrderKuota dari [https://api.wahdx.co](https://api.wahdx.co).
4
+
5
+ ## Fitur
6
+
7
+ - Membaca dan ekstrak kode QR dari gambar
8
+ - Generate kode QR dengan nominal tertentu
9
+ - Cek status pembayaran secara realtime
10
+ - Generate bukti transaksi (receipt)
11
+ - Kompatibel di semua platform (Windows, Linux, Mac)
12
+
13
+ ## Instalasi
14
+
15
+ ```bash
16
+ npm install wahdx-api
17
+ ```
18
+
19
+ ## Konfigurasi
20
+
21
+ Buat file `.env` di root project Anda:
22
+
23
+ ```
24
+ WAHDX_TOKENKEY=your_wahdx_token_key
25
+ ORKUT_TOKEN_AUTH=your_orkut_token_auth
26
+ ORKUT_USERNAME=your_orkut_username
27
+ ```
28
+
29
+ > **Catatan:** Untuk mendapatkan tokenKey, Anda bisa membelinya di halaman [https://api.wahdx.co](https://api.wahdx.co)
30
+
31
+ ### Opsi Konfigurasi
32
+
33
+ | Opsi | Deskripsi | Default |
34
+ |---------------------|------------------------------------------------------------------|-------------|
35
+ | storeName | Nama toko yang akan ditampilkan pada receipt | - |
36
+ | defaultQrPath | Path ke QRIS static yang didownload di merchant orderkuota | - |
37
+ | tokenKey | Token key dari WAHDX | - |
38
+ | auth_token | Token autentikasi OrderKuota | - |
39
+ | auth_username | Username OrderKuota | - |
40
+ | autoGenerateReceipt | Mengaktifkan/menonaktifkan pembuatan receipt otomatis | true |
41
+
42
+ ## Penggunaan
43
+
44
+ ### Contoh Lengkap
45
+
46
+ ```javascript
47
+ import QRISPayment from 'wahdx-api';
48
+ import '@dotenvx/dotenvx/config';
49
+ import fs from 'fs';
50
+
51
+ // Konfigurasi
52
+ const config = {
53
+ storeName: 'AHDX STORE',
54
+ defaultQrPath: 'QRIS.png', // Path ke QRIS static yang didownload di merchant orderkuota
55
+ tokenKey: process.env.WAHDX_TOKENKEY,
56
+ auth_token: process.env.ORKUT_TOKEN_AUTH,
57
+ auth_username: process.env.ORKUT_USERNAME,
58
+ autoGenerateReceipt: true // Atur false jika tidak ingin otomatis membuat receipt
59
+ };
60
+
61
+ // Membuat instance QRISPayment
62
+ const qrisPayment = new QRISPayment(config);
63
+
64
+ async function main() {
65
+ try {
66
+ console.log('=== TEST REALTIME QRIS PAYMENT ===\n');
67
+ const randomAmount = Math.floor(Math.random() * 99) + 1; // Random 1-99
68
+ const amount = 100 + randomAmount; // Base 100 + random amount
69
+ const reference = 'REF' + Date.now();
70
+
71
+ // Generate QR code
72
+ const { qrBuffer } = await qrisPayment.generateQRFromImage(amount);
73
+
74
+ // Save QR code image
75
+ fs.writeFileSync(`qr-${amount}.png`, qrBuffer);
76
+
77
+ console.log('=== TRANSACTION DETAILS ===');
78
+ console.log('Reference:', reference);
79
+ console.log('Amount:', amount);
80
+ console.log('QR Image:', `qr-${amount}.png`);
81
+ console.log('\nSilakan scan QR code dan lakukan pembayaran');
82
+ console.log('\nMenunggu pembayaran...\n');
83
+
84
+ // Check payment status with 5 minutes timeout
85
+ const startTime = Date.now();
86
+ const timeout = 5 * 60 * 1000;
87
+
88
+ while (Date.now() - startTime < timeout) {
89
+ const result = await qrisPayment.checkPayment(reference, amount);
90
+
91
+ if (result.success && result.data.status === 'PAID') {
92
+ console.log('✓ Pembayaran berhasil!');
93
+ if (result.receipt) {
94
+ console.log('✓ Bukti transaksi:', result.receipt.filePath);
95
+ }
96
+ return;
97
+ }
98
+
99
+ await new Promise(resolve => setTimeout(resolve, 10000)); // delay 10 detik
100
+ console.log('Menunggu pembayaran...');
101
+ }
102
+
103
+ throw new Error('Timeout: Pembayaran tidak diterima dalam 5 menit');
104
+
105
+ } catch (error) {
106
+ console.error('Error:', error.message);
107
+ }
108
+ }
109
+
110
+ main();
111
+ ```
112
+
113
+ ### API Reference
114
+
115
+ #### Inisialisasi
116
+
117
+ ```javascript
118
+ import QRISPayment from 'wahdx-api';
119
+
120
+ const config = {
121
+ storeName: 'NAMA TOKO',
122
+ defaultQrPath: 'path/to/qris/template.png',
123
+ tokenKey: 'your_wahdx_token_key',
124
+ auth_token: 'your_orkut_token_auth',
125
+ auth_username: 'your_orkut_username',
126
+ autoGenerateReceipt: true // Atur false jika tidak ingin otomatis membuat receipt
127
+ };
128
+
129
+ const qrisPayment = new QRISPayment(config);
130
+ ```
131
+
132
+ #### Generate QR dari Template
133
+
134
+ ```javascript
135
+ const amount = 10000; // Rp 10.000
136
+ // Menggunakan default QR yang sudah diatur
137
+ const { qrString, qrBuffer } = await qrisPayment.generateQRFromImage(amount);
138
+ // Atau dengan path QR spesifik
139
+ // const { qrString, qrBuffer } = await qrisPayment.generateQRFromImage(amount, 'path/to/qris/template.png');
140
+
141
+ // Simpan QR ke file
142
+ fs.writeFileSync('qr-output.png', qrBuffer);
143
+ ```
144
+
145
+ #### Cek Status Pembayaran
146
+
147
+ ```javascript
148
+ const reference = 'REF' + Date.now();
149
+ const amount = 10000;
150
+
151
+ const result = await qrisPayment.checkPayment(reference, amount);
152
+ console.log(result);
153
+ /*
154
+ Output jika berhasil:
155
+ {
156
+ success: true,
157
+ data: {
158
+ status: 'PAID',
159
+ amount: 10000,
160
+ reference: 'REF1234567890',
161
+ ...
162
+ },
163
+ receipt: {
164
+ filePath: 'path/to/receipt.pdf',
165
+ ...
166
+ }
167
+ }
168
+ */
169
+ ```
170
+
171
+ #### Generate Receipt Secara Manual
172
+
173
+ Jika Anda telah menonaktifkan `autoGenerateReceipt` dalam konfigurasi, Anda dapat menghasilkan receipt secara manual dengan metode berikut:
174
+
175
+ ```javascript
176
+ // Ketika pembayaran sudah diterima
177
+ const result = await qrisPayment.checkPayment(reference, amount);
178
+
179
+ if (result.success && result.data.status === 'PAID') {
180
+ // Generate receipt secara manual
181
+ const receipt = await qrisPayment.generateReceipt(result.data);
182
+ console.log('Receipt berhasil dibuat:', receipt.filePath);
183
+ }
184
+ ```
185
+
186
+ ## FAQ
187
+
188
+ ### Q: Bagaimana cara mendapatkan tokenKey agar bisa menggunakan module ini?
189
+ A: Anda bisa membeli tokenKey di halaman utama [https://api.wahdx.co](https://api.wahdx.co)
190
+
191
+ ### Q: Bagaimana cara mendapatkan kredensial API OrderKuota?
192
+ A: Silahkan kunjungi dokumentasi api [https://api.wahdx.co/api-docs](https://api.wahdx.co/api-docs) untuk mendapatkan token pada akun orderkuota anda.
193
+
194
+ ### Q: Apakah module ini bisa digunakan di project CommonJS?
195
+ A: Ya! Package ini mendukung dual module system (ESM dan CommonJS). Anda bisa menggunakan dengan dua cara:
196
+
197
+ 1. Dengan ES Modules (dalam file .js dengan `type: "module"` di package.json):
198
+ ```javascript
199
+ import QRISPayment from 'wahdx-api';
200
+
201
+ const qrisPayment = new QRISPayment(config);
202
+ // gunakan qrisPayment
203
+ ```
204
+
205
+ 2. Dengan CommonJS (dalam file .cjs atau project tanpa `type: "module"`):
206
+ ```javascript
207
+ const QRISPayment = require('wahdx-api');
208
+
209
+ const qrisPayment = new QRISPayment(config);
210
+ // gunakan qrisPayment
211
+ ```
212
+
213
+ Package secara otomatis mendeteksi format yang digunakan dan menyediakan versi yang sesuai.
214
+
215
+ ## Lisensi
216
+
188
217
  MIT
package/dist/index.cjs CHANGED
@@ -4,6 +4,12 @@ const ReceiptGenerator = require("./receipt-generator.cjs");
4
4
 
5
5
  class QRISPayment {
6
6
  constructor(config = {}) {
7
+ // Default config
8
+ this.config = {
9
+ autoGenerateReceipt: true, // Default-nya adalah true untuk mempertahankan kompatibilitas
10
+ ...config
11
+ };
12
+
7
13
  this.qrGenerator = new QRISGenerator(config);
8
14
  this.paymentChecker = new PaymentChecker(config);
9
15
  this.receiptGenerator = new ReceiptGenerator(config);
@@ -24,12 +30,7 @@ class QRISPayment {
24
30
  * @returns {Promise<{qrString: string, qrBuffer: Buffer}>}
25
31
  */
26
32
  async generateQR(amount) {
27
- const qrString = this.qrGenerator.generateQrString(amount);
28
- const qrBuffer = await this.qrGenerator.generateQRWithLogo(qrString);
29
- return {
30
- qrString,
31
- qrBuffer
32
- };
33
+ return await this.qrGenerator.generateQR(amount);
33
34
  }
34
35
 
35
36
  /**
@@ -44,7 +45,9 @@ class QRISPayment {
44
45
 
45
46
  async checkPayment(reference, amount) {
46
47
  const result = await this.paymentChecker.checkPaymentStatus(reference, amount);
47
- if (result.success && result.data.status === 'PAID') {
48
+
49
+ // Cek apakah pembayaran sukses dan statusnya PAID, serta autoGenerateReceipt diaktifkan
50
+ if (result.success && result.data.status === 'PAID' && this.config.autoGenerateReceipt) {
48
51
  const receipt = await this.receiptGenerator.generateReceipt(result.data);
49
52
  result.receipt = receipt;
50
53
  }
package/dist/index.mjs CHANGED
@@ -4,6 +4,12 @@ import ReceiptGenerator from './receipt-generator.mjs';
4
4
 
5
5
  class QRISPayment {
6
6
  constructor(config = {}) {
7
+ // Default config
8
+ this.config = {
9
+ autoGenerateReceipt: true, // Default-nya adalah true untuk mempertahankan kompatibilitas
10
+ ...config
11
+ };
12
+
7
13
  this.qrGenerator = new QRISGenerator(config);
8
14
  this.paymentChecker = new PaymentChecker(config);
9
15
  this.receiptGenerator = new ReceiptGenerator(config);
@@ -24,12 +30,7 @@ class QRISPayment {
24
30
  * @returns {Promise<{qrString: string, qrBuffer: Buffer}>}
25
31
  */
26
32
  async generateQR(amount) {
27
- const qrString = this.qrGenerator.generateQrString(amount);
28
- const qrBuffer = await this.qrGenerator.generateQRWithLogo(qrString);
29
- return {
30
- qrString,
31
- qrBuffer
32
- };
33
+ return await this.qrGenerator.generateQR(amount);
33
34
  }
34
35
 
35
36
  /**
@@ -44,7 +45,9 @@ class QRISPayment {
44
45
 
45
46
  async checkPayment(reference, amount) {
46
47
  const result = await this.paymentChecker.checkPaymentStatus(reference, amount);
47
- if (result.success && result.data.status === 'PAID') {
48
+
49
+ // Cek apakah pembayaran sukses dan statusnya PAID, serta autoGenerateReceipt diaktifkan
50
+ if (result.success && result.data.status === 'PAID' && this.config.autoGenerateReceipt) {
48
51
  const receipt = await this.receiptGenerator.generateReceipt(result.data);
49
52
  result.receipt = receipt;
50
53
  }