Skip to content

Feat/preauth #77

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions dist/api/preauthorization/capture/requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const sh = `curl https://api.paystack.co/preauthorization/capture
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{ "reference": "123-abc",
"currency": "ZAR",
"amount": "1000"
}'
-X POST`

const js = `const https = require('https')

const params = JSON.stringify({
"reference": "123-abc",
"currency": "ZAR",
"amount": "1000",
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/preauthorization/capture',
method: 'POST',
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))
})
}).on('error', error => {
console.error(error)
})

req.write(params)
req.end()`

const php = `<?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;
?>`

export {sh, js, php}
67 changes: 67 additions & 0 deletions dist/api/preauthorization/capture/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"200": {
"description": "200 Ok",
"data": {
"status": true,
"message": "Capture attempted",
"data": {
"amount": 1000,
"currency": "ZAR",
"transaction_date": "2023-08-24T11:38:32.000Z",
"status": "success",
"reference": "123-abc",
"domain": "live",
"metadata": {
"custom_fields": [
{
"display_name": "Cart Number",
"variable_name": "cart_number",
"value": "123443"
}
]
},
"gateway_response": "Approved",
"message": null,
"channel": "preauth",
"ip_address": null,
"log": null,
"fees": 373,
"authorization": {
"authorization_code": "AUTH_5h7ifp9x1h",
"bin": "541333",
"last4": "0028",
"exp_month": "12",
"exp_year": "2025",
"channel": "card",
"card_type": "mastercard ",
"bank": "Absa Bank Limited, South Africa ",
"country_code": "ZA",
"brand": "mastercard",
"reusable": true,
"signature": "SIG_6bCAS8p20rANfmuYgQ2i",
"account_name": null
},
"customer": {
"id": 180063193,
"first_name": null,
"last_name": null,
"email": "customer@email.com",
"customer_code": "CUS_zi5os4fs31qxao0",
"phone": null,
"metadata": null,
"risk_action": "default",
"international_format_phone": null
},
"plan": null,
"id": 1504173002
}
}
},
"400": {
"description": "400 Invalid",
"data": {
"status": false,
"message": "Capture amount cannot be more than authorized amount"
}
}
}
77 changes: 77 additions & 0 deletions dist/api/preauthorization/initialize/requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const sh = `curl https://api.paystack.co/preauthorization/initialize
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{ "email": "customer@email.com",
"amount": "500000",
"currency": "ZAR"
}'
-X POST`

const js = `const https = require('https')

const params = JSON.stringify({
"email": "customer@email.com",
"amount": "500000",
"currency": "ZAR"
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/preauthorization/initialize',
method: 'POST',
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))
})
}).on('error', error => {
console.error(error)
})

req.write(params)
req.end()`

const php = `<?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;
?>`

export {sh, js, php}
21 changes: 21 additions & 0 deletions dist/api/preauthorization/initialize/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"200": {
"description": "200 Ok",
"data": {
"status": true,
"message": "Authorization URL created",
"data": {
"authorization_url": "https://checkout.paystack.com/preauthorization/NDEyOTIyOmxpdmU6ZWloZ2VodTNyczZjanJj",
"access_code": "NDEyOTIyOmxpdmU6ZWloZ2VodTNyczZjanJj",
"reference": "eihgehu3rs6cjrc"
}
}
},
"400": {
"description": "400 Invalid",
"data": {
"status": false,
"message": "Customer email address is required"
}
}
}
63 changes: 63 additions & 0 deletions dist/api/preauthorization/list/requests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const sh = `#!/bin/sh
url="https://api.paystack.co/preauthorization"
authorization="Authorization: Bearer YOUR_SECRET_KEY"

curl "$url" -H "$authorization" -X GET`

const js = `const https = require('https')

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/preauthorization',
method: 'GET',
headers: {
Authorization: 'Bearer SECRET_KEY'
}
}

const req = https.request(options, res => {
let data = ''

res.on('data', (chunk) => {
data += chunk
});

res.on('end', () => {
console.log(JSON.parse(data))
})
}).on('error', error => {
console.error(error)
})
req.end()`

const php = `<?php
$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.paystack.co/preauthorization",
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;
}
?>`

export {sh, js, php}
49 changes: 49 additions & 0 deletions dist/api/preauthorization/list/response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"200": {
"description": "200 OK",
"data": {
"status": true,
"message": "Preauthorizations retrieved",
"data": [
{
"domain": "test",
"status": "success",
"reference": "ctbaq5z6fkzsk2f",
"amount": 1200,
"created_at": "2023-08-21T06:30:31.000Z",
"transaction_id": null,
"captured_at": null,
"released_at": null,
"currency": "ZAR",
"fees": 0,
"customer": {
"id": 180063193,
"first_name": null,
"last_name": null,
"email": "test@paystack.com",
"customer_code": "CUS_zi5os4fs31qxao0",
"phone": null,
"metadata": null,
"risk_action": "default",
"international_format_phone": null
},
"id": 436
}
],
"meta": {
"total": 1,
"skipped": 0,
"perPage": 50,
"page": 1,
"pageCount": 1
}
}
},
"500": {
"description": "500 Error",
"data": {
"status": false,
"message": "An error occurred"
}
}
}
Loading