Skip to content

Commit 85b0806

Browse files
Merge pull request #77 from PaystackOSS/feat/preauth
Feat/preauth
2 parents 996404e + 79d9f5e commit 85b0806

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+2162
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const sh = `curl https://api.paystack.co/preauthorization/capture
2+
-H "Authorization: Bearer YOUR_SECRET_KEY"
3+
-H "Content-Type: application/json"
4+
-d '{ "reference": "123-abc",
5+
"currency": "ZAR",
6+
"amount": "1000"
7+
}'
8+
-X POST`
9+
10+
const js = `const https = require('https')
11+
12+
const params = JSON.stringify({
13+
"reference": "123-abc",
14+
"currency": "ZAR",
15+
"amount": "1000",
16+
})
17+
18+
const options = {
19+
hostname: 'api.paystack.co',
20+
port: 443,
21+
path: '/preauthorization/capture',
22+
method: 'POST',
23+
headers: {
24+
Authorization: 'Bearer SECRET_KEY',
25+
'Content-Type': 'application/json'
26+
}
27+
}
28+
29+
const req = https.request(options, res => {
30+
let data = ''
31+
32+
res.on('data', (chunk) => {
33+
data += chunk
34+
});
35+
36+
res.on('end', () => {
37+
console.log(JSON.parse(data))
38+
})
39+
}).on('error', error => {
40+
console.error(error)
41+
})
42+
43+
req.write(params)
44+
req.end()`
45+
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}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Capture attempted",
7+
"data": {
8+
"amount": 1000,
9+
"currency": "ZAR",
10+
"transaction_date": "2023-08-24T11:38:32.000Z",
11+
"status": "success",
12+
"reference": "123-abc",
13+
"domain": "live",
14+
"metadata": {
15+
"custom_fields": [
16+
{
17+
"display_name": "Cart Number",
18+
"variable_name": "cart_number",
19+
"value": "123443"
20+
}
21+
]
22+
},
23+
"gateway_response": "Approved",
24+
"message": null,
25+
"channel": "preauth",
26+
"ip_address": null,
27+
"log": null,
28+
"fees": 373,
29+
"authorization": {
30+
"authorization_code": "AUTH_5h7ifp9x1h",
31+
"bin": "541333",
32+
"last4": "0028",
33+
"exp_month": "12",
34+
"exp_year": "2025",
35+
"channel": "card",
36+
"card_type": "mastercard ",
37+
"bank": "Absa Bank Limited, South Africa ",
38+
"country_code": "ZA",
39+
"brand": "mastercard",
40+
"reusable": true,
41+
"signature": "SIG_6bCAS8p20rANfmuYgQ2i",
42+
"account_name": null
43+
},
44+
"customer": {
45+
"id": 180063193,
46+
"first_name": null,
47+
"last_name": null,
48+
"email": "[email protected]",
49+
"customer_code": "CUS_zi5os4fs31qxao0",
50+
"phone": null,
51+
"metadata": null,
52+
"risk_action": "default",
53+
"international_format_phone": null
54+
},
55+
"plan": null,
56+
"id": 1504173002
57+
}
58+
}
59+
},
60+
"400": {
61+
"description": "400 Invalid",
62+
"data": {
63+
"status": false,
64+
"message": "Capture amount cannot be more than authorized amount"
65+
}
66+
}
67+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
const sh = `curl https://api.paystack.co/preauthorization/initialize
2+
-H "Authorization: Bearer YOUR_SECRET_KEY"
3+
-H "Content-Type: application/json"
4+
-d '{ "email": "[email protected]",
5+
"amount": "500000",
6+
"currency": "ZAR"
7+
}'
8+
-X POST`
9+
10+
const js = `const https = require('https')
11+
12+
const params = JSON.stringify({
13+
"email": "[email protected]",
14+
"amount": "500000",
15+
"currency": "ZAR"
16+
})
17+
18+
const options = {
19+
hostname: 'api.paystack.co',
20+
port: 443,
21+
path: '/preauthorization/initialize',
22+
method: 'POST',
23+
headers: {
24+
Authorization: 'Bearer SECRET_KEY',
25+
'Content-Type': 'application/json'
26+
}
27+
}
28+
29+
const req = https.request(options, res => {
30+
let data = ''
31+
32+
res.on('data', (chunk) => {
33+
data += chunk
34+
});
35+
36+
res.on('end', () => {
37+
console.log(JSON.parse(data))
38+
})
39+
}).on('error', error => {
40+
console.error(error)
41+
})
42+
43+
req.write(params)
44+
req.end()`
45+
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}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"200": {
3+
"description": "200 Ok",
4+
"data": {
5+
"status": true,
6+
"message": "Authorization URL created",
7+
"data": {
8+
"authorization_url": "https://checkout.paystack.com/preauthorization/NDEyOTIyOmxpdmU6ZWloZ2VodTNyczZjanJj",
9+
"access_code": "NDEyOTIyOmxpdmU6ZWloZ2VodTNyczZjanJj",
10+
"reference": "eihgehu3rs6cjrc"
11+
}
12+
}
13+
},
14+
"400": {
15+
"description": "400 Invalid",
16+
"data": {
17+
"status": false,
18+
"message": "Customer email address is required"
19+
}
20+
}
21+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const sh = `#!/bin/sh
2+
url="https://api.paystack.co/preauthorization"
3+
authorization="Authorization: Bearer YOUR_SECRET_KEY"
4+
5+
curl "$url" -H "$authorization" -X GET`
6+
7+
const js = `const https = require('https')
8+
9+
const options = {
10+
hostname: 'api.paystack.co',
11+
port: 443,
12+
path: '/preauthorization',
13+
method: 'GET',
14+
headers: {
15+
Authorization: 'Bearer SECRET_KEY'
16+
}
17+
}
18+
19+
const req = https.request(options, res => {
20+
let data = ''
21+
22+
res.on('data', (chunk) => {
23+
data += chunk
24+
});
25+
26+
res.on('end', () => {
27+
console.log(JSON.parse(data))
28+
})
29+
}).on('error', error => {
30+
console.error(error)
31+
})
32+
req.end()`
33+
34+
const php = `<?php
35+
$curl = curl_init();
36+
37+
curl_setopt_array($curl, array(
38+
CURLOPT_URL => "https://api.paystack.co/preauthorization",
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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"200": {
3+
"description": "200 OK",
4+
"data": {
5+
"status": true,
6+
"message": "Preauthorizations retrieved",
7+
"data": [
8+
{
9+
"domain": "test",
10+
"status": "success",
11+
"reference": "ctbaq5z6fkzsk2f",
12+
"amount": 1200,
13+
"created_at": "2023-08-21T06:30:31.000Z",
14+
"transaction_id": null,
15+
"captured_at": null,
16+
"released_at": null,
17+
"currency": "ZAR",
18+
"fees": 0,
19+
"customer": {
20+
"id": 180063193,
21+
"first_name": null,
22+
"last_name": null,
23+
"email": "[email protected]",
24+
"customer_code": "CUS_zi5os4fs31qxao0",
25+
"phone": null,
26+
"metadata": null,
27+
"risk_action": "default",
28+
"international_format_phone": null
29+
},
30+
"id": 436
31+
}
32+
],
33+
"meta": {
34+
"total": 1,
35+
"skipped": 0,
36+
"perPage": 50,
37+
"page": 1,
38+
"pageCount": 1
39+
}
40+
}
41+
},
42+
"500": {
43+
"description": "500 Error",
44+
"data": {
45+
"status": false,
46+
"message": "An error occurred"
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)