Skip to main content

Steps to start accepting payments via SADAD IOS SDK

👉 DOWNLOAD SAMPLE CODE
  • Merchant have to configure PHP code in the server before starting iOS SDK.

SDK Installation and Setup​

Steps to Integration :​

Step 1:installed following depenaded pods in your project.

  • pod 'IQKeyboardManagerSwift'
  • pod 'MaterialComponents/TextControls+FilledTextAreas'
  • pod 'MaterialComponents/TextControls+FilledTextFields'

Step2: Drag the framework 'SadadPaymentSDK' in top of your project. what ever you want to run app into(i.e. App or for simulator)

Step3: Add the framework sadadPaymentSDK in Project -> General -> Frameworks and Libraries -> select Embed and Signin for that framework.

Step4: Now go to the viewcontroller where you neeed to open or access framework and write.

import SadadPaymentSDK

How to Use ?​

  1. Create product array with following details.

  2.     let arrProduct:NSMutableArray = NSMutableArray()
    let productDIC = NSMutableDictionary()
    productDIC.setValue("GUCCI Perfume", forKey: "itemname")
    productDIC.setValue(ProductOneQuantity, forKey: "quantity")
    productDIC.setValue(ProductOneAmount, forKey: "amount")
    arrProduct.add(productDIC)
    arrProduct.add(productDIC)
  3. Use following code for open framework from your project.

  4.     let podBundle = Bundle(for: SelectPaymentMethodVC.self)
    let storyboard = UIStoryboard(name: "mainStoryboard", bundle: podBundle)
    let vc = storyboard.instantiateViewController(withIdentifier: "SelectPaymentMethodVC") as! SelectPaymentMethodVC
    vc.delegate = self
    vc.isSandbox = false
    vc.strAccessToken = strAccessToken
    vc.amount = self.TotalValue()
    vc.arrProductDetails = self.arrProduct
    vc.modalPresentationStyle = .overCurrentContext
    let navigationController = UINavigationController(rootViewController: vc)
    self.present(navigationController, animated: true, completion: nil)
  5. To get the callback from this response extend your class with following Delegate:

  6. class ViewController: UIViewController,SelectCardReponseDelegate {
    }
  7. And call Its delegate method. In which you will get Success/Failure from the SDK. You will get response dictionary in below method. In my demo I have fetch message and statuscode and data from that dictionary and passed to another controller to display success failure message properly.

  8. func ResponseData(DataDIC: NSMutableDictionary) {
    DispatchQueue.main.async {
    let objTransferResponse = self.storyboard?.instantiateViewController(withIdentifier: "TransferResponseVC") as! TransferResponseVC
    objTransferResponse.strMessage = DataDIC.value(forKey: "message") as! String
    objTransferResponse.statusCode = DataDIC.value(forKey: "statusCode") as! Int

    if let strDic = DataDIC.value(forKey: "data") as? NSDictionary{
    objTransferResponse.transferResponse = strDic
    self.navigationController?.pushViewController(objTransferResponse, animated: true)
    }
    }
    }
  9. As per the statuscode value set Success/failure message in your controller. For more details check setResponse() method in TransferResponseVC.swift file. included in demo. For success you will get statuscode value 200. and for failed Transaction you will get statuscode value 400.

Steps to confiqure PHP code in server​

Create a config.php file over your server and write the following code

<?php 
if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
echo 'access denied';
die;
}
/*
* Set the credentials in below places.
*/
$secretkey = '5rQRZSC4t7Ze42Cb'; // Secret key of the merchant
$sadadid = 7648426; // Sadad id of the merchant
$registered_domain = 'www.some.com'; // Registered domain of the merchant
$type = 'sandbox'; // 'live' - For live SDK,'sandbox' - For Sandbox
?>

Create a index.php file over your server and write the following code. Replace the SadadId, SecretKey and Domain with your original details.

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'GET' && realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) {
echo 'access denied';
die;
}

include 'config.php';
$wspath = 'https://api.sadadqatar.com/api-v4/';

$requestdata = array();

$requestdata = '{
"sadadId": "<SadadId>",
"secretKey": "<SecretKey>",
"domain": "<Domain>"
}';

$ch = curl_init($wspath . 'userbusinesses/getsdktoken');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, @$requestdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Content-Length: ' . strlen(@$requestdata)));
$returndata = curl_exec($ch) . "\n";
curl_close($ch);

echo $returndata;
?>