yohannescodes / Chapa4iOSFramework

An SDK for Chapa

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Chapa4iOSXCFramework

This is the XCFramework Project for Chapa4iOS (Unofficial iOS SDK of Chapa).

chapalogo

Chapa4iOS (Unofficial)

An iOS SDK for projects with Swift Programming Language
Accessible over Swift Package Manager

Inspired by the works of YohannesTz and Chapi, Chapa4iOS is the unofficial iOS SDK for Chapa. This is done according to the official documentation provided by the internal team of Chapa.

Features

  • Generate Transaction Reference (Util)
  • Accept Payment
  • Verify Payment

Remark

We have dealt with the snake_case variable names of JSON by mapping them into camelCase representations to make the models prepared comforming to Codable protocol.

Installation

Chapa4iOS can be installed with the Swift Package Manager (SPM): (https://github.com/yohannescodes/Chapa4iOS/)

Getting Started

Once the installation process is done, we can import the SDK in the file we want to use it in.

Configuration

import Chapa4iOS

var chapa: Chapa!

override func viewDidLoad(){
  chapa = Chapa(secretKey: "**YOUR SECRET KEY FROM CHAPA DASHBOARD**")
}

Generate Transaction Reference

This utility method of Chapa instance allows you to generating a customizable random alpha numberic transaction reference.

let transactionReference = chapa.generateTransactionReference()

Accept Payment

Here we can initialize transaction by providing customer information and requesting for a checkout URL to load for our users.

let customer = Customer(amount: "100", currency: .etb, email: nil, firstName: "Yohannes", lastName: "Haile", phoneNumber: "0922106876", txRef: transactionReference, callbackURL: nil, returnURL: nil, customization: nil)

//Enter the instance of your View Controller when you call the following method so it can instantiate Web View for the Checkout page it retrieves from the response.
chapa.acceptPayment(controller: self, customer: customer)

Data Types of Optional Properties:

  • email: String?
  • firstName: String?
  • lastName: String?
  • phoneNumber: String?
  • callbackURL: String?
  • returnURL: String? (HIGHLY RECOMMENDED TO PROVIDE THIS FIELD)
  • customization: ChapaCustomization?

What can you customize?

You can customize the checkout page for your users by providing:

  • title
  • description

Verify Payment

To verify payment, simply call the verify method from Chapa instance.

chapa.verifyPayment(controller: self, txRef: transactionReference)

Remark

Successfully presenting the checkout page doesn’t necessarily mean your customer has finalized their payment. You need to verify the transaction by providing the transaction reference you generated before initializing Customer object.

About

An SDK for Chapa

License:MIT License


Languages

Language:Swift 96.5%Language:Objective-C 3.5%