Skip to content

ottuco/ottu-ios-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ottu

The Ottu is iOS SDK makes it quick and easy to build an excellent payment experience in your iOS app. We provide powerful and customizable UI screens and elements that can be used out-of-the-box to collect your user's payment details. We also expose the low-level APIs that power those UIs so that you can build fully custom experiences.

Features

Simplified security: We make it simple for you to collect sensitive data such as credit card numbers and remain PCI compliant. This means the sensitive data is sent directly to Ottu instead of passing through your server.

Apple Pay: We provide a seamless integration with Apple Pay.

Native UI: We provide native screens and elements to collect payment details.

PaymentUI PaymentUI

Localized: We support the following localizations: English, Arabic.

Recommended usage

If you're selling digital products or services that will be consumed within your app, (e.g. subscriptions, in-game currencies, game levels, access to premium content, or unlocking a full version), you must use Apple's in-app purchase APIs. See the App Store review guidelines for more information.

Privacy

The Ottu SDK collects data to help us improve our products and prevent fraud. This data is never used for advertising and is not rented, sold, or given to advertisers.

Requirements

The Ottu requires Xcode 13.0 or later and is compatible with apps targeting iOS 12 or above.

Getting started

To initialize the SDK you need to create session token. You can create session token with our public API Click here to see more detail about our public API.

#Note: Demo project is already created inside the repo. Please go through it if any issue.

Installation

Installation with CocoaPods

Ottu: Ottu is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Ottu', :git => 'https://github.com/ottuco/ottu-ios-sdk.git', :tag => '1.0.86'

Installation with Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding Alamofire as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/ottuco/ottu-ios-sdk.git")
]

Manually

If you prefer not to use any of the aforementioned dependency managers, you can integrate Ottu into your project manually by downloading project and keep the source folder in your project.

Swift 5.1, 5.0, 4.2, 4.0

In ViewController.swift, just import Ottu framework and initalize Ottu SDK.

import Ottu

class ViewController: UIViewController,OttuDelegate {

    var responseDict : [String:Any]?
    var message = ""
    
    //apikey: You will get the apikey from Ottu
    //merchant_id: You will get the merchant id from Ottu
    //sessionid: You will get the sessionid from the public API
    //lang: This is for language. "en" for English and "ar" for Arabic
    override func viewDidLoad() {
        super.viewDidLoad()
        //Intiate the SDK accordingly after getting session id from the public API documentation.
        //session_id - It is generated when payment was created. [See API documentation](https://docs.ottu.com/developer/checkout-api)
        //merchant_id - Merchant domain. See API documentation.
        //apiKey - API Public key should be used. [See API documentation](https://docs.ottu.com/user-guide/configuration/how-to-get-api-keys). 
        //lang - You can use it to change the language. We support two languages english and arabic. You can use "en" for english and "ar" for arabic.        
        let session_id = "ENTER_YOUR_SESSION_ID"
        _ = Ottu.init(session_id, merchant_id: "MERCHANT_ID", apiKey: "API_KEY" ,lang: "ENTER_LANGUAGE_ID_en_or_ar", viewController: self, delegate: self)
    }
    
    //The error callback is invoked when problems occur during a payment.
    //Reason will be defined in the response attribute. 
    func errorCallback(message: String, response: [String : Any]?) {
        responseDict = response
        self.message = "Error"
        self.dismissed()

    }
    
    //Called when a customer cancels the payment.
    func cancelCallback(message: String, response: [String : Any]?) {
        responseDict = response
        self.message = "Cancel"
        self.dismissed()
    }
    
    //Called when the payment completed successfully.
    func successCallback(message: String, response: [String : Any]?) {
        responseDict = response
        self.message = "Success"
        self.dismissed()
    }
    
    //It is a helper function that has to return a promise object, to create the redirect_url.
    //This allows the merchant to redirect the user to the cart page and wait for a while before creating the redirect_url. 
    //In case the customer changes items in the cart, the due amount will be updated accordingly, then the merchant will wait for a while until the customer does not return, then the function returns a promise object, the cart will be frozen and marked as submitted, and the redirect_url will be generated.
    func beforeRedirect() {
        
    }
    
    //After successCallback or cancelCallback or errorCallback you can show alert to the user accordingly.
    func dismissed() {
        DispatchQueue.main.asyncAfter(deadline: .now()+1) {
            let alert = UIAlertController(title: self.message.capitalized, message: "\(String(describing: self.responseDict))", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }
    }
    
}

Inetgrate Apple pay

Please follow below steps to integrate apple pay button in storyboard

ApplePay

Now Create a action for the button and initalise the SDK with session id.

let session_id = "ENTER_YOUR_SESSION_ID"
_ = Ottu.init(session_id, merchant_id: "MERCHANT_ID", apiKey: "API_KEY" ,lang: "ENTER_LANGUAGE_ID_en_or_ar",formsOfPayment: ["applePay"], viewController: self, delegate: self)

Note: You need to pass formsOfPayment as ["applePay"]. If it is not passed then normal flow will start working.

Note: To inetgrate apple pay you need to enable apple pay in capabilites in your project.

Inetgrate STC pay

Please follow below steps to integrate stc pay button in storyboard

STCPay

Now Create a action for the button and initalise the SDK with session id.

let session_id = "ENTER_YOUR_SESSION_ID"
_ = Ottu.init(session_id, merchant_id: "MERCHANT_ID", apiKey: "API_KEY" ,lang: "ENTER_LANGUAGE_ID_en_or_ar",formsOfPayment: ["stcPay"], viewController: self, delegate: self)

Note: You need to pass formsOfPayment as ["stcPay"]. If it is not passed then normal flow will start working.

Licenses