Skip to content
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

Feat: Add SDK accept payment API snippets #65

Merged
merged 1 commit into from
Mar 11, 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
84 changes: 84 additions & 0 deletions dist/doc/payments/accept-payment/initialize-transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const sh = `curl https://api.paystack.co/transaction/initialize
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{ "email": "[email protected]",
"amount": "500000"
}'
-X POST`

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

const params = JSON.stringify({
"email": "[email protected]",
"amount": "500000"
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/transaction/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/transaction/initialize";

$fields = [
'email' => "[email protected]",
'amount' => "500000"
];

$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;
?>`

const json = `{
"status": true,
"message": "Authorization URL created",
"data": {
"authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
"access_code": "nkdks46nymizns7",
"reference": "nms6uvr1pl"
}
}`

export {sh, js, php, json}
7 changes: 3 additions & 4 deletions dist/doc/payments/accept-payment/ios-complete-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct PaymentView: View {
VStack(spacing: 8) {
Text("Make Payemnt")

paystack?.chargeUIButton(accessCode: "0peioxfhpn",
onComplete: paymentDone) {
paystack?.chargeUIButton(accessCode: "0peioxfhpn", onComplete: paymentDone) {
Text("Initiate Payment")
}
}
Expand All @@ -38,11 +37,11 @@ class ViewController: UIViewController {
.setKey("PUBLIC_KEY")
.build()

let paymentAccessCodee = "ACCESS_CODE"
let paymentAccessCode = "ACCESS_CODE"

@IBAction func launchPaymentTapped(_ sender: Any) {
paystack?.presentChargeUI(on: self,
accessCode: paymentAccessCodee,
accessCode: paymentAccessCode,
onComplete: paymentCompleted)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
languages:
- sh
- js
- php
- json
34 changes: 34 additions & 0 deletions src/doc/payments/accept-payment/initialize-transaction/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const https = require('https')

const params = JSON.stringify({
"email": "[email protected]",
"amount": "500000"
})

const options = {
hostname: 'api.paystack.co',
port: 443,
path: '/transaction/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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"status": true,
"message": "Authorization URL created",
"data": {
"authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
"access_code": "nkdks46nymizns7",
"reference": "nms6uvr1pl"
}
}
29 changes: 29 additions & 0 deletions src/doc/payments/accept-payment/initialize-transaction/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
$url = "https://api.paystack.co/transaction/initialize";

$fields = [
'email' => "[email protected]",
'amount' => "500000"
];

$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;
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
curl https://api.paystack.co/transaction/initialize
-H "Authorization: Bearer YOUR_SECRET_KEY"
-H "Content-Type: application/json"
-d '{ "email": "[email protected]",
"amount": "500000"
}'
-X POST
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ struct PaymentView: View {
VStack(spacing: 8) {
Text("Make Payemnt")

paystack?.chargeUIButton(accessCode: "0peioxfhpn",
onComplete: paymentDone) {
paystack?.chargeUIButton(accessCode: "0peioxfhpn", onComplete: paymentDone) {
Text("Initiate Payment")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class ViewController: UIViewController {
.setKey("PUBLIC_KEY")
.build()

let paymentAccessCodee = "ACCESS_CODE"
let paymentAccessCode = "ACCESS_CODE"

@IBAction func launchPaymentTapped(_ sender: Any) {
paystack?.presentChargeUI(on: self,
accessCode: paymentAccessCodee,
accessCode: paymentAccessCode,
onComplete: paymentCompleted)
}

Expand Down