Skip to content

Commit f04bf5a

Browse files
generate code snippets
1 parent 2fa55c8 commit f04bf5a

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const sh = `#!/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`
15+
16+
const js = `const https = require('https')
17+
18+
const params = JSON.stringify({
19+
"email": "[email protected]",
20+
"amount": "10000",
21+
"bank_transfer": {
22+
"account_expires_at": "2025-04-24T16:40:57.954Z"
23+
}
24+
})
25+
26+
const options = {
27+
hostname: 'api.paystack.co',
28+
port: 443,
29+
path: '/charge',
30+
method: 'POST',
31+
headers: {
32+
Authorization: 'Bearer SECRET_KEY',
33+
'Content-Type': 'application/json'
34+
}
35+
}
36+
37+
const req = https.request(options, res => {
38+
let data = ''
39+
40+
res.on('data', (chunk) => {
41+
data += chunk
42+
});
43+
44+
res.on('end', () => {
45+
console.log(JSON.parse(data))
46+
})
47+
}).on('error', error => {
48+
console.error(error)
49+
})
50+
51+
req.write(params)
52+
req.end()`
53+
54+
const php = `<?php
55+
$curl = curl_init();
56+
57+
curl_setopt_array($curl, array(
58+
CURLOPT_URL => "https://api.paystack.co/charge",
59+
CURLOPT_RETURNTRANSFER => true,
60+
CURLOPT_ENCODING => "",
61+
CURLOPT_MAXREDIRS => 10,
62+
CURLOPT_TIMEOUT => 30,
63+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
64+
CURLOPT_CUSTOMREQUEST => "POST",
65+
CURLOPT_POSTFIELDS => [
66+
"email" => "[email protected]",
67+
"amount" => "10000",
68+
"bank_transfer" => [
69+
"account_expires_at" => "2025-04-24T16:40:57.954Z"
70+
]
71+
],
72+
CURLOPT_HTTPHEADER => array(
73+
"Authorization: Bearer SECRET_KEY",
74+
"Cache-Control: no-cache"
75+
),
76+
));
77+
78+
$response = curl_exec($curl);
79+
$err = curl_error($curl);
80+
81+
curl_close($curl);
82+
83+
if ($err) {
84+
echo "cURL Error #:" . $err;
85+
} else {
86+
echo $response;
87+
}
88+
?>`
89+
90+
const json = `{
91+
"status": true,
92+
"message": "Charge attempted",
93+
"data": {
94+
"reference": "kcvu0t3kzs",
95+
"status": "pending_bank_transfer",
96+
"display_text": "Please make a transfer to the account specified",
97+
"account_name": "Paystack Payments Kenya Limited",
98+
"account_number": "1260257501",
99+
"bank": {
100+
"slug": "diamond-trust-bank-ltd-ke",
101+
"name": "Diamond Trust Bank Kenya Ltd",
102+
"id": 225
103+
},
104+
"account_expires_at": "2025-04-24T16:55:57.954Z"
105+
}
106+
}`
107+
108+
export {sh, js, php, json}

0 commit comments

Comments
 (0)