SDK Functions Code Samples

This guide will provide you with guidance on various code samples that you can use to enable various functions that we have in our iOS SDK.

📘

Note:

The code samples shown here are the backend of the program and not including the interface. You can modify the interface as needed when you build your own app.

1. Authentication

You should start with the authentication first when you use our iOS SDK. There are log in and log out functions within authentication.

1.1 Log in

To enable the login function, simply follow the code below:

Code sample:

import UIKit
import RMSCocoapodsLibrary

@available(iOS 13.0, *)
class LoginVC: UIViewController {

    let scope = "rms/pos:read+rms/pos:write";
    let redirectURL =  URL.init(string: "rmssdk://www.rmssdk.com/callback");
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    var activityView = UIActivityIndicatorView(style: .large)
    
    @IBOutlet weak var loginbutton: UIButton!
    override func viewDidLoad() {
        super.viewDidLoad();
        appDelegate.rmsOAuth.allowMissingStateCheck = true;
        let defaults1 = UserDefaults.standard
        if let stringOne = defaults1.string(forKey: "refreshToken") {
            self.showActivityIndicatory();
            loginbutton.isHidden = true;
            appDelegate.rmsOAuth.renewAccessToken(withRefreshToken: stringOne, completionHandler: { result in
            print("result:::::::",result)
            switch result {
            case .success(let (credential, _, _)):
              print("result success refresh:::::::",credential.oauthToken)
                self.activityView.stopAnimating();
                self.activityView.removeFromSuperview();
                self.loginbutton.isHidden = false;
                let defaults = UserDefaults.standard
                defaults.set(credential.oauthToken, forKey: "accessToken");
                if let terminalvc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "terminals") as? TerminalVC {
                    self.navigationController?.pushViewController(terminalvc, animated: true)
                }
                
            case .failure(let error):
                self.activityView.stopAnimating();
                self.activityView.removeFromSuperview();
                self.loginbutton.isHidden = false;
                print(error.localizedDescription)
            }
        })
        }
    }
    func showActivityIndicatory() {
       activityView.center = self.view.center
       self.view.addSubview(activityView)
       activityView.startAnimating()
   }
    @IBAction func setAuthorize(_ sender: Any) {
        appDelegate.rmsOAuth.authorize(withCallbackURL:  redirectURL, scope: scope, state: "", completionHandler: { result in
            print("result:::::::",result)
            switch result {
            case .success(let (credential, _, _)):
                // Setting
                let defaults = UserDefaults.standard
                defaults.set(credential.oauthToken, forKey: "accessToken")
                defaults.set(credential.oauthRefreshToken, forKey: "refreshToken")
              // Do your request
                if let terminalvc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "terminals") as? TerminalVC {
                    self.navigationController?.pushViewController(terminalvc, animated: true)
                    }
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }

}

2. Select the terminal

To enable the terminal selection function, please refer to the code sample below.

Code sample:

func getTerminals() {
        appDelegate.rmsOAuth.client.getTerminalList(completionHandler: { result in
            switch result {
            case .success(let data):
                let response: RMSOAuthResponse = data
             
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                
                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        if let appJson = json!["_embedded"] as? Dictionary<String, Any> {
                            let results: NSArray = appJson["terminals"] as! NSArray
                         self.terminals = results;
                         print("self.terminals::::::",self.terminals);
                         self.terminalList.reloadData();

                            
                            
                        }
                    } catch {
                        print("Something went wrong")
                    }
                }
            case .failure(let error):
              print(error.localizedDescription)
            }
        })

3. Initiate a sale

To enable the sale initiation function, please refer to the code sample below.

Code sample:

