You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you want to build a mobile app like [Afro](http://www.getafrocab.com) and enable people to make purchases directly in your app, our iOS and [Android](https://github.com/PaystackHQ/paystack-android) libraries can help.
3
+
If you want to build mobile apps like [Taxify](http://www.taxify.eu), [Afro](http://www.getafrocab.com), [Okada Books](https://www.okadabooks.com) and enable people to make purchases directly in your app, our iOS and [Android](https://github.com/PaystackHQ/paystack-android) libraries can help.
4
4
5
-
Accepting payments in your app after collecting card information can be acieved in either of two ways, which we'll cover in this guide. The`authorization code` from either option can be used on your server in future to charge the cards.
5
+
Accepting payments in your app after collecting card information can be achieved by charging the card with our SDK. Reusable`authorization code`s from such transaction from can be used from your backend to charge the cards directly.
6
6
7
-
#### Option 1 - Charge the card directly from App
8
-
- Charging the credit card and get the transaction `reference`
9
-
- Verifying the transaction on your server which provides an `authorizaton code` if successful
7
+
## Summarized flow
10
8
11
-
or
9
+
Once it's time to pay, and the user has provided card details on your app,
a. App prompts backend to initialize a transaction, backend returns `access_code`.
14
+
15
+
b. Provide `access_code` and card details to our SDK's `chargeCard` function.
16
+
17
+
#### OPTION 2: App starts transaction
18
+
19
+
a. Provide transaction parameters and card params to our SDK's `chargeCard` function.
20
+
21
+
#### SDK will prompt user for PIN, OTP or Bank authentication as required
22
+
23
+
#### Once successful, we will send event to your webhook url and call the didTransactionSuccess callback
12
24
13
-
#### Option 2 - Tokenize on App, charge on server
14
-
- Converting the credit card information to a _**single-use**_`token`
15
-
- Sending this token to your server to create a charge which provides an `authorizaton code` if successful
16
25
17
26
## Getting Started
18
27
28
+
### Step 0: Add Keychain Sharing entitlements to your app
29
+
19
30
### Step 1: Install the library
20
31
21
32
#### Manual installation
22
33
23
-
We also publish our SDK as a static framework that you can copy directly into your app without any additional tools:
34
+
We publish our SDK as a static framework that you can copy directly into your app without any additional tools:
24
35
25
36
- Head to our [releases page](https://github.com/PaystackHQ/paystack-ios/releases/) and download the framework that's right for you.
26
37
- Unzip the file you downloaded.
@@ -44,7 +55,7 @@ We also support installing our SDK using Carthage. You can simply add github "pa
44
55
45
56
### Step 2: Configure API keys
46
57
47
-
First, you'll want to configure Paystack with your public API key. We recommend doing this in your `AppDelegate`'s `application:didFinishLaunchingWithOptions:` method so that it'll be set for the entire lifecycle of your app.
58
+
First, you'll want to configure Paystack with your public API key. We recommend doing this in your `AppDelegate`'s `application:didFinishLaunchingWithOptions:` method so that it will be set for the entire lifecycle of your app.
48
59
49
60
```Swift
50
61
// AppDelegate.swift
@@ -85,7 +96,12 @@ We've placed a test public API key as the PaystackPublicKey constant in the abov
85
96
86
97
When you're using your test public key, our libraries give you the ability to test your payment flow without having to charge real credit cards.
87
98
88
-
If you're building your own form or using `PSTCKPaymentCardTextField`, using the card number `4123450131001381` with CVC `883` (along with any future expiration date) will accomplish the same effect.
99
+
If you're building your own form or using `PSTCKPaymentCardTextField`, using any of:
100
+
101
+
1. card number `4084084084084081` with CVC `408` (along with any future expiration date); or;
102
+
2. card number `5060666666666666666` with CVC `123` and any future expiration date, PIN `1234`, OTP `123456`
103
+
104
+
will accomplish the same effect.
89
105
90
106
At some point in the flow of your app, you'll want to obtain payment details from the user. There are two ways to do this. You can (in increasing order of complexity):
91
107
@@ -208,18 +224,42 @@ cardParams.expMonth = 9;
208
224
209
225
### Step 4: Getting payments
210
226
211
-
Our libraries shoulder the burden of PCI compliance by helping you avoid the need to send card data directly to your server. Instead, our libraries send credit card data directly to our servers, where we can charge them or create tokens which you charge on your server.
227
+
Our libraries shoulder the burden of PCI compliance by helping you avoid the need to send card data directly to your server. Instead, our libraries send credit card data directly to our servers, where we can charge them or create authorizations which you charge on your server.
228
+
229
+
We charge cards you send using parameters provided in your `PSTCKTransactionParams`. Assemble Transaction parameters into `PSTCKTransactionParams`, and send them along with the `cardParams` from the previous step to get a charge.
230
+
231
+
-**CardParams** - As gathered in [Step 3](#step-4-assembling-card-information-into-pstckcardparams)
232
+
233
+
-**TransactionParams** - This object allows you provide information about the transaction to be made. This can be used in either of 2 ways:
234
+
-**Resume an initialized transaction**: If employing this flow, you would send all required parameters
235
+
for the transaction from your backend to the Paystack API via the `transaction/initialize` call -
236
+
documented [here](https://developers.paystack.co/reference#initialize-a-transaction).. The
237
+
response of the call includes an `access_code`. This can be used to charge the card by doing
238
+
`transactionParams.access_code = {value from backend});`. Once an access code is set, others will be ignored.
239
+
-**Initiate a fresh transaction on Paystack**: By setting the parameters: `amount`, `email`, `currency`, `plan`,
240
+
`subaccount`, `transactionCharge`, `reference`, `bearer`. And calling the `setCustomFieldValue` and `setMetadataValue`
241
+
you can set up a fresh transaction directly from the SDK.
242
+
Documentation for these parameters are same as for `transaction/initialize`.
243
+
244
+
-**ViewController** - A view controller to be used when presenting dialogs. The currently open ViewController is perfect.
245
+
246
+
You will need to specify callbacks too. Each will be called depending on how the transaction went.
212
247
248
+
-**didTransactionSuccess** will be called once the charge succeeds.
213
249
214
-
#### Step 4 Option 1: Charge Card
250
+
-**didRequestValidation** is called every time the SDK needs to request user input. This function currently only allows the app know that the SDK is requesting further user input.
251
+
252
+
-**didEndWithError** is called if an error occurred during processing. Some types that you should watch include
253
+
-*PSTCKErrorCode.PSTCKExpiredAccessCodeError*: This would be thrown if the access code has already been used to attempt a charge.
254
+
-*PSTCKErrorCode.PSTCKConflictError*: This would be thrown if another transaction is currently being processed by the SDK
215
255
216
-
If you choose the `chargeCard` route, we charge cards you send using parameters provided in your `PSTCKTransactionParams`. Assemble Transaction parameters into `PSTCKTransactionParams`, and send them along with the `cardParams` to get a charge.
217
256
218
257
```Swift
219
258
@IBActionfunccharge(sender: UIButton) {
220
259
// cardParams already fetched from our view or assembled by you
221
260
let transactionParams = PSTCKTransactionParams.init();
// an OTP was requested, transaction has not yet succeeded
277
309
}
278
310
didTransactionSuccess: ^(NSString *reference){
279
-
// transaction may have succeeded, please verify on server
311
+
// transaction may have succeeded, please verify on backend
280
312
}];
281
313
282
314
}
283
315
```
284
316
285
-
#### Step 4 Option 2: Using Tokens
286
-
287
-
If you choose the `createToken` route, we convert cards sent to tokens. You should charge these tokens later in your server-side code to get an authorization code.
288
-
289
-
```Swift
290
-
@IBActionfuncsave(sender: UIButton) {
291
-
// cardParams Fetched from our view or built by you
// cardParams Fetched from our view or built by you
308
-
[[PSTCKAPIClient sharedClient]
309
-
createTokenWithCard:cardParams
310
-
completion:^(PSTCKToken *token, NSError *error) {
311
-
if (error) {
312
-
[self handleError:error];
313
-
} else {
314
-
// call your createBackendChargeWithToken function
315
-
// A sample is presented in step 6
316
-
}
317
-
}];
318
-
}
319
-
```
320
-
321
-
In the example above, we're calling `createTokenWithCard:` when a save button is tapped. The important thing to ensure is the createToken isn't called before the user has finished entering their card details.
322
-
323
-
Handling error messages and showing activity indicators while we're creating the token is up to you.
317
+
### Step 5: Send the reference to your backend
324
318
325
-
### Step 6 Option 1: Sending the reference to your server
326
-
327
-
The blocks you gave to `chargeCard` will be called whenever Paystack returns with a reference (or error). You'll need to send the reference off to your server so you can verify the transactions.
319
+
The blocks you gave to `chargeCard` will be called whenever Paystack returns with a reference (or error). You'll need to send the `reference` off to your backend so you can verify the transactions.
On the server, you just need to implement an endpoint that will accept the parameter: `reference`. Make sure any communication with your server is SSL secured to prevent eavesdropping.
380
+
On the server, you just need to implement an endpoint that will accept the parameter: `reference`. Make sure any communication with your backend is SSL secured to prevent eavesdropping.
389
381
390
-
### Step 6 Option 2: Sending the token to your server
391
382
392
-
The block you gave to `createToken` will be called whenever Paystack returns with a token (or error). You'll need to send the token off to your server so you can, for example, charge the card.
On the server, you just need to implement an endpoint that will accept the parameters `token`, `email` and `amountinkobo`. Make sure any communication with your server is SSL secured to prevent eavesdropping.
456
-
457
-
--------------------
458
-
459
-
### Step 6 Option 1: Implement verification on your server
460
-
Verify a charge by calling our REST API. An `authorization_code` will be returned once the card has been charged successfully. You can learn more about our API [here](https://developers.paystack.co/docs/getting-started).
383
+
### Step 6: Implement verification on your server
384
+
Verify a charge by calling our REST API. An active `authorization_code` will be returned once the card has been charged successfully. You can learn more about our API [here](https://developers.paystack.co/docs/getting-started).
### Step 6 Option 2: Implement payment on your server
480
-
Create a charge by calling our REST API. An `authorization_code` will be returned once the _single-use_ token has been charged successfully. You can learn more about our API [here](https://developers.paystack.co/docs/getting-started).
// save the authorization_code so you may charge in future
517
-
} else {
518
-
// invalid body was returned
519
-
// handle this or troubleshoot
520
-
throw new \Exception('Transaction Initialise returned non-true status');
521
-
}
522
-
523
-
```
524
-
525
-
**Result**
526
-
```json
527
-
{
528
-
"status": true,
529
-
"message": "Charge successful",
530
-
"data": {
531
-
"amount": 10000,
532
-
"transaction_date": "2016-01-26T15:34:02.000Z",
533
-
"status": "success",
534
-
"reference": "amutaJHSYGWakinlade256",
535
-
"domain": "test",
536
-
"authorization": {
537
-
"authorization_code": "AUTH_d47nbp3x",
538
-
"card_type": "visa",
539
-
"last4": "1111",
540
-
"bank": null
541
-
},
542
-
"customer": {
543
-
"first_name": "John",
544
-
"last_name": "Doe",
545
-
"email": "customer@email.com"
546
-
},
547
-
"plan": 0
548
-
}
549
-
```
550
403
551
404
### Charging Returning Customers
552
-
See details for charging returning customers [here](https://developers.paystack.co/docs/charging-returning-customers).
405
+
See details for charging returning customers [here](https://developers.paystack.co/docs/charging-returning-customers). Note that only `reusable` authorizations can be charged with this endpoint.
0 commit comments