Skip to content

Commit fe55426

Browse files
add mpesa offline
1 parent 2108aed commit fe55426

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const sh = `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+
"phone": "254700000000",
9+
"provider" : "mpesa_offline"
10+
}
11+
}'
12+
-X POST`
13+
14+
const js = `const https = require('https')
15+
16+
const params = JSON.stringify({
17+
"amount": 100,
18+
"email": "[email protected]",
19+
"currency": "KES",
20+
"mobile_money": {
21+
"phone": "254700000000",
22+
"provider" : "mpesa_offline"
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+
56+
$curl = curl_init();
57+
58+
curl_setopt_array($curl, array(
59+
CURLOPT_URL => "https://api.paystack.co/charge",
60+
CURLOPT_RETURNTRANSFER => true,
61+
CURLOPT_ENCODING => "",
62+
CURLOPT_MAXREDIRS => 10,
63+
CURLOPT_TIMEOUT => 30,
64+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
65+
CURLOPT_CUSTOMREQUEST => "POST",
66+
CURLOPT_POSTFIELDS => [
67+
"amount" => 100,
68+
"email" => "[email protected]",
69+
"currency" => "KES",
70+
"mobile_money" => [
71+
"phone" => "254700000000",
72+
"provider" => "mpesa_offline"
73+
]
74+
],
75+
CURLOPT_HTTPHEADER => array(
76+
"Authorization: Bearer SECRET_KEY",
77+
"Content-Type: application/json"
78+
),
79+
));
80+
81+
$response = curl_exec($curl);
82+
$err = curl_error($curl);
83+
84+
curl_close($curl);
85+
86+
if ($err) {
87+
echo "cURL Error #:" . $err;
88+
} else {
89+
echo $response;
90+
}`
91+
92+
const json = `{
93+
"status": true,
94+
"message": "Charge attempted",
95+
"data": {
96+
"reference": "e6i9ak3rbq982wh",
97+
"status": "pay_offline",
98+
"display_text": "Please complete authorization process on your mobile phone",
99+
"account_number": "4084333",
100+
"account_reference": 1234567
101+
}
102+
}`
103+
104+
export {sh, js, php, json}
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: 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+
"phone": "254700000000",
9+
"provider" : "mpesa_offline"
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"status": true,
3+
"message": "Charge attempted",
4+
"data": {
5+
"reference": "e6i9ak3rbq982wh",
6+
"status": "pay_offline",
7+
"display_text": "Please complete authorization process on your mobile phone",
8+
"account_number": "4084333",
9+
"account_reference": 1234567
10+
}
11+
}
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+
"phone" => "254700000000",
19+
"provider" => "mpesa_offline"
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+
"phone": "254700000000",
9+
"provider" : "mpesa_offline"
10+
}
11+
}'
12+
-X POST

0 commit comments

Comments
 (0)