@IBAction func saleClicked(_ sender: Any) {
        if amount.text == "0.00" {
            let alert = UIAlertController(title: "", message: "Please Enter Amount", preferredStyle: UIAlertController.Style.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            return;
        }
        cashbackView.isHidden = true;
        print(((terminal.value(forKey: "_links") as! NSDictionary).value(forKey: "self") as! NSDictionary).value(forKey: "href") as! NSString);
        let terminalURL = ((terminal.value(forKey: "_links") as! NSDictionary).value(forKey: "self") as! NSDictionary).value(forKey: "href") as! NSString;
        let params1 = NSMutableDictionary();
        let finalAmount =  amount.text?.replacingOccurrences(of: ".", with: "");
        params1["amount"] = Int(finalAmount!)
        params1["currency"] = "GBP"
        params1["transactionType"] = "SALE"

        let headers = NSMutableDictionary();
        headers["Accept"] = "*/*"
        headers["Content-Type"] = "application/json"
        headers["Connection"] = "keep-alive"
        appDelegate.rmsOAuth.client.post("\(terminalURL)/transaction", parameters: params1 as! RMSOAuth.Parameters, headers: (headers as! RMSOAuth.Headers), body: nil, completionHandler: { result in
            print("terminal result:::::::",result);
            switch result {
            case .success(let data):
              print("result success datadatadatadata:::::::",data)
                let response: RMSOAuthResponse = data
                //print("data string:::::::::::",data.jsonObject)
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                
                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        print("json::::::::",json!);
                        self.transView.isHidden = false;
                        self.cashbackView.isHidden = true;
                        self.amount.resignFirstResponder();
                        self.cashback.resignFirstResponder();
                        self.updateReceiptStatus(jsonValue: json!)
                    } catch {
                        print("Something went wrong")
                    }
                }
                
               
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
       
    }

4. Initiate a refund

To enable the refund initiation function, please refer to the code sample below.

Code sample:

@IBAction func refundClicked(_ sender: Any) {
        let finalAmount =  Int((amount.text?.replacingOccurrences(of: ".", with: ""))!);
        appDelegate.rmsOAuth.client.CreateTransaction(amount:finalAmount!, currency: "GBP", transactionType: "REFUND", completion: { result in
            switch result {
            case .success(let data):
              print("refundClicked success datadatadatadata:::::::",data)
                let response: RMSOAuthResponse = data
                //print("data string:::::::::::",data.jsonObject)
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                
                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        print("json::::::::",json!);
                        self.transView.isHidden = false;
                        self.cashbackView.isHidden = true;
                        self.amount.resignFirstResponder();
                        self.cashback.resignFirstResponder();
                        self.updateReceiptStatus(jsonValue: json!)
                    } catch {
                        print("Something went wrong")
                    }
                }
                
               
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }

5. Initiate a cashback

To enable the cashback initiation function, please refer to the code sample below.

Code sample:

@IBAction func cashbackClicked(_ sender: Any) {
        if amount.text == "0.00" {
            let alert = UIAlertController(title: "", message: "Please Enter Amount", preferredStyle: UIAlertController.Style.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            return;
        }
        else if cashback.text == "0.00" {
            let alert = UIAlertController(title: "", message: "Please Enter Cashback Amount", preferredStyle: UIAlertController.Style.alert)
            alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
            return;
        }
        transView.isHidden = true;
        print(((terminal.value(forKey: "_links") as! NSDictionary).value(forKey: "self") as! NSDictionary).value(forKey: "href") as! NSString);
        let terminalURL = ((terminal.value(forKey: "_links") as! NSDictionary).value(forKey: "self") as! NSDictionary).value(forKey: "href") as! NSString;
        let params1 = NSMutableDictionary();
        let finalAmount =  amount.text?.replacingOccurrences(of: ".", with: "");
        let cashbackAmount =  cashback.text?.replacingOccurrences(of: ".", with: "");
        params1["amount"] = Int(finalAmount!)
        params1["currency"] = "GBP"
        params1["transactionType"] = "SALE"
        params1["amountCashback"] = Int(cashbackAmount!)
        

        let headers = NSMutableDictionary();
        headers["Accept"] = "*/*"
        headers["Content-Type"] = "application/json"
        headers["Connection"] = "keep-alive"
        appDelegate.rmsOAuth.client.post("\(terminalURL)/transaction", parameters: params1 as! RMSOAuth.Parameters, headers: (headers as! RMSOAuth.Headers), body: nil, completionHandler: { result in
            print("terminal result:::::::",result);
            switch result {
            case .success(let data):
              print("result success datadatadatadata:::::::",data)
                let response: RMSOAuthResponse = data
                //print("data string:::::::::::",data.jsonObject)
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                
                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        print("json::::::::",json!);
                        //print("transURLtransURLtransURLtransURL:: %@",self.transURL!);
                        self.transView.isHidden = true;
                        self.cashbackView.isHidden = false;
                        self.amount.resignFirstResponder();
                        self.cashback.resignFirstResponder();
                        self.updateReceiptStatus(jsonValue: json!)
                    } catch {
                        print("Something went wrong")
                    }
                }
                
               
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
       
    }

6. Cancel transaction

To enable the transaction cancellation function, please refer to the code sample below.

Code sample:

@IBAction func cancelTransaction(_ sender: Any) {
        print("transURL::::: %@",self.transURL!)
        appDelegate.rmsOAuth.client.delete(self.transURL!, completionHandler: { result in
            print("refreshStatus result:::::::",result);
            switch result {
            case .success(let data):
              print("result success datadatadatadata:::::::",data)
                let response: RMSOAuthResponse = data
                //print("data string:::::::::::",data.jsonObject)
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                
                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        print("json refreshStatus::::::::",json!)
                        self.updateReceiptStatus(jsonValue: json!)
                      
                    } catch {
                        print("Something went wrong")
                    }
                }
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
        
    }

7. List/filter transactions and retrieve the transaction's status

You can list/filter the transactions by status, type, and, transaction ID and retrieve the transaction's status. To do that, please refer to the code sample below.

Code sample:

//
//  TransactionList.swift
//  RMSExample
//
//  Created by Developer on 15/11/21.
//
import UIKit
import RMSCocoapodsLibrary

@available(iOS 13.0, *)
class TransactionList: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
    
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    let barHeight: CGFloat = UIApplication.shared.statusBarFrame.size.height
    var terminal : NSDictionary = [:];
    var transURL : String? = nil;
    private var transactions: NSArray = []
    private var transactionList: UITableView!
    lazy var searchBar:UISearchBar = UISearchBar()
    var isSearch : Bool = false
    var filteredTableData: NSArray = []
    var transactionType : String? = "";
    var transactionStatus : String? = "";
    @IBOutlet weak var sideView: UIView!
    @IBOutlet weak var saleImg: UIImageView!
    @IBOutlet weak var refundImg: UIImageView!
    @IBOutlet weak var successfulImg: UIImageView!
    @IBOutlet weak var referralImg: UIImageView!
    @IBOutlet weak var cancelUserImg: UIImageView!
    @IBOutlet weak var notSuccessImg: UIImageView!
    @IBOutlet weak var cancelPOSImg: UIImageView!
    @IBOutlet weak var revertPOSImg: UIImageView!
    @IBOutlet weak var timeoutImg: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Transaction List";
        let rightButtonItem = UIBarButtonItem.init(
              title: "Filter",
            style: .done,
              target: self,
            action: #selector(rightButtonAction)
        )

        self.navigationItem.rightBarButtonItem = rightButtonItem
        
        
        let displayWidth: CGFloat = self.view.frame.width
        let displayHeight: CGFloat = self.view.frame.height
        searchBar = UISearchBar(frame: CGRect(x: 0, y: barHeight+44, width: displayWidth, height:44))
        searchBar.searchBarStyle = UISearchBar.Style.default
        searchBar.placeholder = " Search by Transaction Id"
        searchBar.sizeToFit()
        searchBar.isTranslucent = false
        searchBar.backgroundImage = UIImage()
        searchBar.delegate = self
        transactionList = UITableView(frame: CGRect(x: 0, y: barHeight+98, width: displayWidth, height: displayHeight - barHeight-98))
        transactionList.register(TransactionTableCell.self, forCellReuseIdentifier: "MyCell")
        transactionList.dataSource = self
        transactionList.delegate = self
        self.view.addSubview(transactionList)
        self.view.addSubview(searchBar)
        self.getTransactionList();
    }
    func getTransactionList() {
        appDelegate.rmsOAuth.client.getTransactionList(completionHandler: { result in
            print("TransactionList result:::::::",result);
            switch result {
            case .success(let data):
                let response: RMSOAuthResponse = data
                let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))

                if let data = getResponse!.data(using: String.Encoding.utf8) {
                    do {
                        let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                        if let appJson = json!["_embedded"] as? Dictionary<String, Any> {
                            let results: NSArray = appJson["transactions"] as! NSArray
                            print("transaction result:::::",results);
                         self.transactions = results;
                         self.transactionList.reloadData();
                        }

                    } catch {
                        print("Something went wrong")
                    }
                }
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }
    @objc func rightButtonAction(sender: UIBarButtonItem) {
        if self.sideView.isHidden {
            self.view.bringSubviewToFront(self.sideView)
            self.sideView.isHidden = false
            searchBar.resignFirstResponder()
            self.title = "Filter";
        }
        else
        {
            self.title = "Transaction List";
            self.sideView.isHidden = true
        }
    }
    func getAmount(amountValue : String) -> String {
        var amountText = amountValue
        let count = amountValue.count
        if count > 2 {
            let deciamlIndex = count - 2
            let suffixAmount = amountValue.suffix(2)
            let prefixAmount = amountValue.prefix(deciamlIndex)
            amountText = NSString.init(format: "%@.%@", prefixAmount as CVarArg,suffixAmount as CVarArg) as String
        }
        return amountText;
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        isSearch ? filteredTableData.count : transactions.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        let transaction: NSDictionary = isSearch ? filteredTableData[indexPath.row] as! NSDictionary : transactions[indexPath.row] as! NSDictionary;
        if transaction["finalTransactionAmount"] != nil
        {
            return 170.0
        }
        return 140.0
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//        let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath as IndexPath)
//        cell.textLabel!.text = "\(indexPath.row)"
//        return cell
        
        let transaction: NSDictionary = isSearch ? filteredTableData[indexPath.row] as! NSDictionary : transactions[indexPath.row] as! NSDictionary;
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! TransactionTableCell
        let amountString = transaction["amount"] ?? "";
        let amountText = self.getAmount(amountValue: NSString.init(format: "%@", amountString as! CVarArg) as String)
        if transaction["finalTransactionAmount"] != nil
        {
            let cashbackAmountString = transaction["amountCashback"] ?? "";
            let cashbackAmountText = self.getAmount(amountValue: NSString.init(format: "%@", cashbackAmountString as! CVarArg) as String)
            let finalAmountString = transaction["finalTransactionAmount"] ?? "";
            let finalAmountText = self.getAmount(amountValue: NSString.init(format: "%@", finalAmountString as! CVarArg) as String)
            cell.label.text = "Transaction Amount: \(amountText) GBP\nCashback  Amount: \(cashbackAmountText) GBP\nFinal Transaction Amount: \(finalAmountText) GBP\nTransaction Id: \(transaction.value(forKey: "transactionRefId") as! String)\nTransaction Stage: \(transaction.value(forKey: "transactionStage") as! String)\nTransaction Status: \(transaction.value(forKey: "transactionStatus") as! String)\nTransaction Type: \(transaction.value(forKey: "transactionType") as! String)";
        }
        else
        {
            cell.label.text = "Transaction Amount: \(amountText) GBP\nTransaction Id: \(transaction.value(forKey: "transactionRefId") as! String)\nTransaction Stage: \(transaction.value(forKey: "transactionStage") as! String)\nTransaction Status: \(transaction.value(forKey: "transactionStatus") as! String)\nTransaction Type: \(transaction.value(forKey: "transactionType") as! String)";
        }
        
        return cell
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        sideView.isHidden = true;
    }
    
    //MARK: UISearchbar delegate
        func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
            isSearch = true;
            sideView.isHidden = true;
        }
           
        func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
               searchBar.resignFirstResponder()
               isSearch = false
        }
           
        func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
               searchBar.resignFirstResponder()
               isSearch = false
        }
           
        func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
               searchBar.resignFirstResponder()
               isSearch = false
        }
        func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
            if searchText.count == 0 {
                isSearch = false
                self.transactionList.reloadData()
            } else {
                let filterPredicate = NSPredicate(format: "transactionRefId BEGINSWITH[c] %@", searchText)
                filteredTableData = transactions.filtered(using: filterPredicate) as NSArray
              
//                filteredTableData = transactions.filter({ (text) -> Bool in
//                    let tmp: NSString = text as NSString
//                    let range = tmp.range(of: searchText, options: NSString.CompareOptions.caseInsensitive)
//                    return range.location != NSNotFound
//                })
                if(filteredTableData.count == 0){
                    isSearch = false
                } else {
                    isSearch = true
                }
                self.transactionList.reloadData()
            }
        }
    func updateTrasactionType(updateValue: Bool, index: Int) {
        if index == 1 && updateValue{
            self.transactionType = "SALE"
        }
        else if index == 2 && updateValue{
            self.transactionType = "REFUND"
        }
        else if !updateValue{
            self.transactionType = ""
        }
    }
    func updateTrasactionStatus(updateValue: Bool, index: Int) {
        if index == 3 && updateValue{
            self.transactionStatus = "SUCCESSFUL"
        }
        else if index == 4 && updateValue{
            self.transactionStatus = "REFERRAL"
        }
        else if index == 5 && updateValue{
            self.transactionStatus = "CANCELLED_BY_USER"
        }
        else if index == 6 && updateValue{
            self.transactionStatus = "NOT_SUCCESSFUL"
        }
        else if index == 7 && updateValue{
            self.transactionStatus = "CANCELLED_BY_POS"
        }
        else if index == 8 && updateValue{
            self.transactionStatus = "REVERTED_BY_POS"
        }
        else if index == 9 && updateValue{
            self.transactionStatus = "TIMEOUT"
        }
        else if !updateValue{
            self.transactionStatus = ""
        }
    }
    @IBAction func filterButtonCalled(sender: UIButton)
    {
        
        if sender.tag == 1 {
            self.updateTransactionImage(senderimg: saleImg, index: sender.tag)
        }
        else if sender.tag == 2 {
            self.updateTransactionImage(senderimg: refundImg, index: sender.tag)
        }
        else if sender.tag == 3 {
            self.updateStatusImage(senderimg: successfulImg, index: sender.tag)
        }
        else if sender.tag == 4 {
            self.updateStatusImage(senderimg: referralImg, index: sender.tag)
        }
        else if sender.tag == 5 {
            self.updateStatusImage(senderimg: cancelUserImg, index: sender.tag)
        }
        else if sender.tag == 6 {
            self.updateStatusImage(senderimg: notSuccessImg, index: sender.tag)
        }
        else if sender.tag == 7 {
            self.updateStatusImage(senderimg: cancelPOSImg, index: sender.tag)
        }
        else if sender.tag == 8 {
            self.updateStatusImage(senderimg: revertPOSImg, index: sender.tag)
        }
        else if sender.tag == 9 {
            self.updateStatusImage(senderimg: timeoutImg, index: sender.tag)
        }
        
    }
    func updateTransactionType(senderimg: UIImageView, index: Int)  {
        switch index {
        case 1:
            refundImg.image = UIImage(systemName: "square");
            self.transactionType = "SALE"
        case 2:
            saleImg.image = UIImage(systemName: "square");
            self.transactionType = "REFUND"
        default:
            refundImg.image = UIImage(systemName: "square");
            saleImg.image = UIImage(systemName: "square");
            self.transactionType = ""
        }
    }
    func updateTransactionStatus(senderimg: UIImageView, index: Int)  {
        switch index {
        case 3:
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "SUCCESSFUL"
        case 4:
            successfulImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "REFERRAL"
        case 5:
            referralImg.image = UIImage(systemName: "square");
            successfulImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "CANCELLED_BY_USER"
        case 6:
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            successfulImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "NOT_SUCCESSFUL"
        case 7:
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            successfulImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "CANCELLED_BY_POS"
        case 8:
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            successfulImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = "REVERTED_BY_POS"
        case 9:
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            successfulImg.image = UIImage(systemName: "square");
            self.transactionStatus = "TIMEOUT"
        default:
            successfulImg.image = UIImage(systemName: "square");
            referralImg.image = UIImage(systemName: "square");
            cancelUserImg.image = UIImage(systemName: "square");
            notSuccessImg.image = UIImage(systemName: "square");
            cancelPOSImg.image = UIImage(systemName: "square");
            revertPOSImg.image = UIImage(systemName: "square");
            timeoutImg.image = UIImage(systemName: "square");
            self.transactionStatus = ""
        }
    }
    func updateTransactionImage(senderimg: UIImageView, index: Int){
        if (senderimg.image?.isEqual(UIImage(systemName: "square")))! {
            senderimg.image = UIImage(systemName: "checkmark.square.fill");
            self.updateTransactionType(senderimg: senderimg, index: index)
        }
        else
        {
            senderimg.image = UIImage(systemName: "square");
            self.transactionType = ""
        }
    }
    func updateStatusImage(senderimg: UIImageView, index: Int){
        if (senderimg.image?.isEqual(UIImage(systemName: "square")))! {
            senderimg.image = UIImage(systemName: "checkmark.square.fill");
            self.updateTransactionStatus(senderimg: senderimg, index: index)
            
        }
        else
        {
            senderimg.image = UIImage(systemName: "square");
            self.transactionStatus = ""
        }
    }
    @IBAction func filterSearchClicked(_ sender: Any) {
        sideView.isHidden = true;
        self.transactions = [];
        self.transactionList.reloadData();
        appDelegate.rmsOAuth.client.getTransactionListByAll(transactionType: self.transactionType!, transactionStage: "", transactionStatus: self.transactionStatus!, parameters: [:], headers: nil, completionHandler: { result in
                switch result {
                case .success(let data):
                    let response: RMSOAuthResponse = data
                    let getResponse = response.dataString(encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))
                    print("check getResponse:::::",getResponse as Any)
                    if let data = getResponse!.data(using: String.Encoding.utf8) {
                        do {
                            let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String:Any]
                            if let appJson = json!["_embedded"] as? Dictionary<String, Any> {
                                let results: NSArray = appJson["transactions"] as! NSArray
                                print("transaction result:::::",results);
                             self.transactions = results;
                             self.transactionList.reloadData();
                            }

                        } catch {
                            print("Something went wrong")
                        }
                    }
                case .failure(let error):
                  print(error.localizedDescription)
                }
            })
        
        
    }
    @IBAction func filterResetClicked(_ sender: Any) {
        saleImg.image = UIImage(systemName: "square");
        refundImg.image = UIImage(systemName: "square");
        successfulImg.image = UIImage(systemName: "square");
        referralImg.image = UIImage(systemName: "square");
        cancelUserImg.image = UIImage(systemName: "square");
        notSuccessImg.image = UIImage(systemName: "square");
        cancelPOSImg.image = UIImage(systemName: "square");
        revertPOSImg.image = UIImage(systemName: "square");
        timeoutImg.image = UIImage(systemName: "square");
        sideView.isHidden = true;
        self.getTransactionList();
        
    }
    
}


