Skip to content

Commit 9b3460a

Browse files
Add php code snippets to api reference
1 parent 35d60f1 commit 9b3460a

File tree

5 files changed

+147
-0
lines changed

5 files changed

+147
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
$url = "https://api.paystack.co/preauthorization/capture";
3+
4+
$fields = [
5+
'reference' => '123-abc'
6+
'currency' => 'ZAR'
7+
'amount' => '10000'
8+
];
9+
10+
$fields_string = http_build_query($fields);
11+
12+
//open connection
13+
$ch = curl_init();
14+
15+
//set the url, number of POST vars, POST data
16+
curl_setopt($ch,CURLOPT_URL, $url);
17+
curl_setopt($ch,CURLOPT_POST, true);
18+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
19+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
20+
"Authorization: Bearer SECRET_KEY",
21+
"Cache-Control: no-cache",
22+
));
23+
24+
//So that curl_exec returns the contents of the cURL; rather than echoing it
25+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
26+
27+
//execute post
28+
$result = curl_exec($ch);
29+
echo $result;
30+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
$url = "https://api.paystack.co/preauthorization/initialize";
3+
4+
$fields = [
5+
'reference' => '123-abc'
6+
'currency' => 'ZAR'
7+
'amount' => '10000'
8+
];
9+
10+
$fields_string = http_build_query($fields);
11+
12+
//open connection
13+
$ch = curl_init();
14+
15+
//set the url, number of POST vars, POST data
16+
curl_setopt($ch,CURLOPT_URL, $url);
17+
curl_setopt($ch,CURLOPT_POST, true);
18+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
19+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
20+
"Authorization: Bearer SECRET_KEY",
21+
"Cache-Control: no-cache",
22+
));
23+
24+
//So that curl_exec returns the contents of the cURL; rather than echoing it
25+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
26+
27+
//execute post
28+
$result = curl_exec($ch);
29+
echo $result;
30+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$url = "https://api.paystack.co/preauthorization/release";
3+
4+
$fields = [
5+
'reference' => '123-abc'
6+
];
7+
8+
$fields_string = http_build_query($fields);
9+
10+
//open connection
11+
$ch = curl_init();
12+
13+
//set the url, number of POST vars, POST data
14+
curl_setopt($ch,CURLOPT_URL, $url);
15+
curl_setopt($ch,CURLOPT_POST, true);
16+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
17+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
18+
"Authorization: Bearer SECRET_KEY",
19+
"Cache-Control: no-cache",
20+
));
21+
22+
//So that curl_exec returns the contents of the cURL; rather than echoing it
23+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
24+
25+
//execute post
26+
$result = curl_exec($ch);
27+
echo $result;
28+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
$url = "https://api.paystack.co/preauthorization/reserve_authorization";
3+
4+
$fields = [
5+
'email' => '[email protected]',
6+
'currency' => 'ZAR',
7+
'amount' => 1000,
8+
'authorization_code' => 'AUTH_dalhwqi5vw',
9+
];
10+
11+
$fields_string = http_build_query($fields);
12+
13+
//open connection
14+
$ch = curl_init();
15+
16+
//set the url, number of POST vars, POST data
17+
curl_setopt($ch,CURLOPT_URL, $url);
18+
curl_setopt($ch,CURLOPT_POST, true);
19+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
20+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
21+
"Authorization: Bearer SECRET_KEY",
22+
"Cache-Control: no-cache",
23+
));
24+
25+
//So that curl_exec returns the contents of the cURL; rather than echoing it
26+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
27+
28+
//execute post
29+
$result = curl_exec($ch);
30+
echo $result;
31+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
$curl = curl_init();
3+
4+
curl_setopt_array($curl, array(
5+
CURLOPT_URL => "https://api.paystack.co/preauthorization/verify/:reference",
6+
CURLOPT_RETURNTRANSFER => true,
7+
CURLOPT_ENCODING => "",
8+
CURLOPT_MAXREDIRS => 10,
9+
CURLOPT_TIMEOUT => 30,
10+
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
11+
CURLOPT_CUSTOMREQUEST => "GET",
12+
CURLOPT_HTTPHEADER => array(
13+
"Authorization: Bearer SECRET_KEY",
14+
"Cache-Control: no-cache",
15+
),
16+
));
17+
18+
$response = curl_exec($curl);
19+
$err = curl_error($curl);
20+
21+
curl_close($curl);
22+
23+
if ($err) {
24+
echo "cURL Error #:" . $err;
25+
} else {
26+
echo $response;
27+
}
28+
?>

0 commit comments

Comments
 (0)