Skip to content

Commit a8e7105

Browse files
Merge pull request #65 from PaystackOSS/feat-mobile-sdk
Feat: Add SDK accept payment API snippets
2 parents 64223ab + 97324a4 commit a8e7105

File tree

9 files changed

+174
-8
lines changed

9 files changed

+174
-8
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
const sh = `curl https://api.paystack.co/transaction/initialize
2+
-H "Authorization: Bearer YOUR_SECRET_KEY"
3+
-H "Content-Type: application/json"
4+
-d '{ "email": "customer@email.com",
5+
"amount": "500000"
6+
}'
7+
-X POST`
8+
9+
const js = `const https = require('https')
10+
11+
const params = JSON.stringify({
12+
"email": "customer@email.com",
13+
"amount": "500000"
14+
})
15+
16+
const options = {
17+
hostname: 'api.paystack.co',
18+
port: 443,
19+
path: '/transaction/initialize',
20+
method: 'POST',
21+
headers: {
22+
Authorization: 'Bearer SECRET_KEY',
23+
'Content-Type': 'application/json'
24+
}
25+
}
26+
27+
const req = https.request(options, res => {
28+
let data = ''
29+
30+
res.on('data', (chunk) => {
31+
data += chunk
32+
});
33+
34+
res.on('end', () => {
35+
console.log(JSON.parse(data))
36+
})
37+
}).on('error', error => {
38+
console.error(error)
39+
})
40+
41+
req.write(params)
42+
req.end()`
43+
44+
const php = `<?php
45+
$url = "https://api.paystack.co/transaction/initialize";
46+
47+
$fields = [
48+
'email' => "customer@email.com",
49+
'amount' => "500000"
50+
];
51+
52+
$fields_string = http_build_query($fields);
53+
54+
//open connection
55+
$ch = curl_init();
56+
57+
//set the url, number of POST vars, POST data
58+
curl_setopt($ch,CURLOPT_URL, $url);
59+
curl_setopt($ch,CURLOPT_POST, true);
60+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
61+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
62+
"Authorization: Bearer SECRET_KEY",
63+
"Cache-Control: no-cache",
64+
));
65+
66+
//So that curl_exec returns the contents of the cURL; rather than echoing it
67+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
68+
69+
//execute post
70+
$result = curl_exec($ch);
71+
echo $result;
72+
?>`
73+
74+
const json = `{
75+
"status": true,
76+
"message": "Authorization URL created",
77+
"data": {
78+
"authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
79+
"access_code": "nkdks46nymizns7",
80+
"reference": "nms6uvr1pl"
81+
}
82+
}`
83+
84+
export {sh, js, php, json}

dist/doc/payments/accept-payment/ios-complete-payment.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ struct PaymentView: View {
1212
VStack(spacing: 8) {
1313
Text("Make Payemnt")
1414
15-
paystack?.chargeUIButton(accessCode: "0peioxfhpn",
16-
onComplete: paymentDone) {
15+
paystack?.chargeUIButton(accessCode: "0peioxfhpn", onComplete: paymentDone) {
1716
Text("Initiate Payment")
1817
}
1918
}
@@ -38,11 +37,11 @@ class ViewController: UIViewController {
3837
.setKey("PUBLIC_KEY")
3938
.build()
4039
41-
let paymentAccessCodee = "ACCESS_CODE"
40+
let paymentAccessCode = "ACCESS_CODE"
4241
4342
@IBAction func launchPaymentTapped(_ sender: Any) {
4443
paystack?.presentChargeUI(on: self,
45-
accessCode: paymentAccessCodee,
44+
accessCode: paymentAccessCode,
4645
onComplete: paymentCompleted)
4746
}
4847
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
languages:
2+
- sh
3+
- js
4+
- php
5+
- json
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const https = require('https')
2+
3+
const params = JSON.stringify({
4+
"email": "customer@email.com",
5+
"amount": "500000"
6+
})
7+
8+
const options = {
9+
hostname: 'api.paystack.co',
10+
port: 443,
11+
path: '/transaction/initialize',
12+
method: 'POST',
13+
headers: {
14+
Authorization: 'Bearer SECRET_KEY',
15+
'Content-Type': 'application/json'
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+
33+
req.write(params)
34+
req.end()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"status": true,
3+
"message": "Authorization URL created",
4+
"data": {
5+
"authorization_url": "https://checkout.paystack.com/nkdks46nymizns7",
6+
"access_code": "nkdks46nymizns7",
7+
"reference": "nms6uvr1pl"
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
$url = "https://api.paystack.co/transaction/initialize";
3+
4+
$fields = [
5+
'email' => "customer@email.com",
6+
'amount' => "500000"
7+
];
8+
9+
$fields_string = http_build_query($fields);
10+
11+
//open connection
12+
$ch = curl_init();
13+
14+
//set the url, number of POST vars, POST data
15+
curl_setopt($ch,CURLOPT_URL, $url);
16+
curl_setopt($ch,CURLOPT_POST, true);
17+
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
18+
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
19+
"Authorization: Bearer SECRET_KEY",
20+
"Cache-Control: no-cache",
21+
));
22+
23+
//So that curl_exec returns the contents of the cURL; rather than echoing it
24+
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
25+
26+
//execute post
27+
$result = curl_exec($ch);
28+
echo $result;
29+
?>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
curl https://api.paystack.co/transaction/initialize
2+
-H "Authorization: Bearer YOUR_SECRET_KEY"
3+
-H "Content-Type: application/json"
4+
-d '{ "email": "customer@email.com",
5+
"amount": "500000"
6+
}'
7+
-X POST

src/doc/payments/accept-payment/ios-complete-payment/swift-ui.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ struct PaymentView: View {
1212
VStack(spacing: 8) {
1313
Text("Make Payemnt")
1414

15-
paystack?.chargeUIButton(accessCode: "0peioxfhpn",
16-
onComplete: paymentDone) {
15+
paystack?.chargeUIButton(accessCode: "0peioxfhpn", onComplete: paymentDone) {
1716
Text("Initiate Payment")
1817
}
1918
}

src/doc/payments/accept-payment/ios-complete-payment/ui-kit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ class ViewController: UIViewController {
88
.setKey("PUBLIC_KEY")
99
.build()
1010

11-
let paymentAccessCodee = "ACCESS_CODE"
11+
let paymentAccessCode = "ACCESS_CODE"
1212

1313
@IBAction func launchPaymentTapped(_ sender: Any) {
1414
paystack?.presentChargeUI(on: self,
15-
accessCode: paymentAccessCodee,
15+
accessCode: paymentAccessCode,
1616
onComplete: paymentCompleted)
1717
}
1818

0 commit comments

Comments
 (0)