Skip to content

Commit c7e2f2b

Browse files
Merge pull request #114 from PaystackOSS/patch-refunds
patch: add new refund snippets
2 parents 8d82f9d + cb4c1d9 commit c7e2f2b

File tree

15 files changed

+539
-1
lines changed

15 files changed

+539
-1
lines changed

dist/api/refunds/retry/requests.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
const sh = `#!/bin/sh
2+
url="https://api.paystack.co/refundretry_with_customer_details/{id}"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
content_type="Content-Type: application/json"
5+
data='{
6+
"refund_account_details": {
7+
"currency": "NGN",
8+
"account_number": "1234567890",
9+
"bank_id": "9"
10+
}
11+
}'
12+
13+
curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST`
14+
15+
const js = `const https = require('https')
16+
17+
const params = JSON.stringify({
18+
"refund_account_details": {
19+
"currency": "NGN",
20+
"account_number": "1234567890",
21+
"bank_id": "9"
22+
}
23+
})
24+
25+
const options = {
26+
hostname: 'api.paystack.co',
27+
port: 443,
28+
path: '/refund/retry_with_customer_details/{id}',
29+
method: 'POST',
30+
headers: {
31+
Authorization: 'Bearer SECRET_KEY',
32+
'Content-Type': 'application/json'
33+
}
34+
}
35+
36+
const req = https.request(options, res => {
37+
let data = ''
38+
39+
res.on('data', (chunk) => {
40+
data += chunk
41+
});
42+
43+
res.on('end', () => {
44+
console.log(JSON.parse(data))
45+
})
46+
}).on('error', error => {
47+
console.error(error)
48+
})
49+
50+
req.write(params)
51+
req.end()`
52+
53+
const php = `<?php
54+
$url = "https://api.paystack.co/refund/retry_with_customer_details/{id}";
55+
56+
$fields = [
57+
'transaction' => 1641,
58+
"refund_account_details" => [
59+
"currency" => "NGN",
60+
"account_number" => "1234567890",
61+
"bank_id" => "9"
62+
]
63+
];
64+
65+
$fields_string = http_build_query($fields);
66+
67+
//open connection
68+
$ch = curl_init();
69+
70+
//set the url, number of POST vars, POST data
71+
curl_setopt($ch, CURLOPT_URL, $url);
72+
curl_setopt($ch, CURLOPT_POST, true);
73+
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
74+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
75+
"Authorization: Bearer SECRET_KEY",
76+
"Cache-Control: no-cache",
77+
));
78+
79+
//So that curl_exec returns the contents of the cURL; rather than echoing it
80+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
81+
82+
//execute post
83+
$result = curl_exec($ch);
84+
echo $result;
85+
`
86+
87+
export {sh, js, php}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Refund retried and has been queued for processing",
7+
"data": {
8+
"integration": 123456,
9+
"transaction": 3298598423,
10+
"dispute": null,
11+
"settlement": null,
12+
"id": 1234567,
13+
"domain": "live",
14+
"currency": "NGN",
15+
"amount": 20000,
16+
"status": "processing",
17+
"refunded_at": null,
18+
"expected_at": "2025-10-13T16:02:18.000Z",
19+
"channel": "isw_3ds",
20+
"refunded_by": "[email protected]",
21+
"customer_note": "Refund for transaction T708775813895475",
22+
"merchant_note": "Refund for transaction T708775813895475 by [email protected]",
23+
"deducted_amount": 20000,
24+
"fully_deducted": true,
25+
"bank_reference": null,
26+
"reason": "PROCESSING",
27+
"customer": null,
28+
"initiated_by": "[email protected]",
29+
"reversed_at": null,
30+
"session_id": null
31+
}
32+
}
33+
},
34+
"422": {
35+
"description": "422",
36+
"data": {
37+
"status": false,
38+
"message": "Invalid Refund state, refund status should be \"needs-attention\"",
39+
"meta": {
40+
"nextStep": "Ensure that the value(s) you're passing are valid."
41+
},
42+
"type": "validation_error",
43+
"code": "invalid_params"
44+
}
45+
}
46+
}

dist/doc/payments/refunds/events.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,27 @@ const refund_failed = `{
1717
}
1818
}`
1919

