1+ const sh = `#!/bin/sh
2+ url="https://api.paystack.co/order"
3+ authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+ content_type="Content-Type: application/json"
5+ data='{
6+ "customer": "CUS_abc123def456",
7+ "line_items": [
8+ {
9+ "product": 2196244,
10+ "quantity": 2
11+ }
12+ ]
13+ }'
14+
15+ curl "$url" -H "$authorization" -H "$content_type" -d "$data" -X POST
16+ `
17+
18+ const js = `const https = require('https')
19+
20+ const params = JSON.stringify({
21+ "customer": "CUS_abc123def456",
22+ "line_items": [
23+ {
24+ "product": 2196244,
25+ "quantity": 2
26+ }
27+ ]
28+ })
29+
30+ const options = {
31+ hostname: 'api.paystack.co',
32+ port: 443,
33+ path: '/order',
34+ method: 'POST',
35+ headers: {
36+ Authorization: 'Bearer SECRET_KEY',
37+ 'Content-Type': 'application/json'
38+ }
39+ }
40+
41+ const req = https.request(options, res => {
42+ let data = ''
43+
44+ res.on('data', (chunk) => {
45+ data += chunk
46+ });
47+
48+ res.on('end', () => {
49+ console.log(JSON.parse(data))
50+ })
51+ }).on('error', error => {
52+ console.error(error)
53+ })
54+
55+ req.write(params)
56+ req.end()
57+ `
58+
59+ const php = `<?php
60+ $url = "https://api.paystack.co/order";
61+
62+ $fields = [
63+ 'customer' => "CUS_abc123def456",
64+ 'line_items' => [
65+ [
66+ 'product' => 2196244,
67+ 'quantity' => 2
68+ ]
69+ ]
70+ ];
71+
72+ $fields_string = json_encode($fields);
73+
74+ $ch = curl_init();
75+
76+ curl_setopt($ch,CURLOPT_URL, $url);
77+ curl_setopt($ch,CURLOPT_POST, true);
78+ curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
79+ curl_setopt($ch, CURLOPT_HTTPHEADER, array(
80+ "Authorization: Bearer SECRET_KEY",
81+ "Content-Type: application/json",
82+ "Cache-Control: no-cache",
83+ ));
84+ curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
85+
86+ $result = curl_exec($ch);
87+ echo $result;
88+ ?>
89+ `
90+
91+ export { sh , js , php }
0 commit comments