Skip to content

Commit 35d60f1

Browse files
add PHP snippets to 'API reference'
1 parent f7c0fb3 commit 35d60f1

10 files changed

Lines changed: 167 additions & 10 deletions

File tree

dist/api/preauthorization/capture/requests.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,35 @@ const req = https.request(options, res => {
4343
req.write(params)
4444
req.end()`
4545

46-
export {sh, js}
46+
const php = `<?php
47+
$url = "https://api.paystack.co/preauthorization/capture";
48+
49+
$fields = [
50+
'reference' => '123-abc'
51+
'currency' => 'ZAR'
52+
'amount' => '10000'
53+
];
54+
55+
$fields_string = http_build_query($fields);
56+
57+
//open connection
58+
$ch = curl_init();
59+
60+
//set the url, number of POST vars, POST data
61+
curl_setopt($ch,CURLOPT_URL, $url);
62+
curl_setopt($ch,CURLOPT_POST, true);
63+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
64+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
65+
"Authorization: Bearer SECRET_KEY",
66+
"Cache-Control: no-cache",
67+
));
68+
69+
//So that curl_exec returns the contents of the cURL; rather than echoing it
70+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
71+
72+
//execute post
73+
$result = curl_exec($ch);
74+
echo $result;
75+
?>`
76+
77+
export {sh, js, php}

dist/api/preauthorization/initialize/requests.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,35 @@ const req = https.request(options, res => {
4343
req.write(params)
4444
req.end()`
4545

46-
export {sh, js}
46+
const php = `<?php
47+
$url = "https://api.paystack.co/preauthorization/initialize";
48+
49+
$fields = [
50+
'reference' => '123-abc'
51+
'currency' => 'ZAR'
52+
'amount' => '10000'
53+
];
54+
55+
$fields_string = http_build_query($fields);
56+
57+
//open connection
58+
$ch = curl_init();
59+
60+
//set the url, number of POST vars, POST data
61+
curl_setopt($ch,CURLOPT_URL, $url);
62+
curl_setopt($ch,CURLOPT_POST, true);
63+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
64+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
65+
"Authorization: Bearer SECRET_KEY",
66+
"Cache-Control: no-cache",
67+
));
68+
69+
//So that curl_exec returns the contents of the cURL; rather than echoing it
70+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
71+
72+
//execute post
73+
$result = curl_exec($ch);
74+
echo $result;
75+
?>`
76+
77+
export {sh, js, php}

dist/api/preauthorization/release/requests.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,33 @@ const req = https.request(options, res => {
4040
req.write(params)
4141
req.end()`
4242

43-
export {sh, js}
43+
const php = `<?php
44+
$url = "https://api.paystack.co/preauthorization/release";
45+
46+
$fields = [
47+
'reference' => '123-abc'
48+
];
49+
50+
$fields_string = http_build_query($fields);
51+
52+
//open connection
53+
$ch = curl_init();
54+
55+
//set the url, number of POST vars, POST data
56+
curl_setopt($ch,CURLOPT_URL, $url);
57+
curl_setopt($ch,CURLOPT_POST, true);
58+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
59+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
60+
"Authorization: Bearer SECRET_KEY",
61+
"Cache-Control: no-cache",
62+
));
63+
64+
//So that curl_exec returns the contents of the cURL; rather than echoing it
65+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
66+
67+
//execute post
68+
$result = curl_exec($ch);
69+
echo $result;
70+
?>`
71+
72+
export {sh, js, php}

dist/api/preauthorization/reserve/requests.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,36 @@ const req = https.request(options, res => {
4646
req.write(params)
4747
req.end()`
4848

49-
export {sh, js}
49+
const php = `<?php
50+
$url = "https://api.paystack.co/preauthorization/reserve_authorization";
51+
52+
$fields = [
53+
'email' => 'test@paystack.com',
54+
'currency' => 'ZAR',
55+
'amount' => 1000,
56+
'authorization_code' => 'AUTH_dalhwqi5vw',
57+
];
58+
59+
$fields_string = http_build_query($fields);
60+
61+
//open connection
62+
$ch = curl_init();
63+
64+
//set the url, number of POST vars, POST data
65+
curl_setopt($ch,CURLOPT_URL, $url);
66+
curl_setopt($ch,CURLOPT_POST, true);
67+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
68+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
69+
"Authorization: Bearer SECRET_KEY",
70+
"Cache-Control: no-cache",
71+
));
72+
73+
//So that curl_exec returns the contents of the cURL; rather than echoing it
74+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
75+
76+
//execute post
77+
$result = curl_exec($ch);
78+
echo $result;
79+
?>`
80+
81+
export {sh, js, php}

dist/api/preauthorization/verify/requests.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,33 @@ const req = https.request(options, res => {
3131
})
3232
req.end()`
3333

34-
export {sh, js}
34+
const php = `<?php
35+
$curl = curl_init();
36+
37+
curl_setopt_array($curl, array(
38+
CURLOPT_URL => "https://api.paystack.co/preauthorization/verify/:reference",
39+
CURLOPT_RETURNTRANSFER => true,
40+
CURLOPT_ENCODING => "",
41+
CURLOPT_MAXREDIRS => 10,
42+
CURLOPT_TIMEOUT => 30,
43+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
44+
CURLOPT_CUSTOMREQUEST => "GET",
45+
CURLOPT_HTTPHEADER => array(
46+
"Authorization: Bearer SECRET_KEY",
47+
"Cache-Control: no-cache",
48+
),
49+
));
50+
51+
$response = curl_exec($curl);
52+
$err = curl_error($curl);
53+
54+
curl_close($curl);
55+
56+
if ($err) {
57+
echo "cURL Error #:" . $err;
58+
} else {
59+
echo $response;
60+
}
61+
?>`
62+
63+
export {sh, js, php}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
languages:
22
- sh
3-
- js
3+
- js
4+
- php
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
languages:
22
- sh
3-
- js
3+
- js
4+
- php
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
languages:
22
- sh
3-
- js
3+
- js
4+
- php
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
languages:
22
- sh
3-
- js
3+
- js
4+
- php
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
languages:
22
- sh
3-
- js
3+
- js
4+
- php

0 commit comments

Comments
 (0)