Skip to content

Commit 2fa55c8

Browse files
add pesalink code snippets
1 parent 9005860 commit 2fa55c8

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
languages:
2+
- sh
3+
- js
4+
- php
5+
- json
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+
"email": "[email protected]",
5+
"amount": "10000",
6+
"bank_transfer": {
7+
"account_expires_at": "2025-04-24T16:40:57.954Z"
8+
}
9+
})
10+
11+
const options = {
12+
hostname: 'api.paystack.co',
13+
port: 443,
14+
path: '/charge',
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()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"status": true,
3+
"message": "Charge attempted",
4+
"data": {
5+
"reference": "kcvu0t3kzs",
6+
"status": "pending_bank_transfer",
7+
"display_text": "Please make a transfer to the account specified",
8+
"account_name": "Paystack Payments Kenya Limited",
9+
"account_number": "1260257501",
10+
"bank": {
11+
"slug": "diamond-trust-bank-ltd-ke",
12+
"name": "Diamond Trust Bank Kenya Ltd",
13+
"id": 225
14+
},
15+
"account_expires_at": "2025-04-24T16:55:57.954Z"
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
$curl = curl_init();
3+
4+
curl_setopt_array($curl, array(
5+
CURLOPT_URL => "https://api.paystack.co/charge",
6+
CURLOPT_RETURNTRANSFER => true,
7+
CURLOPT_ENCODING => "",
8+
CURLOPT_MAXREDIRS => 10,
9+
CURLOPT_TIMEOUT => 30,
10+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
11+
CURLOPT_CUSTOMREQUEST => "POST",
12+
CURLOPT_POSTFIELDS => [
13+
"email" => "[email protected]",
14+
"amount" => "10000",
15+
"bank_transfer" => [
16+
"account_expires_at" => "2025-04-24T16:40:57.954Z"
17+
]
18+
],
19+
CURLOPT_HTTPHEADER => array(
20+
"Authorization: Bearer SECRET_KEY",
21+
"Cache-Control: no-cache"
22+
),
23+
));
24+
25+
$response = curl_exec($curl);
26+
$err = curl_error($curl);
27+
28+
curl_close($curl);
29+
30+
if ($err) {
31+
echo "cURL Error #:" . $err;
32+
} else {
33+
echo $response;
34+
}
35+
?>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
url="https://api.paystack.co/charge"
4+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
5+
content_type="Content-Type: application/json"
6+
data='{
7+
"email": "[email protected]",
8+
"amount": "10000",
9+
"bank_transfer": {
10+
"account_expires_at": "2025-04-24T16:40:57.954Z"
11+
}
12+
}'
13+
14+
curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST

0 commit comments

Comments
 (0)