cashi-id 1.0.0
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/.history/.npmignore_20251225201807 +0 -0
- package/.history/.npmignore_20251225201808 +3 -0
- package/.history/.npmignore_20251225201811 +2 -0
- package/.history/.npmignore_20251225201832 +3 -0
- package/.history/.npmignore_20251225202057 +4 -0
- package/README.md +99 -0
- package/index.js +51 -0
- package/npm_recovery_codes.txt +5 -0
- package/package.json +21 -0
- package/test.js +15 -0
|
File without changes
|
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# CASHI.ID Node.js SDK 🚀
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/cashi-id)
|
|
4
|
+
[](https://github.com/cashi-id/sdk/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
**CASHI.ID SDK** adalah library resmi Node.js untuk memudahkan integrasi pembayaran **QRIS Dinamis** ke dalam aplikasi Anda. Cocok digunakan untuk Website, Bot Telegram, Backend API, hingga Sistem Kasir.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Fitur Utama
|
|
11
|
+
- ✅ **Simple Order Creation**: Buat tagihan QRIS cuma dengan 1 baris kode.
|
|
12
|
+
- ✅ **Real-time Polling**: Cek status transaksi secara instan (Sangat berguna untuk Bot).
|
|
13
|
+
- ✅ **Promise Based**: Menggunakan `async/await` yang modern dan bersih.
|
|
14
|
+
- ✅ **Hybrid Support**: Support CommonJS (`require`) & ES Modules (`import`).
|
|
15
|
+
|
|
16
|
+
## 📦 Instalasi
|
|
17
|
+
|
|
18
|
+
Instal melalui npm:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install cashi-id
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
🚀 Penggunaan Cepat
|
|
25
|
+
|
|
26
|
+
1. Inisialisasi
|
|
27
|
+
Dapatkan API Key Anda melalui Dashboard Merchant Cashi.id.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
const Cashi = require('cashi-id');
|
|
32
|
+
const cashi = new Cashi('YOUR_API_KEY_HERE');
|
|
33
|
+
```
|
|
34
|
+
2. Membuat Pembayaran (QRIS)
|
|
35
|
+
Gunakan fungsi ini untuk membuat transaksi baru.
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
const createPayment = async () => {
|
|
39
|
+
try {
|
|
40
|
+
const order = await cashi.createOrder(15000); // Nominal Rp 15.000
|
|
41
|
+
|
|
42
|
+
console.log("Order ID:", order.order_id);
|
|
43
|
+
console.log("Nominal + Kode Unik:", order.amount);
|
|
44
|
+
console.log("Link Pembayaran:", order.checkout_url);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
console.error("Gagal membuat order:", err.message);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
createPayment();
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Cek Status Transaksi (Polling)
|
|
54
|
+
Metode ini sangat disarankan jika Anda membangun Bot Telegram atau aplikasi yang tidak memiliki URL publik untuk menerima Webhook.
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
const checkStatus = async (orderId) => {
|
|
58
|
+
const result = await cashi.checkStatus(orderId);
|
|
59
|
+
|
|
60
|
+
if (result.status === 'SETTLED') {
|
|
61
|
+
console.log("Pembayaran Berhasil Diterima! ✅");
|
|
62
|
+
} else if (result.status === 'PENDING') {
|
|
63
|
+
console.log("Menunggu Pembayaran... ⏳");
|
|
64
|
+
} else {
|
|
65
|
+
console.log("Transaksi Kadaluarsa atau Gagal ❌");
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
🛡️ Webhook Handler
|
|
71
|
+
Jika Anda menggunakan Webhook, server Cashi.id akan mengirimkan POST request dengan payload berikut:
|
|
72
|
+
|
|
73
|
+
```JSON
|
|
74
|
+
|
|
75
|
+
{
|
|
76
|
+
"order_id": "ORD-1766-999",
|
|
77
|
+
"amount": 50000,
|
|
78
|
+
"status": "SETTLED",
|
|
79
|
+
"timestamp": "2025-12-25 20:00:00"
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
Penting: Pastikan server Anda merespon dengan status code 200 untuk menghentikan retrying notifikasi.
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
🛠️ Error Handling
|
|
86
|
+
SDK ini akan melempar error jika API Key tidak valid atau terjadi masalah jaringan. Selalu gunakan blok try...catch untuk menjaga stabilitas aplikasi Anda.
|
|
87
|
+
|
|
88
|
+
```javascript
|
|
89
|
+
try {
|
|
90
|
+
const res = await cashi.checkStatus('ORD-123');
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.log("Terjadi Kesalahan:", error.message);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
📄 Lisensi
|
|
97
|
+
Distribusi di bawah lisensi MIT. Bebas digunakan untuk proyek personal maupun komersial.
|
|
98
|
+
|
|
99
|
+
<p align="center"> Dibuat dengan ❤️ oleh <b>CASHI.ID Developer Team</b> </p>
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// index.js
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
|
|
4
|
+
class Cashi {
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} apiKey - API Key dari Dashboard Cashi.id
|
|
7
|
+
*/
|
|
8
|
+
constructor(apiKey) {
|
|
9
|
+
if (!apiKey) throw new Error("API Key is required!");
|
|
10
|
+
|
|
11
|
+
this.apiKey = apiKey;
|
|
12
|
+
this.baseURL = "http://localhost:5012/api"; // Sesuaikan dengan domain asli lu nanti
|
|
13
|
+
|
|
14
|
+
// Inisialisasi Axios instance
|
|
15
|
+
this.client = axios.create({
|
|
16
|
+
baseURL: this.baseURL,
|
|
17
|
+
headers: {
|
|
18
|
+
'x-api-key': this.apiKey,
|
|
19
|
+
'Content-Type': 'application/json'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Membuat Order QRIS Baru
|
|
26
|
+
* @param {number} amount - Nominal pembayaran
|
|
27
|
+
*/
|
|
28
|
+
async createOrder(amount) {
|
|
29
|
+
try {
|
|
30
|
+
const response = await this.client.post('/create-order', { amount });
|
|
31
|
+
return response.data;
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(error.response?.data?.message || "Failed to create order");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Cek Status Transaksi secara Manual (Polling)
|
|
39
|
+
* @param {string} orderId - ID Order dari Cashi (Contoh: ORD-XXXX)
|
|
40
|
+
*/
|
|
41
|
+
async checkStatus(orderId) {
|
|
42
|
+
try {
|
|
43
|
+
const response = await this.client.get(`/check-status/${orderId}`);
|
|
44
|
+
return response.data;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
throw new Error(error.response?.data?.message || "Failed to check status");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = Cashi;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
f540a22744d8cb3d226f79deb8c26ec26d8e946fdb024e2183758140fd5668f7
|
|
2
|
+
dcd64ae8959ed8ce26e73dca10935a4c42aa8cbdd4682298584b3faa48f30d77
|
|
3
|
+
cf044a2270913664fa58b364b5fe7452d4bf4928dc10e4214dc8942e9a46463e
|
|
4
|
+
6afa1964610606261395542f23fcf0a1f388216e1e326dd5fbbb388320634495
|
|
5
|
+
06bba8b0e9911ecdbb30f94e3425042c3b539e5ddbdc92b07f7ad0248a47019d
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cashi-id",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Official Node.js SDK for Cashi.id QRIS Dynamic Payment Gateway",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"qris",
|
|
11
|
+
"payment-gateway",
|
|
12
|
+
"cashi",
|
|
13
|
+
"indonesia",
|
|
14
|
+
"automation"
|
|
15
|
+
],
|
|
16
|
+
"author": "Pitucode.com / Cashi.id Team",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^1.6.0"
|
|
20
|
+
}
|
|
21
|
+
}
|
package/test.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const Cashi = require('./index.js');
|
|
2
|
+
|
|
3
|
+
const cashi = new Cashi('YOURAPIKEY');
|
|
4
|
+
|
|
5
|
+
async function runTest() {
|
|
6
|
+
try {
|
|
7
|
+
console.log("--- Mengetes Check Status ---");
|
|
8
|
+
const status = await cashi.checkStatus('ORD-XXXX5404XX710-721');
|
|
9
|
+
console.log("Hasil:", status);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
console.error("Error Test:", err.message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
runTest();
|