-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathsnapBiRefund.js
119 lines (93 loc) · 3.39 KB
/
snapBiRefund.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const midtransClient = require('midtrans-client'); // use this if installed via NPM
// This is just for very basic implementation reference, in production, you should validate the incoming requests and implement your backend more securely.
const { randomUUID } = require('crypto');
/**
* Setup your credentials here to try the example code.
*/
const clientId = "Zabcdefg-MIDTRANS-CLIENT-SNAP";
// Ensure to include newlines properly in the private key as shown below
const private_key = `-----BEGIN PRIVATE KEY-----
BCDEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7Zk6kJjqamLddaN1lK03XJW3vi5zOSA7V+5eSiYeM9tCOGouJewN/Py58wgvRh7OMAMm1IbSZpAbcZbBa1=
-----END PRIVATE KEY-----`;
const clientSecret = "ABcdefghiSrLJPgKRXqdjaSAuj5WDAbeaXAX8Vn7CWGHuBCfFgABCDVqRLvNZf8BaqPGKaksMjrZDrZqzZEbaA1AYFwBewIWCqLZr4PuvuLBqfTmYIzAbCakHKejABCa";
const partnerId = "partner-id";
const merchantId = "M001234";
const channelId = "12345";
const externalId = randomUUID();
midtransClient.SnapBiConfig.snapBiPrivateKey = private_key;
midtransClient.SnapBiConfig.snapBiClientSecret = clientSecret;
midtransClient.SnapBiConfig.snapBiPartnerId = partnerId;
midtransClient.SnapBiConfig.snapBiChannelId = channelId;
midtransClient.SnapBiConfig.snapBiClientId = clientId
midtransClient.SnapBiConfig.enableLogging = true;
const externalId = randomUUID();
let directDebitRefundBody = {
"originalReferenceNo": "A1202409300808041pswnOt7wMID",
"reason" : "refund reason"
}
let qrisRefundBody = {
"merchantId": merchantId,
"originalPartnerReferenceNo": "488fd30e-64d7-4236-9e7a-82d55d9efad3",
"originalReferenceNo": "A1202409300907114b5RZRNSRuID",
"partnerRefundNo": "is-refund-12345",
"reason": "refund reason",
"refundAmount": {
"value": "100.00",
"currency": "IDR"
},
"additionalInfo": {
"foo": "bar"
}
}
let additionalHeader = {
"X-device-id": "your device id",
"debug-id": "your debug id"
}
/**
* Example code for refund using Direct Debit (gopay/ dana/ shopeepay).
*/
midtransClient.SnapBi.directDebit()
.withBody(directDebitRefundBody)
.refund(externalId)
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)
midtransClient.SnapBi.directDebit()
.withBody(directDebitRefundBody)
.withAccessToken("your access token")
.refund(externalId)
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)
midtransClient.SnapBi.directDebit()
.withBody(directDebitRefundBody)
.withAccessTokenHeader(additionalHeader)
.withTransactionHeader(additionalHeader)
.refund(externalId)
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)
/**
* Example code for refund using Qris,
*/
midtransClient.SnapBi.qris()
.withBody(qrisRefundBody)
.refund(externalId)
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)
midtransClient.SnapBi.qris()
.withBody(qrisRefundBody)
.withAccessToken("your access token")
.refund(externalId)
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)
midtransClient.SnapBi.qris()
.withBody(qrisRefundBody)
.withAccessTokenHeader(additionalHeader)
.withTransactionHeader(additionalHeader)
.refund("408c0226-c53d-4dd7-8d79-ce3c09278de0")
.then(r =>
console.log("Snap Bi result: " + JSON.stringify(r, null, 2))
)