Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions dist/doc/payments/direct-debit/charge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const sh = `#!/bin/sh
curl https://api.paystack.co/charge
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{
"email": "ravi@demo.com",
"amount": "1000000",
"currency": "NGN",
"direct_debit": {
"account": { "number": "0123456789", "bank_code": "057" },
"address": { "street": "126 Joel Ogunnaike", "city": "Ikeja", "state": "Lagos", "country": "NG" },
"phone": "+2348012345678"
}
}'
-X POST`

const js = `const https = require('https')

const params = JSON.stringify({
"email": "ravi@demo.com",
"amount": 1000000,
"currency": "NGN",
"direct_debit": {
"account": { "number": "0123456789", "bank_code": "057" },
"address": { "street": "126 Joel Ogunnaike", "city": "Ikeja", "state": "Lagos", "country": "NG" },
"phone": "+2348012345678"
}
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/charge',
method: 'POST',
headers: {
Authorization: 'Bearer SECRET_KEY',
'Content-Type': 'application/json'
}
}

const req = https.request(options, res => {
let data = ''

res.on('data', (chunk) => {
data += chunk
});

res.on('end', () => {
console.log(JSON.parse(data))
})
}).on('error', error => {
console.error(error)
})

req.write(params)
req.end()`

const php = `<?php
$url = "https://api.paystack.co/charge";

$fields = [
'email' => "ravi@demo.com",
'amount' => "1000000",
'currency' => "NGN",
'direct_debit' => [
'account' => [
'number' => "0123456789",
'bank_code' => "057"
],
'address' => [
'street' => "126 Joel Ogunnaike",
'city' => "Ikeja",
'state' => "Lagos",
'country' => "NG"
],
'phone' => "+2348012345678"
]
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>`

const json = `{
"status": true,
"message": "Charge attempted",
"data": {
"reference": "dd-charge-8f3a1c",
"status": "pending_bank_transfer",
"amount": 1000000,
"account_number": "1234567890",
"bank_name": "Test Bank"
}
}`

export {sh, js, php, json}
5 changes: 5 additions & 0 deletions src/doc/payments/direct-debit/charge/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
languages:
- sh
- js
- php
- json
40 changes: 40 additions & 0 deletions src/doc/payments/direct-debit/charge/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const https = require('https')

const params = JSON.stringify({
"email": "ravi@demo.com",
"amount": 1000000,
"currency": "NGN",
"direct_debit": {
"account": { "number": "0123456789", "bank_code": "057" },
"address": { "street": "126 Joel Ogunnaike", "city": "Ikeja", "state": "Lagos", "country": "NG" },
"phone": "+2348012345678"
}
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/charge',
method: 'POST',
headers: {
Authorization: 'Bearer SECRET_KEY',
'Content-Type': 'application/json'
}
}

const req = https.request(options, res => {
let data = ''

res.on('data', (chunk) => {
data += chunk
});

res.on('end', () => {
console.log(JSON.parse(data))
})
}).on('error', error => {
console.error(error)
})

req.write(params)
req.end()
11 changes: 11 additions & 0 deletions src/doc/payments/direct-debit/charge/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"status": true,
"message": "Charge attempted",
"data": {
"reference": "dd-charge-8f3a1c",
"status": "pending_bank_transfer",
"amount": 1000000,
"account_number": "1234567890",
"bank_name": "Test Bank"
}
}
43 changes: 43 additions & 0 deletions src/doc/payments/direct-debit/charge/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
$url = "https://api.paystack.co/charge";

$fields = [
'email' => "ravi@demo.com",
'amount' => "1000000",
'currency' => "NGN",
'direct_debit' => [
'account' => [
'number' => "0123456789",
'bank_code' => "057"
],
'address' => [
'street' => "126 Joel Ogunnaike",
'city' => "Ikeja",
'state' => "Lagos",
'country' => "NG"
],
'phone' => "+2348012345678"
]
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>
15 changes: 15 additions & 0 deletions src/doc/payments/direct-debit/charge/index.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
curl https://api.paystack.co/charge
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{
"email": "ravi@demo.com",
"amount": "1000000",
"currency": "NGN",
"direct_debit": {
"account": { "number": "0123456789", "bank_code": "057" },
"address": { "street": "126 Joel Ogunnaike", "city": "Ikeja", "state": "Lagos", "country": "NG" },
"phone": "+2348012345678"
}
}'
-X POST