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 }
0 commit comments