Skip to content

Commit b3d5663

Browse files
Add mpesa till request response
1 parent 107e08d commit b3d5663

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed
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
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const https = require('https')
2+
3+
const params = JSON.stringify({
4+
"amount": 100,
5+
"email": "[email protected]",
6+
"currency": "KES",
7+
"mobile_money": {
8+
"account" : "1234567",
9+
"provider" : "mptill"
10+
}
11+
})
12+
13+
const options = {
14+
hostname: 'api.paystack.co',
15+
port: 443,
16+
path: '/charge',
17+
method: 'POST',
18+
headers: {
19+
Authorization: 'Bearer SECRET_KEY',
20+
'Content-Type': 'application/json'
21+
}
22+
}
23+
24+
const req = https.request(options, res => {
25+
let data = ''
26+
27+
res.on('data', (chunk) => {
28+
data += chunk
29+
});
30+
31+
res.on('end', () => {
32+
console.log(JSON.parse(data))
33+
})
34+
}).on('error', error => {
35+
console.error(error)
36+
})
37+
38+
req.write(params)
39+
req.end()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
$curl = curl_init();
4+
5+
curl_setopt_array($curl, array(
6+
CURLOPT_URL => "https://api.paystack.co/charge",
7+
CURLOPT_RETURNTRANSFER => true,
8+
CURLOPT_ENCODING => "",
9+
CURLOPT_MAXREDIRS => 10,
10+
CURLOPT_TIMEOUT => 30,
11+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
12+
CURLOPT_CUSTOMREQUEST => "POST",
13+
CURLOPT_POSTFIELDS => [
14+
"amount" => 100,
15+
"email" => "[email protected]",
16+
"currency" => "KES",
17+
"mobile_money" => [
18+
"account" => "1234567",
19+
"provider" => "mptill"
20+
]
21+
],
22+
CURLOPT_HTTPHEADER => array(
23+
"Authorization: Bearer SECRET_KEY",
24+
"Content-Type: application/json"
25+
),
26+
));
27+
28+
$response = curl_exec($curl);
29+
$err = curl_error($curl);
30+
31+
curl_close($curl);
32+
33+
if ($err) {
34+
echo "cURL Error #:" . $err;
35+
} else {
36+
echo $response;
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
curl https://api.paystack.co/charge
2+
-H "Authorization: Bearer YOUR_SECRET_KEY"
3+
-H "Content-Type: application/json"
4+
-d '{ "amount": 100,
5+
"email": "[email protected]",
6+
"currency": "KES",
7+
"mobile_money": {
8+
"account" : "1234567",
9+
"provider" : "mptill"
10+
}
11+
}'
12+
-X POST

0 commit comments

Comments
 (0)