Mobile SDK for iOS

Integrating PayHere with your iOS Mobile App is super easy with our PayHere Mobile SDK for iOS. You just have to include that in your Xcode project & call its methods to initiate a payment & fetch the payment status just after the payment. The beauty is, this Mobile SDK allows you to accept a payment within your app, without redirecting your app user to the web browser.

Please refer the below steps to integrate PayHere Mobile SDK to your iOS App.

1. Install CocoaPods for PayHere

Install CocoaPods dependency manager

$ gem install cocoapods

Specify PayHere in your Podfile

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'payHereSDK'
end

Then run following command

$ pod install


2. Import PayHere Mobile SDK

Import PayHere Mobile SDK into your UIViewController

import payHereSDK


3. Initiate a Payment Request to PayHere Payment Gateway

let phVC = PHViewController()
phVC.initRequest = req
phVC.delegate = self
phVC.isSandBoxEnabled = true  
phVC.modalPresentationStyle = .overCurrentContext

self.present(phVC, animated: true, completion: nil)

let req : InitRequest = InitRequest()
req.merchantId = "1210251"      // Your Merchant ID
req.merchantSecret = "bhasha2"  // Your Merchant secret
req.amount = 100.0              // Amount which the customer should pay
req.currency = "LKR"            // Currency
req.orderId = "ABCDWXYZ"        // Unique ID for your payment transaction
req.itemsDescription = "1 Greeting Card"    // Item title or Order/Invoice number
req.custom1 = "This is the custom 1 message"
req.custom2 = "This is the custom 2 message"

let customer = Customer()

customer.firstName = "Saman"
customer.lastName = "Perera"
customer.email = "samanp@gmail.com"
customer.phone = "+94771234567"

let address = Address()
address.address = "No 43, Galle Road"
address.city = "Colombo"
address.country = "Sri Lanka"

let deliverAddress = Address()
deliverAddress.address = "No 1, Galle Road"
deliverAddress.city = "Colombo"
deliverAddress.country = "Sri Lanka"

customer.address = address
customer.deliveryAddress = deliverAddress

req.customer = customer

req.items = [Item(id: "1", name: "Card", quantity: 1)]


5. Fetch the Payment Status

Example code

 extension <<ViewController>> : PHViewControllerDelegate{
    func onResponseReceived(response: PHResponse<Any>?) {
        if(response?.isSuccess())!{          
            guard let resp = response?.getData() as? StatusResponse else{
                return
            }            
            //Payment Success         
        }else{
            response?.getMessage()
        }
    }
}

Mobile SDK for iOS - PayHere Knowledge Base

Still need help? Get in touch!
Last updated on 29th Aug 2018