Git Product home page Git Product logo

payhere-mobilesdk-ios's Introduction

PayHere Mobile SDK for iOS

PayHere Mobile SDK for iOS allows you to accept payments seamlessly within your iOS app, without redirecting your app user to the web browser.

Contents

Requirements

  • iOS 11.0+
  • Xcode 11.0+
  • Swift 5.0+

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! # add this line if not present

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

Then, run the following command:

$ pod install

Usage

Import PayHere SDK into your UIViewController

import payHereSDK

Create InitRequest

CheckOut

let merchantID = ""
let item = Item(id: "item_1", name: "Item 1", quantity: 1, amount: 50.0)
let initRequest = PHInitialRequest(
    merchantID: merchantID, 
    notifyURL: "", 
    firstName: "Pay", 
    lastName: "Here", 
    email: "[email protected]", 
    phone: "+9477123456", 
    address: "Colombo", 
    city: "Colombo", 
    country: "Sri Lanka", 
    orderID: "001", 
    itemsDescription: "PayHere SDK Sample", 
    itemsMap: [item], 
    currency: .LKR, 
    amount: 50.00,
    deliveryAddress: "", 
    deliveryCity: "", 
    deliveryCountry: "", 
    custom1: "custom 01", 
    custom2: "custom 02"
)

PreApproval

let merchantID = ""
let item = Item(id: "item_1", name: "Item 1", quantity: 1, amount: 50.0)
let initRequest = PHInitialRequest(
    merchantID: merchantID, 
    notifyURL: "", 
    firstName: "", 
    lastName: "", 
    email: "", 
    phone: "", 
    address: "", 
    city: "", 
    country: "", 
    orderID: "001", 
    itemsDescription: "", 
    itemsMap: [item1], 
    currency: .LKR, 
    custom1: "", 
    custom2: ""
)

Recurring

let merchantID = ""
let item = Item(id: "item_1", name: "Item 1", quantity: 1, amount: 50.0)
let initRequest = PHInitialRequest(
    merchantID: merchantID, 
    notifyURL: "", 
    firstName: "", 
    lastName: "", 
    email: "", 
    phone: "", 
    address: "", 
    city: "", 
    country: "", 
    orderID: "002", 
    itemsDescription: "", 
    itemsMap: [item1], 
    currency: .LKR, 
    amount: 60.50, 
    deliveryAddress: "", 
    deliveryCity: "", 
    deliveryCountry: "", 
    custom1: "", 
    custom2: "", 
    startupFee: 0.0, 
    recurrence: .Month(duration: 2), 
    duration: .Forver
)

PreApproval

let merchantID = ""
let item = Item(id: "item_1", name: "Item 1", quantity: 1, amount: 50.0)
let initRequest = PHInitialRequest(
    merchantID: merchantID, 
    notifyURL: "", 
    firstName: "", 
    lastName: "", 
    email: "", 
    phone: "", 
    address: "", 
    city: "", 
    country: "", 
    orderID: "001", 
    itemsDescription: "", 
    itemsMap: [item1], 
    currency: .LKR, 
    custom1: "", 
    custom2: ""
)

Hold On Card

let merchantID = ""
let item = Item(id: "item_1", name: "Item 1", quantity: 1, amount: 50.0)
let initRequest = PHInitialRequest(
            merchantID: merchandID,
            notifyURL: "",
            firstName: "",
            lastName: "",
            email: "",
            phone: "",
            address: "",
            city: "",
            country: "",
            orderID: "",
            itemsDescription: "",
            itemsMap: [item1,item2],
            currency: .LKR,
            amount: 0.0,
            deliveryAddress: "",
            deliveryCity: "",
            deliveryCountry: "",
            custom1: "",
            custom2: "",
            isHoldOnCardEnabled: true 
)

Precent PayHere Payment View

In order to make a payment request, first initialize PayHere ViewController as below;

PHPrecentController.precent(from: self, withInitRequest: initRequest, delegate: self)

Handle Payment Response

extension ViewController : PHViewControllerDelegate{
    func onErrorReceived(error: Error) {
        print("โœ‹ Error",error)
    }
    
    func onResponseReceived(response: PHResponse<Any>?) {
        guard let response = response else {
            print("Could not receive payment response")
            return
        }
        if(response.isSuccess()){
            
            guard let resp = response.getData() as? payHereSDK.StatusResponse else{
                return
            }
            
            print("Payment Success")
            print("Payment Status", resp.status ?? -1)
            print("Message", resp.message ?? "Unknown Message")
            print("Payment No", resp.paymentNo ?? -1.0)
            print("Payment Amount", resp.price ?? -1.0)
            
        }
        else{
            print("Payment Error", response.getMessage() ?? "Unknown Message")
        }
    }
}

FAQ

How to fixed [!] Unable to find a specification for payHereSDK issue

follow the instruction given bellow

$ pod repo remove master
$ pod setup
$ pod install

payhere-mobilesdk-ios's People

Contributors

kamalsampathupsena avatar kamalupasena avatar payheredevs avatar thisura98 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

payhere-mobilesdk-ios's Issues

Build error

pod 'payHereSDK' produces build errors in the project file

Customer object is null when built with all the data passed correctly

i am getting customer object nill here is the code block:
let initRequest:InitRequest = InitRequest()
initRequest.merchantId = merchantID
initRequest.merchantSecret = "yutfgjbhkjniohuiy"
initRequest.customer?.firstName = "Pay"
initRequest.customer?.lastName = "Here"
initRequest.customer?.email = "[email protected]"
initRequest.customer?.phone = "+9477123456"
initRequest.customer?.deliveryAddress?.city = "Colombo"
initRequest.customer?.deliveryAddress?.country = "Sri Lanka"
initRequest.orderId = "001"
initRequest.itemsDescription = "PayHere SDK Sample"
initRequest.items = [item1,item2]
initRequest.currency = "LKR"
initRequest.amount = 50.00
initRequest.customer?.deliveryAddress?.city = "hgfgchgv"
initRequest.customer?.deliveryAddress?.country = "kbgfrytuykh"
initRequest.custom1 = "custom 01"
initRequest.custom2 = "custom 02"

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

Example application

Hi, Im struggle to present the phViewController on top of my view. Can you provide any example application to get better understanding?

"PayHere Bundle could not be found!" Runtime Error

Since version "2.2.2" of the PayHere iOS SDK, you might get this run-time error in a file named "Extension.swift".

  • "PayHere Bundle could not be found!"

This is because the latest PayHere iOS SDK version does not support dynamic frameworks.

To fix the issue follow these steps:

  1. Open your "Podfile" file.
  2. Add a "#" symbol in front of all the lines that state "use_frameworks!"

For example:

  1. Save the file.
  2. Run the following command in your project folder.
pod install

Error when other library using Alamofire different version

AlamofireObjectMapper return build time error: -
Image 11-5-20 at 3 56 AM

And also I'm using the 'RxMoya' library and it using the 'Alamofire 5.0' version as a dependency. Pay-Here required to use 'Alamofire 5.0.0-rc.2'. When both are using the same library and different versions, pod install the latest compatible version of the 'Alamofire ' and 'AlamofireObjectMapper'. In my cause, it's 'Alamofire 5.0.5' & 'AlamofireObjectMapper 6.0'. I think there are not support each other.

it's not a good idea to limit this specific library version !!!!

Please fix this issue ๐Ÿ™๐Ÿผ

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.