Skip to content

Commit

Permalink
Add php code snippets to api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Paystack committed Jun 4, 2024
1 parent 35d60f1 commit 9b3460a
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/api/preauthorization/capture/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
$url = "https://api.paystack.co/preauthorization/capture";

$fields = [
'reference' => '123-abc'
'currency' => 'ZAR'
'amount' => '10000'
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>
30 changes: 30 additions & 0 deletions src/api/preauthorization/initialize/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
$url = "https://api.paystack.co/preauthorization/initialize";

$fields = [
'reference' => '123-abc'
'currency' => 'ZAR'
'amount' => '10000'
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>
28 changes: 28 additions & 0 deletions src/api/preauthorization/release/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
$url = "https://api.paystack.co/preauthorization/release";

$fields = [
'reference' => '123-abc'
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>
31 changes: 31 additions & 0 deletions src/api/preauthorization/reserve/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
$url = "https://api.paystack.co/preauthorization/reserve_authorization";

$fields = [
'email' => '[email protected]',
'currency' => 'ZAR',
'amount' => 1000,
'authorization_code' => 'AUTH_dalhwqi5vw',
];

$fields_string = http_build_query($fields);

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
));

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
echo $result;
?>
28 changes: 28 additions & 0 deletions src/api/preauthorization/verify/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/preauthorization/verify/:reference",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer SECRET_KEY",
"Cache-Control: no-cache",
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>

0 comments on commit 9b3460a

Please sign in to comment.