How to use PayTabs payment gateway in iOS application.

Hi everyone, here we will discuss about how to use PayTabs payment gateway in iOS application.

You can study their integration guide from the below mentioned link:

 https://www.paytabs.com/PayTabs_iOS_SDK_V2.0.pdf

Before entering in to code first we want to know what a payment gateway is

payment gateway is an ecommerce service that practices credit card payments for online and traditional piece and mortar stores. It completes an essential role in the ecommerce transaction process; permit the payment between merchant and client.

Now start by the following instruction mentioned below:

  1. Download the PayTabs iOS SDK  https://www.dropbox.com/s/40jjk40dmnfz79j/PayTabs_Objective%20c.zip?dl=0
  2. Copy or drag drop each the content inside Demo Merchants folder into your project.
  3. Build bridging header or XCode will automatically build it for you when you drag drop content inside Demo Merchants/headerfiles.
  4. Inside the bridging header.h file paste #import“PayTabCardReaderViewController.h”.
  5. Now, In Payment ViewController build an object of PayTabCardReaderViewController similar to this.
var paytab = PayTabCardReaderViewController()
  1. Then paste this code inside your payment class
func callPaytabPaymentGateway(){

        paytab.tag_amount = "Order's total amount"

        paytab.tag_title = "Order payment title like customer's Firstname , Lastname etc"

        paytab.tag_currency = "Order amount currency"

        paytab.sdklanguage = "Your SDK language code like 'en' "

        paytab.tag_tax = "Total applicable tax";

 

        paytab.shipping_address = "Customer's shipping address";

        paytab.shipping_city = "Customer's shipping city";

        paytab.shiping_country = "Customer's shipping country";

        paytab.shipping_state = "Customer's shipping state"

        paytab.shipping_zip_code = "Customer's shipping zipcode"

 

        paytab.billing_address = "Customer's billing address"

        paytab.billing_city = "Customer's billing city"

        paytab.billing_country = "Customer's billing country"

        paytab.billing_state = "Customer's billing state"

        paytab.billing_zip_code = "Customer's billing zipcode"

        paytab.order_id = "Customer's order id that uniquely identifies order"

        paytab.phonenum = "Customer phone number"

        paytab.customer_email = "Customer's mail Id"

 

        paytab.tag_merchant_email = "Your merchant Id"

        paytab.timerFlag = 20100;//seconds

        

        paytab.secretKey = "Your merchant secret key"

        paytab.tag_original_assignee_code = "SDK"; // booking id - n

        self.present(paytab, animated: true, completion: nil)

    }

 

    func checkPaymentStatus(){

        if UserDefaults.standard.value(forKey: "pt_response_code") as? String ?? "0" == "0"{

             // Payment Failed

            showAlert(message:"Payment Failed")

        }

        else{

            // Payment Success

            self.responseCode = UserDefaults.standard.value(forKey: "pt_response_code") as! String

            self.transactionId = UserDefaults.standard.value(forKey: "pt_transaction_id") as! String

           // Update your server for the successful payment

        }

    }

 

    func showAlert(message:String){

        let errorAlert = UIAlertController(title: "", message:message, preferredStyle: .alert)

        let noBtn = UIAlertAction(title: "ok", style: .default, handler: {(_ action: UIAlertAction) -> Void in

             CheckoutShippingMethod.orderData = ""

            self.continue2Btn()

        })

        errorAlert.addAction(noBtn)

        self.parent!.present(errorAlert, animated: true, completion: { _ in })

    }

7. Call the function callPaytabPaymentGateway() into the exploit of your payment button.

8. Once the successful or unsuccessful transaction PayTabs stores the transaction id and response code into your UserDefaults. To ensure the  payment status call checkPaymentStatus() function into your payment ViewController’s viewWillAppear function.

9. At last you have successfully executed the PayTabs Payment Gateway in your iOS application.

Important Note:-

  • PayTabs SDK does’t support XCode simulator.
  • You want to disable bitcode from build settings of your project ambition.

 

Last Update: December 21, 2018  

December 19, 2018   12   Nandini R    Swift-iOS    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Google+
https://www.webnexs.com/blog/kb/how-use-paytabs-payment-gateway-ios-application
Twitter
LinkedIn