class TransactionTableCell: UITableViewCell {
    var label = UILabel()
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        contentView.backgroundColor = .white
        contentView.layer.masksToBounds = true
        contentView.layer.borderColor = UIColor.gray.cgColor
        contentView.layer.borderWidth = 0.5
        label = UILabel(frame: CGRect(x: 10, y: 0, width: 400, height: 160))
        //label.center = CGPoint(x: 160, y: 40)
        label.textAlignment = .left
        label.numberOfLines = 7
        label.font = UIFont.systemFont(ofSize: 18.0)
        label.backgroundColor = .white
        label.text = "-"
       
        contentView.addSubview(label)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

8. View all transactions

To enable view all transactions functions, please refer to the code sample below.

Code sample:

@IBAction func transactionListCalled(_ sender: Any) {
        reportUpdate.isHidden = true;
        if let transactionListVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "transactionList") as? TransactionList {
            transactionListVC.terminal = terminal;
            self.navigationController?.pushViewController(transactionListVC, animated: true)
        }
    }

9. Start an XBAL and ZBAL Report

To enable the XBAL and ZBAL report generator function, please refer to the code sample below.

Code sample:

@IBAction func reportXBAL(_ sender: Any) {
        reportUpdate.isHidden = true;
        appDelegate.rmsOAuth.client.requestReportByType(type: "XBAL", completionHandler: { result in
            print("TransactionList result:::::::",result);
            switch result {
            case .success( _):
                self.reportUpdate.isHidden = false;
                self.reportUpdate.text = "XBAL Report created successfully"
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }
    
    @IBAction func reportZBAL(_ sender: Any) {
        reportUpdate.isHidden = true;
        appDelegate.rmsOAuth.client.requestReportByType(type: "ZBAL", completionHandler: { result in
            print("TransactionList result:::::::",result);
            switch result {
            case .success( _):
                self.reportUpdate.isHidden = false;
                self.reportUpdate.text = "ZBAL Report created successfully"
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }
    
    @IBAction func reportEOD(_ sender: Any) {
        reportUpdate.isHidden = true;
        appDelegate.rmsOAuth.client.requestReportByType(type: "EOD", completionHandler: { result in
            print("TransactionList result:::::::",result);
            switch result {
            case .success( _):
                self.reportUpdate.isHidden = false;
                self.reportUpdate.text = "EOD Report created successfully"
            case .failure(let error):
              print(error.localizedDescription)
            }
        })
    }

💬 We're here to help!

If you're looking for help, shoot us an email. Please include a description of the issues that you are running into.


Did this page help you?