iOS SDK
Integrating PayHere with your iOS Mobile App is super easy with our PayHere iOS SDK. 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 iOS 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 iOS 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, '11.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
a. One-time Payment Request
let initRequest = PHInitialRequest(
merchantID: 1210251, // Your Merchant ID
notifyURL: "",
firstName: "Saman",
lastName: "Perera",
email: "samanp@gmail.com",
phone: "+9477123456",
address: "No.1, Galle Road",
city: "Colombo",
country: "Sri Lanka",
orderID: "001", // Unique ID for your payment transaction
itemsDescription: "Greeting Card", // Item title or Order/Invoice number
itemsMap: [item1,item2],
currency: .LKR, // Currency Enum
amount: 50.00, // Amount which the customer should pay
deliveryAddress: "",
deliveryCity: "",
deliveryCountry: "",
custom1: "custom 01",
custom2: "custom 02")
PHPrecentController.precent(from: self, isSandBoxEnabled: false, withInitRequest: initRequest!, delegate: self)
b. Recurring Payment Request
let initRequest = PHInitialRequest(
merchantID: 1210251, // Your Merchant ID
notifyURL: "",
firstName: "Saman",
lastName: "Perera",
email: "amanp@gmail.com",
phone: "0771234567",
address: "No.1, Galle Road",
city: "Colombo",
country: "Sri Lanka",
orderID: "002", // Unique ID for your payment transaction
itemsDescription: "Magazine Subscription", // Item title or Order/Invoice number
itemsMap: [item1],
currency: .LKR, // Currency Enum
amount: 60.50,
deliveryAddress: "",
deliveryCity: "",
deliveryCountry: "",
custom1: "",
custom2: "",
startupFee: 0.00,
recurrence: .Month(duration: 1), // Recurrence Enum
duration: .Forver) // Duration Enum
PHPrecentController.precent(from: self, isSandBoxEnabled: false, withInitRequest: initRequest!, delegate: self)
c. Preapproval Request
let initRequest = PHInitialRequest(
merchantID: 1210251, // Your Merchant ID
notifyURL: "",
firstName: "Saman",
lastName: "Perera",
email: "samanp@gmail.com",
phone: "0771234567",
address: "No.1, Galle Road",
city: "Colombo",
country: "Sri Lanka",
orderID: "001", // Unique ID for your payment transaction
itemsDescription: "", // Save Card on MyApp
itemsMap: [item1],
currency: .LKR, // Currency Enum
custom1: "",
custom2: "")
PHPrecentController.precent(from: self, isSandBoxEnabled: false, withInitRequest: initRequest!, delegate: self)
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()
}
}
}