Skip to content

Commit 4b420cf

Browse files
Merge pull request #104 from PaystackOSS/patch-dd
Chore: Update DD code snippets
2 parents bf6cb56 + fd4a75c commit 4b420cf

File tree

55 files changed

+1462
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1462
-2
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const sh = `#!/bin/sh
2+
curl https://api.paystack.co/customer/{id}/directdebit-activation-charge
3+
-H "Authorization: Bearer YOUR_SECRET_KEY"
4+
-H "Content-Type: application/json"
5+
-d '{
6+
"authorization_id" : 1069309917
7+
}'
8+
-X PUT`
9+
10+
const js = `const https = require('https')
11+
12+
const params = JSON.stringify({
13+
"authorization_id" : 1069309917
14+
})
15+
16+
const options = {
17+
hostname: 'api.paystack.co',
18+
port: 443,
19+
path: '/customer/{id}/directdebit-activation-charge',
20+
method: 'PUT',
21+
headers: {
22+
Authorization: 'Bearer SECRET_KEY',
23+
'Content-Type': 'application/json'
24+
}
25+
}
26+
27+
const req = https.request(options, res => {
28+
let data = ''
29+
30+
res.on('data', (chunk) => {
31+
data += chunk
32+
});
33+
34+
res.on('end', () => {
35+
console.log(JSON.parse(data))
36+
})
37+
}).on('error', error => {
38+
console.error(error)
39+
})
40+
41+
req.write(params)
42+
req.end()`
43+
44+
const php = `<?php
45+
$url = "https://api.paystack.co/customer/{id}/directdebit-activation-charge";
46+
47+
$fields = [
48+
'authorization_id' => 1069309917
49+
];
50+
51+
$fields_string = http_build_query($fields);
52+
53+
//open connection
54+
$ch = curl_init();
55+
56+
//set the url, PUT data
57+
curl_setopt($ch,CURLOPT_URL, $url);
58+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
59+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
60+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
61+
"Authorization: Bearer SECRET_KEY",
62+
"Cache-Control: no-cache",
63+
));
64+
65+
//So that curl_exec returns the contents of the cURL; rather than echoing it
66+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
67+
68+
//execute post
69+
$result = curl_exec($ch);
70+
echo $result;
71+
?>`
72+
73+
export {sh, js, php}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Mandate is queued for retry"
7+
}
8+
}
9+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const sh = `#!/bin/sh
2+
url="https://api.paystack.co/customer/{id}/directdebit-mandate-authorizations"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
5+
curl "$url" -H "$authorization" -X GET`
6+
7+
const js = `const https = require('https')
8+
9+
const options = {
10+
hostname: 'api.paystack.co',
11+
port: 443,
12+
path: '/customer/{id}/directdebit-mandate-authorizations',
13+
method: 'GET',
14+
headers: {
15+
Authorization: 'Bearer SECRET_KEY'
16+
}
17+
}
18+
19+
https.request(options, res => {
20+
let data = ''
21+
22+
res.on('data', (chunk) => {
23+
data += chunk
24+
});
25+
26+
res.on('end', () => {
27+
console.log(JSON.parse(data))
28+
})
29+
}).on('error', error => {
30+
console.error(error)
31+
})`
32+
33+
const php = `<?php
34+
$curl = curl_init();
35+
36+
curl_setopt_array($curl, array(
37+
CURLOPT_URL => "https://api.paystack.co//customer/{id}/directdebit-mandate-authorizations",
38+
CURLOPT_RETURNTRANSFER => true,
39+
CURLOPT_ENCODING => "",
40+
CURLOPT_MAXREDIRS => 10,
41+
CURLOPT_TIMEOUT => 30,
42+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
43+
CURLOPT_CUSTOMREQUEST => "GET",
44+
CURLOPT_HTTPHEADER => array(
45+
"Authorization: Bearer SECRET_KEY",
46+
"Cache-Control: no-cache",
47+
),
48+
));
49+
50+
$response = curl_exec($curl);
51+
$err = curl_error($curl);
52+
53+
curl_close($curl);
54+
55+
if ($err) {
56+
echo "cURL Error #:" . $err;
57+
} else {
58+
echo $response;
59+
}
60+
?>`
61+
62+
export {sh, js, php}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Mandate authorizations retrieved successfully",
7+
"data": [
8+
{
9+
"id": 164098,
10+
"status": "active",
11+
"mandate_id": 512003,
12+
"authorization_id": 110049014,
13+
"authorization_code": "AUTH_8Lol0pNt14",
14+
"integration_id": 463433,
15+
"account_number": "0123456789",
16+
"bank_code": "032",
17+
"bank_name": null,
18+
"customer": {
19+
"id": 43975700,
20+
"customer_code": "CUS_2eusy8uwe34s23fy",
21+
"email": "customer@email.com",
22+
"first_name": "Smith",
23+
"last_name": "Bel"
24+
},
25+
"authorized_at": "2024-09-27T10:57:53.824Z"
26+
}
27+
],
28+
"meta": {
29+
"per_page": 50,
30+
"next": null,
31+
"count": 1,
32+
"total": 1
33+
}
34+
}
35+
}
36+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
const sh = `#!/bin/sh
2+
url="https://api.paystack.co/customer/{id}/initialize-direct-debit"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
content_type="Content-Type: application/json"
5+
data='{
6+
"account": {
7+
"number": "0123456789",
8+
"bank_code": "058"
9+
},
10+
"address": {
11+
"street": "Some Where",
12+
"city": "Ikeja",
13+
"state": "Lagos"
14+
}
15+
}'
16+
17+
curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST`
18+
19+
const js = `const https = require('https')
20+
21+
const params = JSON.stringify({
22+
"account": {
23+
"number": "0123456789",
24+
"bank_code": "058"
25+
},
26+
"address": {
27+
"street": "Some Where",
28+
"city": "Ikeja",
29+
"state": "Lagos"
30+
}
31+
})
32+
33+
const options = {
34+
hostname: 'api.paystack.co',
35+
port: 443,
36+
path: '/customer/{id}/initialize-direct-debit',
37+
method: 'POST',
38+
headers: {
39+
Authorization: 'Bearer SECRET_KEY',
40+
'Content-Type': 'application/json'
41+
}
42+
}
43+
44+
const req = https.request(options, res => {
45+
let data = ''
46+
47+
res.on('data', (chunk) => {
48+
data += chunk
49+
});
50+
51+
res.on('end', () => {
52+
console.log(JSON.parse(data))
53+
})
54+
}).on('error', error => {
55+
console.error(error)
56+
})
57+
58+
req.write(params)
59+
req.end()`
60+
61+
const php = `<?php
62+
$url = "https://api.paystack.co/customer/{id}/initialize-direct-debit";
63+
64+
$fields = [
65+
'account' => [
66+
'number' => '0123456789',
67+
'bank_code' => '058'
68+
],
69+
'address' => [
70+
'street' => 'Some Where',
71+
'city' => 'Ikeja',
72+
'state' => 'Lagos'
73+
]
74+
];
75+
76+
$fields_string = http_build_query($fields);
77+
78+
//open connection
79+
$ch = curl_init();
80+
81+
//set the url, number of POST vars, POST data
82+
curl_setopt($ch,CURLOPT_URL, $url);
83+
curl_setopt($ch,CURLOPT_POST, true);
84+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
85+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
86+
"Authorization: Bearer SECRET_KEY",
87+
"Cache-Control: no-cache",
88+
));
89+
90+
//So that curl_exec returns the contents of the cURL; rather than echoing it
91+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
92+
93+
//execute post
94+
$result = curl_exec($ch);
95+
echo $result;
96+
?>`
97+
98+
export {sh, js, php}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Authorization initialized",
7+
"data": {
8+
"redirect_url": "https://link.paystack.com/ll6b0szngj1f27k",
9+
"access_code": "ll6b0szngj1f27k",
10+
"reference": "1er945lpy4txyki"
11+
}
12+
}
13+
}
14+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const sh = `#!/bin/sh
2+
curl https://api.paystack.co/directdebit/activation-charge
3+
-H "Authorization: Bearer YOUR_SECRET_KEY"
4+
-H "Content-Type: application/json"
5+
-d '{
6+
"customer_ids": [28958104, 983697220]
7+
}'
8+
-X PUT`
9+
10+
const js = `const https = require('https')
11+
12+
const params = JSON.stringify({
13+
"customer_ids": [28958104, 983697220]
14+
})
15+
16+
const options = {
17+
hostname: 'api.paystack.co',
18+
port: 443,
19+
path: '/directdebit/activation-charge',
20+
method: 'PUT',
21+
headers: {
22+
Authorization: 'Bearer SECRET_KEY',
23+
'Content-Type': 'application/json'
24+
}
25+
}
26+
27+
const req = https.request(options, res => {
28+
let data = ''
29+
30+
res.on('data', (chunk) => {
31+
data += chunk
32+
});
33+
34+
res.on('end', () => {
35+
console.log(JSON.parse(data))
36+
})
37+
}).on('error', error => {
38+
console.error(error)
39+
})
40+
41+
req.write(params)
42+
req.end()`
43+
44+
const php = `<?php
45+
$url = "https://api.paystack.co/directdebit/activation-charge";
46+
47+
$fields = [
48+
'customer_ids' => [28958104, 983697220]
49+
];
50+
51+
$fields_string = http_build_query($fields);
52+
53+
//open connection
54+
$ch = curl_init();
55+
56+
//set the url, PUT data
57+
curl_setopt($ch,CURLOPT_URL, $url);
58+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
59+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
60+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
61+
"Authorization: Bearer SECRET_KEY",
62+
"Cache-Control: no-cache",
63+
));
64+
65+
//So that curl_exec returns the contents of the cURL; rather than echoing it
66+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
67+
68+
//execute post
69+
$result = curl_exec($ch);
70+
echo $result;
71+
?>`
72+
73+
export {sh, js, php}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Mandate is queued for retry"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)