Skip to content

QattahPay/SampleWithSDK-iOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Qattah Pay iOS SDK Library

Qattah Pay iOS SDK Library is a payment integration library that allows merchants to accept payments in their iOS applications.

Getting Started

To include the Qattah Pay iOS SDK Library in your iOS application, follow these steps:

  1. Open your Xcode project, navigate the File tab within the macOS bar, and click on “Add Packages”.

  1. In the Add New Package window you can search for a package via the URL to the Github page (https://github.com/QattahPay/qattahpay-ios-sdk/).

Usage

To use the QattahPay iOS SDK Library, you need to import the qattahpay_ios_sdk to your project by:

import qattahpay_ios_sdk

And then create a new QattahPaySDK object where you want as in the below example: Note: you have to put your API key in the initiation phase.

    var body: some Scene {
        WindowGroup {
            ContentView(viewModel: ContentViewModel(qattahPay: QattahPaySDK(apiKey: "<YOUR_API_HERE>")))
        }
    }

To make a payment request, you need to create a PaymentRequest object and call the startPayment() method:

// create a new payment request
let paymentRequest = PaymentRequestBuilder().setAmount(120).setCurrency(Currency.SAR).setOrderId("ORDER_ID").setDescription("ORDER_DESCRIPTION").setCustomerEmail("customer@email.com").setCustomerMobileNumber("0501234567").setLanguage(language)
            .setTheme(theme).isSandbox(true).build()

 // start a new payment session
 qattahPay.startPaymentSession(paymentRequest: paymentRequest, onSuccess: { qattahResponse in
    //handle creation success
    
}, onFail: { errorMessage in
    //handle creation failure
    
})

After starting a new payment session with Qattah Pay, you will get a new qattahResponse object in the onSuccess callback of the startPaymentSession function, by this object you can navigate to the QattahWebView which is built using SwiftUI as following:

NavigationLink(destination: QattahWebView(qattahResponse: viewModel.qattahResponse, qattahPaymentCallback: self.qattahPaymentCallback as PaymentCallback), isActive: $viewModel.navigatToQattahWebView) {
    EmptyView()
}

And you can handle all callbacks by creating a new class that implements the protocol PaymentCallback for the Qattah Pay Callback Service by following the below steps:

import Foundation
import qattahpay_ios_sdk

class QattahPaymentCallback: PaymentCallback {
    
    func onStarted(paymentId: String) {
        print(paymentId)
    }
    
    func onSuccess(paymentId: String) {
        print(paymentId)
    }
    
    func onError(errorMessage: String) {
        print(errorMessage)
    }
    
    func onCancel() {
        print("onCancel")
    }
}

License

This library is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages