📱Cowpay iOS Framework

This document is a guide for Cowpay iOS Framework. In addition, following the below steps will help you learn how to add and use (Cowpay Framework) in your iOS Application.

1. REQUIREMENTS

  • minimum Xcode version 14.2

  • minimum iOS Deployment 15.2

2. INSTALLATION

1. Manual Installation

  1. Download the zip file from Versions page.

  2. Unzip the file you will find CowpayFramework.xcframework file

  3. Add the CowpayFramework.xcframework to your project by drag and drop the file to the Frameworks extension like the screenshot below:

2. Swit Package Manager

  1. Go to your project's General page

  2. Select your target

  1. Scroll to the Frameworks section

  2. Press the plus button

  1. In this window click on Add Other then Add Package Dependency

  1. Add the following URL to the search bar in the top right corner:

https://github.com/cowpay-me/CowpayPackage.git
  1. You will find CowpayPackage visible in the packages panel

  2. After clicking on it you can add the package directly from the master branch to get the latest version available. or you can download a specific version by changing the Dependency Rule to Exact Version and writing down the version compatible with your environment.

You can find our versions on the Versions page.

  1. Click Add Package and you are good to go

3. IMPORT

import CowpayFramework

4. USAGE

  1. First Apply to CowpayCallBack Protocol to use callbacks from the framework

For UIKit
class YourViewController: UIViewController, CowpayCallBack {
    func onClosedByUser() {
        
    }
    
    func onSuccess(model: PaymentSuccessModel) {
        
    }
    
    func onError(model: PaymentErrorModel) {
        
    }
}
For Swiftui
struct YourView: View, CowpayCallBack {
    func onClosedByUser() {
        
    }
    
    func onSuccess(model: PaymentSuccessModel) {
        
    }
    
    func onError(model: PaymentErrorModel) {
        
    }
}
  1. Initialize your payment info:

let paymentInfo = try PaymentInfo(description: "description", merchantReferenceId: "merchantReferenceId", amount: Double, customerEmail: "customerEmail", customerFirstName: "customerFirstName", customerLastName: "customerLastName", customerMobile: "customerMobile", customerMerchantProfileId: "customerMerchantProfileId", isFeesOnCustomer: true)

  1. initialize Cowpay init model and pass the payment info and CowbayCallBack Protocol delegate reference

let cowpayInitModel = try CowpayInitModel(merchantCode: "marchantCode", merchantHashCode: "merchantHashCode", merchantMobile: "merchantMobile" ,logoStringUrl: "logoStringUrl", cowpayEnvironment: CowpayEnviroment, localizationCode: LocalizationEnum, cowpayCallback: CowpayCallBack, paymentInfo: PaymentInfo)

  1. Launch Cowpay:

For UIKit

let cowpayViewController = CowpayFrameWork.initCowpayViewController(cowpayInitModel: cowpayInitModel)
self.present(cowpayViewController)
For Swiftui
NavigationLink(destination: CowpayFrameWork.initCowpaySwiftUIView(cowpayInitModel: cowpayInitModel), isActive: $navigateKey){ EmptyView()}

5. VALUES DESCRIPTION

Keys
Values

localizationCode

Select your language code enum value .en for English, and .ar if Arabic. (default is en)

amount

two decimal value like "15.60", sent in case of partial capture

customerEmail

customer valid email (should not be empty or nill)

customerMobile

internationally formatted customer mobile (should not be empty or nill)

customerLastName

customer last name being charged (should not be empty or nill)

customerFirstName

customer first name being charged (should not be empty or nill)

isfeesOnCustomer

is fees on customer or merchant (default is false)

logoStringUrl

merchant logo url (Optional)

merchantMobile

merchant mobile (should be valid mobile number starting with 01 and should not be empty or nill)

description

charge request description that reserve the payment name (should not be empty or nil)

customerMerchantProfileId

ID of the customer being charged on your system (should not be empty or nil)

merchantReferenceId

Unique alphanumeric value required as identifier for the charge request (must be unique per transaction and not be empty or nil)

cowpayEnvironment

.staging || .production (should not be empty or nil)

merchantHashCode

Hash code that is presented in your panel. (should not be empty or nil)

merchantCode

Your code is presented in your panel. (should not be empty or nil)

onSuccess

Call back function if transaction succeeds.

onError

Call back function when an error occurres.

onClosedByUser

Call back function if customer goes back before making a transaction.

cowpayCallBack

A delegate that handles the payment status (Required)

paymentInfo

Your payment info object (Required)

Last updated