20+
const refund_needs_attention = `{
21+
"event": "refund.needs-attention",
22+
"data": {
23+
"status": "needs-attention",
24+
"transaction_reference": "88bfa94509eb96aa9785641c26cc57cc",
25+
"refund_reference": "TRF_7jn17u9vkqm91efk",
26+
"amount": 5306,
27+
"currency": "NGN",
28+
"customer": {
29+
"first_name": null,
30+
"last_name": null,
31+
"email": "[email protected]"
32+
},
33+
"integration": 123456,
34+
"domain": "live",
35+
"id": "123456",
36+
"customer_note": "Refund for transaction 88bfa94509eb96aa9785641c26cc57cc",
37+
"merchant_note": "Refund for transaction 88bfa94509eb96aa9785641c26cc57cc by [email protected]"
38+
}
39+
}`
40+
2041
const refund_pending = `{
2142
"event": "refund.pending",
2243
"data": {
@@ -74,4 +95,4 @@ const refund_processing = `{
7495
}
7596
}`
7697

77-
export {refund_failed, refund_pending, refund_processed, refund_processing}
98+
export {refund_failed, refund_needs_attention, refund_pending, refund_processed, refund_processing}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
const sh = `#!/bin/sh
2+
url="https://api.paystack.co/refundretry_with_customer_details/{id}"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
content_type="Content-Type: application/json"
5+
data='{
6+
"refund_account_details": {
7+
"currency": "NGN",
8+
"account_number": "1234567890",
9+
"bank_id": "9"
10+
}
11+
}'
12+
13+
curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST`
14+
15+
const js = `const https = require('https')
16+
17+
const params = JSON.stringify({
18+
"refund_account_details": {
19+
"currency": "NGN",
20+
"account_number": "1234567890",
21+
"bank_id": "9"
22+
}
23+
})
24+
25+
const options = {
26+
hostname: 'api.paystack.co',
27+
port: 443,
28+
path: '/refund/retry_with_customer_details/{id}',
29+
method: 'POST',
30+
headers: {
31+
Authorization: 'Bearer SECRET_KEY',
32+
'Content-Type': 'application/json'
33+
}
34+
}
35+
36+
const req = https.request(options, res => {
37+
let data = ''
38+
39+
res.on('data', (chunk) => {
40+
data += chunk
41+
});
42+
43+
res.on('end', () => {
44+
console.log(JSON.parse(data))
45+
})
46+
}).on('error', error => {
47+
console.error(error)
48+
})
49+
50+
req.write(params)
51+
req.end()`
52+
53+
const php = `<?php
54+
$url = "https://api.paystack.co/refund/retry_with_customer_details/{id}";
55+
56+
$fields = [
57+
'transaction' => 1641,
58+
"refund_account_details" => [
59+
"currency" => "NGN",
60+
"account_number" => "1234567890",
61+
"bank_id" => "9"
62+
]
63+
];
64+
65+
$fields_string = http_build_query($fields);
66+
67+
//open connection
68+
$ch = curl_init();
69+
70+
//set the url, number of POST vars, POST data
71+
curl_setopt($ch, CURLOPT_URL, $url);
72+
curl_setopt($ch, CURLOPT_POST, true);
73+
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
74+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
75+
"Authorization: Bearer SECRET_KEY",
76+
"Cache-Control: no-cache",
77+
));
78+
79+
//So that curl_exec returns the contents of the cURL; rather than echoing it
80+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
81+
82+
//execute post
83+
$result = curl_exec($ch);
84+
echo $result;`
85+
86+
const json = `{
87+
"status": true,
88+
"message": "Refund retried and has been queued for processing",
89+
"data": {
90+
"integration": 123456,
91+
"transaction": 3298598423,
92+
"dispute": null,
93+
"settlement": null,
94+
"id": 1234567,
95+
"domain": "live",
96+
"currency": "NGN",
97+
"amount": 20000,
98+
"status": "processing",
99+
"refunded_at": null,
100+
"expected_at": "2025-10-13T16:02:18.000Z",
101+
"channel": "isw_3ds",
102+
"refunded_by": "[email protected]",
103+
"customer_note": "Refund for transaction T708775813895475",
104+
"merchant_note": "Refund for transaction T708775813895475 by [email protected]",
105+
"deducted_amount": 20000,
106+
"fully_deducted": true,
107+
"bank_reference": null,
108+
"reason": "PROCESSING",
109+
"customer": null,
110+
"initiated_by": "[email protected]",
111+
"reversed_at": null,
112+
"session_id": null
113+
}
114+
}`
115+
116+
export {sh, js, php, json}

src/api/refunds/retry/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
languages:
2+
- sh
3+
- js
4+
- php

src/api/refunds/retry/index.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const https = require('https')
2+
3+
const params = JSON.stringify({
4+
"refund_account_details": {
5+
"currency": "NGN",
6+
"account_number": "1234567890",
7+
"bank_id": "9"
8+
}
9+
})
10+
11+
const options = {
12+
hostname: 'api.paystack.co',
13+
port: 443,
14+
path: '/refund/retry_with_customer_details/{id}',
15+
method: 'POST',
16+
headers: {
17+
Authorization: 'Bearer SECRET_KEY',
18+
'Content-Type': 'application/json'
19+
}
20+
}
21+
22+
const req = https.request(options, res => {
23+
let data = ''
24+
25+
res.on('data', (chunk) => {
26+
data += chunk
27+
});
28+
29+
res.on('end', () => {
30+
console.log(JSON.parse(data))
31+
})
32+
}).on('error', error => {
33+
console.error(error)
34+
})
35+
36+
req.write(params)
37+
req.end()

src/api/refunds/retry/index.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
$url = "https://api.paystack.co/refund/retry_with_customer_details/{id}";
3+
4+
$fields = [
5+
'transaction' => 1641,
6+
"refund_account_details" => [
7+
"currency" => "NGN",
8+
"account_number" => "1234567890",
9+
"bank_id" => "9"
10+
]
11+
];
12+
13+
$fields_string = http_build_query($fields);
14+
15+
//open connection
16+
$ch = curl_init();
17+
18+
//set the url, number of POST vars, POST data
19+
curl_setopt($ch, CURLOPT_URL, $url);
20+
curl_setopt($ch, CURLOPT_POST, true);
21+
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
22+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
23+
"Authorization: Bearer SECRET_KEY",
24+
"Cache-Control: no-cache",
25+
));
26+
27+
//So that curl_exec returns the contents of the cURL; rather than echoing it
28+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
29+
30+
//execute post
31+
$result = curl_exec($ch);
32+
echo $result;

src/api/refunds/retry/index.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
url="https://api.paystack.co/refundretry_with_customer_details/{id}"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
content_type="Content-Type: application/json"
5+
data='{
6+
"refund_account_details": {
7+
"currency": "NGN",
8+
"account_number": "1234567890",
9+
"bank_id": "9"
10+
}
11+
}'
12+
13+
curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST

0 commit comments

Comments
 (0)