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.
4
4
5
-
Accepting payments in your app involves 4 steps, which we'll cover in this guide:
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.
6
6
7
-
- Collecting credit card information from your customer
8
-
- Converting the credit card information to a _**single-use**_ token
9
-
- Sending this token to your server to create a charge which provides an authorizaton code if successful
10
-
- Using the returned authorization code to make future charge requests
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
11
10
12
-
## Getting Started
13
-
14
-
### Step 1: Install the library
15
-
16
-
#### Using [CocoaPods](https://cocoapods.org/)
17
-
18
-
We recommend using [CocoaPods](https://cocoapods.org/) to install the Paystack iOS library, since it makes it easy to keep your app's dependencies up to date.
19
-
20
-
If you haven't set up Cocoapods before, their site has installation instructions. Then, add pod 'Paystack' to your Podfile, and run pod install.
11
+
or
21
12
22
-
(Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.)
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
23
16
24
-
#### Using Carthage
17
+
##Getting Started
25
18
26
-
We also support installing our SDK using Carthage. You can simply add github "paystackhq/paystack-ios" to your Cartfile, and follow the Carthage installation instructions.
19
+
### Step 1: Install the library
27
20
28
21
#### Manual installation
29
22
@@ -37,6 +30,18 @@ We also publish our SDK as a static framework that you can copy directly into yo
37
30
- Click 'Add'.
38
31
- In your project settings, go to the "Build Settings" tab, and make sure -ObjC is present under "Other Linker Flags".
39
32
33
+
#### Using [CocoaPods](https://cocoapods.org/)
34
+
35
+
We recommend using [CocoaPods](https://cocoapods.org/) to install the Paystack iOS library, since it makes it easy to keep your app's dependencies up to date.
36
+
37
+
If you haven't set up Cocoapods before, their site has installation instructions. Then, add pod 'Paystack' to your Podfile, and run pod install.
38
+
39
+
(Don't forget to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on out.)
40
+
41
+
#### Using Carthage
42
+
43
+
We also support installing our SDK using Carthage. You can simply add github "paystackhq/paystack-ios" to your Cartfile, and follow the Carthage installation instructions.
44
+
40
45
### Step 2: Configure API keys
41
46
42
47
First, you'll want to configure Paystack with your publishable 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.
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.
212
+
213
+
214
+
#### Step 4 Option 1: Charge Card
215
+
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
+
218
+
```Swift
219
+
@IBActionfunccharge(sender: UIButton) {
220
+
// cardParams already fetched from our view or assembled by you
221
+
let transactionParams = PSTCKTransactionParams.init();
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 convert them to tokens. You should charge these tokens later in your server-side code to get an authorization code.
227
+
// check https://developers.paystack.co/docs/split-payments-overview for details on how these work
If you're using `PSTCKPaymentCardTextField` or your own form, you can assemble the data into an `PSTCKCardParams` object. Once you've collected the card number, expiration, and CVC, package them up in an `PSTCKCardParams` object and invoke the `createTokenWithCard:` method on the `PSTCKAPIClient` class, instructing the library to send off the credit card data to Paystack and return a token.
235
+
PSTCKAPIClient.shared().chargeCard(cardParams, forTransaction: transactionParams, on: viewController,
236
+
didEndWithError: { (error) ->Voidin
237
+
handleError(error)
238
+
}, didRequestValidation: { (reference) ->Voidin
239
+
// an OTP was requested, transaction has not yet succeeded
240
+
}, didTransactionSuccess: { (reference) ->Voidin
241
+
// transaction may have succeeded, please verify on server
242
+
})
243
+
}
244
+
```
245
+
246
+
```Objective-C
247
+
- (IBAction)charge:(UIButton *)sender {
248
+
// cardParams already fetched from our view or assembled by you
// an OTP was requested, transaction has not yet succeeded
272
+
}
273
+
didTransactionSuccess: ^(NSString *reference){
274
+
// transaction may have succeeded, please verify on server
275
+
}];
276
+
277
+
}
278
+
```
279
+
280
+
#### Step 4 Option 2: Using Tokens
281
+
282
+
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.
// call your createBackendChargeWithToken function
190
-
// A sample is presented in step 5
310
+
// A sample is presented in step 6
191
311
}
192
312
}];
193
313
}
@@ -197,7 +317,72 @@ In the example above, we're calling `createTokenWithCard:` when a save button is
197
317
198
318
Handling error messages and showing activity indicators while we're creating the token is up to you.
199
319
200
-
### Step 5: Sending the token to your server
320
+
### Step 6 Option 1: Sending the reference to your server
321
+
322
+
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.
323
+
324
+
Here's how it looks:
325
+
326
+
```Swift
327
+
// ViewController.swift
328
+
329
+
funcverifyCharge(reference: String) {
330
+
let url =NSURL(string: "https://example.com/verify")!
331
+
let request =NSMutableURLRequest(URL: url)
332
+
request.HTTPMethod="POST"
333
+
let postBody ="reference=reference"
334
+
let postData = postBody.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
335
+
session.uploadTaskWithRequest(request, fromData: postData, completionHandler: { data, response, error in
336
+
let successfulResponse = (response as? NSHTTPURLResponse)?.statusCode==200
337
+
if successfulResponse && error ==nil&& data !=nil{
338
+
// All was well
339
+
let newStr =NSString(data: data!, encoding: NSUTF8StringEncoding)
340
+
print(newStr) // All we did here is log it to the output window
341
+
} else {
342
+
iflet e=error {
343
+
print(e.description)
344
+
} else {
345
+
// There was no error returned though status code was not 200
346
+
print("There was an error communicating with your payment backend.")
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.
384
+
385
+
### Step 6 Option 2: Sending the token to your server
201
386
202
387
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.
203
388
@@ -266,16 +451,38 @@ On the server, you just need to implement an endpoint that will accept the param
266
451
267
452
--------------------
268
453
269
-
### Step 6: Implement payment on your server
454
+
### Step 6 Option 1: Implement verification on your server
455
+
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).
### Step 6 Option 2: Implement payment on your server
270
475
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).
0 commit comments