Skip to content

kamalupasena/payhere-mobilesdk-ios

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PayHere Mobile SDK for iOS

The PayHere iOS SDK makes it easy to add PayHere payments to your mobile apps easily

Contents

Requirements

  • iOS 8.0+
  • Xcode 8.3+
  • Swift 3.1+

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate PayHere into your Xcode project using CocoaPods, specify it 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 the following command:

$ pod install

Usage

import PayHere SDK into your UIViewController as following

import payHereSDK

When you want to make a payment first initialized PayHere ViewController as bellow

let phVC = PHViewController()
phVC.initRequest = req
phVC.delegate = self
phVC.isSandBoxEnabled = true  
phVC.modalPresentationStyle = .overCurrentContext
        
self.present(phVC, animated: true, completion: nil)

Create InitRequest

        let req : InitRequest = InitRequest()
        req.merchantId = <Your PayHere MerchantID>
        req.merchantSecret = <Your PayHere Merchant Secret>
        req.amount = 100.0
        req.currency = "LKR"
        req.orderId = "ABCDWXYZ"
        req.itemsDescription = "1 Greeting Card"
        req.custom1 = "This is the custom 1 message"
        req.custom2 = "This is the custom 2 message"
        
        
        let customer = Customer()
        
        customer.firstName = "Nuwan"
        customer.lastName = "Kumara"
        customer.email = "n@gmail.com"
        customer.phone = "+94700000000"
        
        
        let address = Address()
        address.address = "No 43, Galle Road"
        address.city = "Colombo"
        address.country = "Sri Lanka"
        
        
        let deliverAddress = Address()
        deliverAddress.address = "No 100, Galle Road"
        deliverAddress.city = "Kadawatha"
        deliverAddress.country = "Sri Lanka"
        
        
        customer.address = address
        customer.deliveryAddress = deliverAddress
        
        req.customer = customer
        
        req.items = [Item(id: "1", name: "Card", quantity: 1)]

Handle Payment Response

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

About

PayHere Mobile SDK for iOS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 91.8%
  • Ruby 5.7%
  • Objective-C 2.5%