ios sdk
This shows the steps requires to use the paymennt iOS SDK for accepting card payments via the paymennt.com payment gateway in your iOS mobile application.
SDK Flow
The paymennt iOS SDK requires three distinct steps for you to accept card payments:
- Create a new Device Checkout
- Initiate the SDK's PointCheckoutClient using the provided checkout key
- Query the API for the payment status
This diagram shows the overall payment and data flow in order to accept payments using the paymennt mobile SDK
Installation
We support CocoaPods. To install the paymennt iOS SDK:
- Add PointCheckoutSdk to your project by adding the following line to your
Podfile
pod 'PointCheckoutSdk', :git => 'https://github.com/pointcheckout/ios-sdk.git', :tag=> v${version}
replace ${version} with the latest version of the SDK, you can check all available versions here. Example:
pod 'PointCheckoutSdk', :git => 'https://github.com/pointcheckout/ios-sdk.git', :tag=> 'v1.3'
Execute
pod install
inside the project directory.Re-build the project.
Using the SDK
Device Checkout request
Send new checkout request to paymennt's API, check the documentation for more details.
API calls made to the paymennt API endpoints should be made from your server. You should NEVER include your API keys in your mobile application. A mallicious user can gain access to your account if those keys are exposed.
Create a new PointCheckoutClient
Create an object of PointCheckoutClient:
var pcoClient = PointCheckoutClient();
Environment | Description |
---|---|
Enviornment.PRODUCTION | Use this for accepting customer payments |
Enviornment.TEST | Use this during integration testing |
Keep a reference of the created client to reuse the same instance
Start the Payment Process
To commence the payment process, you must call the static pay
method of the PointCheckoutClient
. This method accepts 3 parameters:
viewController
is a UIViewController that is calling thepay
functioncheckoutKey
received in the Device Checkout Requestdelegate
that will be called on payment update or cancellation
pcClient.pay(controller: viewController, checkoutKey: strCheckoutKey, delegate: callback)
Calling the pay
function will open a modal where the user will be able to complete the payment in a secure manner.
Listen to Payment Events
The PointCheckoutPaymentDelegate
has two callbacks:
onUpdate
which is called the checkout status is updated (paid, cancelled, failed .etc). You MUST call paymennt API to fetch the new status of the checkout to verify that its been successfully paid.onDismiss
which is called if the user closes the modal by clicking on dismiss or close button.
import UIKit
import PointCheckoutSdk
class ViewController: UIViewController, PointCheckoutPaymentDelegate{
override func viewDidLoad() {
super.viewDidLoad()
}
func onUpdate(){
print("UPDATE CALLBACK")
}
func onDismiss(){
print("USER CLOSED THE MODAL")
}
}
Retrieve Checkout Status
Retrieve checkout details from paymennt's API, check the documentation for more details.
API calls made to the paymennt API endpoints should be made from your server. You should NEVER include your API keys in your mobile application. A mallicious user can gain access to your account if those keys are exposed.
API References
1. New Device Checkout
2. Get Checkout Details