dra-qris-api 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/index.js +90 -0
- package/package.json +17 -0
package/index.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// file: denay-qris.js
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import crypto from "crypto";
|
|
4
|
+
|
|
5
|
+
export async function createQris({
|
|
6
|
+
nominal,
|
|
7
|
+
merchantName,
|
|
8
|
+
qris,
|
|
9
|
+
returnMode = "image",
|
|
10
|
+
apikey,
|
|
11
|
+
requireSignature = true,
|
|
12
|
+
}) {
|
|
13
|
+
const timestamp = Date.now().toString();
|
|
14
|
+
const requestId = crypto.randomBytes(16).toString("hex");
|
|
15
|
+
|
|
16
|
+
const requestBody = { nominal, merchantName, qris, returnMode, apikey };
|
|
17
|
+
|
|
18
|
+
const signature = requireSignature
|
|
19
|
+
? crypto
|
|
20
|
+
.createHmac("sha256", apikey)
|
|
21
|
+
.update(JSON.stringify(requestBody) + timestamp)
|
|
22
|
+
.digest("hex")
|
|
23
|
+
: undefined;
|
|
24
|
+
|
|
25
|
+
const { data, headers } = await axios.post(
|
|
26
|
+
"https://api.denayrestapi.xyz/api/private/qris?op=create",
|
|
27
|
+
requestBody,
|
|
28
|
+
{
|
|
29
|
+
headers: {
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
"x-api-key": apikey,
|
|
32
|
+
...(signature && { "x-signature": signature }),
|
|
33
|
+
"x-timestamp": timestamp,
|
|
34
|
+
"x-request-id": requestId,
|
|
35
|
+
},
|
|
36
|
+
responseType: "arraybuffer",
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const id = headers?.["x-payment-id"] || data.result?.id;
|
|
41
|
+
|
|
42
|
+
if (!id) throw new Error("Gagal membuat QRIS: ID pembayaran tidak tersedia.");
|
|
43
|
+
|
|
44
|
+
return { id, buffer: data };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function submitProof({
|
|
48
|
+
id,
|
|
49
|
+
ocrAmount,
|
|
50
|
+
ocrMerchantName,
|
|
51
|
+
ocrRawText,
|
|
52
|
+
reporter,
|
|
53
|
+
apikey,
|
|
54
|
+
requireSignature = true,
|
|
55
|
+
}) {
|
|
56
|
+
const timestamp = Date.now().toString();
|
|
57
|
+
const requestId = crypto.randomBytes(16).toString("hex");
|
|
58
|
+
|
|
59
|
+
const requestBody = {
|
|
60
|
+
id,
|
|
61
|
+
ocrAmount,
|
|
62
|
+
ocrMerchantName,
|
|
63
|
+
ocrRawText,
|
|
64
|
+
reporter,
|
|
65
|
+
apikey,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const signature = requireSignature
|
|
69
|
+
? crypto
|
|
70
|
+
.createHmac("sha256", apikey)
|
|
71
|
+
.update(JSON.stringify(requestBody) + timestamp)
|
|
72
|
+
.digest("hex")
|
|
73
|
+
: undefined;
|
|
74
|
+
|
|
75
|
+
const { data } = await axios.post(
|
|
76
|
+
"https://api.denayrestapi.xyz/api/private/qris?op=submit-proof",
|
|
77
|
+
requestBody,
|
|
78
|
+
{
|
|
79
|
+
headers: {
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
"x-api-key": apikey,
|
|
82
|
+
...(signature && { "x-signature": signature }),
|
|
83
|
+
"x-timestamp": timestamp,
|
|
84
|
+
"x-request-id": requestId,
|
|
85
|
+
},
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return data;
|
|
90
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dra-qris-api",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Connector for QRIS API DenayRestAPI ",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"draqrisapi"
|
|
11
|
+
],
|
|
12
|
+
"author": "IrukaIndieDevs",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"axios": "^1.12.2",
|
|
15
|
+
"crypto": "^1.0.1"
|
|
16
|
+
}
|
|
17
|
+
}
|