forked from PaystackOSS/doc-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests.js
More file actions
77 lines (62 loc) · 1.46 KB
/
requests.js
File metadata and controls
77 lines (62 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const sh = `#!/bin/sh
url="https://api.paystack.co/virtual_terminal/:code/split_code"
authorization="Authorization: Bearer SECRET_KEY"
content_type="Content-Type: application/json"
data='{
"split_code": "SPL_98WF13Zu8w5"
}'
curl "$url" -H "$authorization" -H "$content_type" -X PUT -d "$data"`
const js = `const https = require('https')
const params = JSON.stringify({
"split_code": "SPL_98WF13Zu8w5"
})
const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/virtual_terminal/:code/split_code',
method: 'PUT',
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))
})
})
req.on('error', error => {
console.error(error)
})
req.write(params)
req.end()`
const php = `<?php
$curl = curl_init();
$data = array(
"split_code" => "SPL_98WF13Zu8w5"
);
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/virtual_terminal/:code/split",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode($data),
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer SECRET_KEY",
"Content-Type: application/json",
"Cache-Control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>`
export {sh, js, php}