Hi guys, today we will learn about how to implement SSLCOMMERZ payment gateway in an iOS application.
Before starting to code first we need to know what a payment gateway is
A payment gateway is a merchant service provided by an e-commerce application service provider that authorizes credit card or direct payments processing for e-businesses, online retailers, bricks, and clicks, or traditional brick and mortar.
Thus, its enough for us now. Let’s start by following the instructions below.
STEPS TO INTEGRATE
->Download & Unzip
Step 1: Go to this link https://developer.sslcommerz.com/registration/ and register.
Step 2: Login account with https://sandbox.sslcommerz.com/manage/
Step 3: Go to console and click the developer tab. you can now download iOS SDK file. Now follow the steps.
->Installation Procedure
- Unzip the SSLCOMMERZ_iOS_SDK file.
- Locate the ‘Universal’ Folder.
- Copy and paste the ‘Universal’ Folder inside your project Directory.
- Drag and Drop all files from the copied folder to your Xcode Project.
- If the swift project has an Objective-C Bridging Header, Skip this step. Otherwise, Create a .h file named ProjectName-Bridging-Header.h Make sure to put it in the project directory
- Go to Target->Build Settings. Search For Swift compiler and go to the section Swift Compiler –General
- Double click the Objective-C bridging Header and add the path for the ProjectName-Bridging-Header.h file.
- Go to Target->Build Settings. Search For Library Search Path and add the path for the LibECommerz.a (Make sure the directory search path is selected as ‘recursive’)
Example
$(PROJECT_DIR)/Project_NAME/SSLCOMMERZ_Sdk_iOS\ 1.0.5/Universal
Note:
- The library is written in Obj-C. Swift Installation and usage guide are also added with SDK.
- Test projects for Both Swift and Obj-C are added to the Zip file.
- Please note that all amount values should have 2 digits after the decimal. If the amount is 42 BDT, the amount that should go in the amount parameter will be @”42.00”
->Now Add The Below Code In Your Payment Controller.
- Include SSLCommerzDelegate in your Swift class
1ViewController: UIViewController , SSLCommerzDelegate { - Create a reference of SSLCommerz in the class.
1var SDKObject : SSLCommerz? - Initialize the Object and set a delegate
12SDKObject = SSLCommerz()SDKObject?.delegate = self - For Payment, Call the following Function With required Parameters
12345678910111213SDKObject?.startSSLCOMMERZinViewController(self, withStoreID: "testbox",storePassword: "qwerty", amountToPay: "10.00", amountCurrency: "BDT",applicationBundleID: "com.sslWireless.SSLCommerzSDKTest", appTransactionID:"TRANX ID", sourceDetail: "DETAIL", withCustomerEmail: "EMAIL",customerName: "NAME", customerContactNumber: "CONTACT", customerFax: "",customerAddress1: "ADDRESS", customerAddress2: "ADDRESS 2", customerCity:"CITY", customerState: "STATE", customerPostCode: "POSTCODE",customerCountry: "COUNTRY", withShipmentInfo: "INFO", shipmentAddress1:"ADDRESS", shipmentAddress2: "ADDRESS LINE 2", shipmentCity: "CITY",shipmentState: "STATE", sHipmentPostCode: "POSTCODE", shipmentCountry:"COUNTRY", withOptionalValueA: "Optional value", optionalValueB:" Optional value ", optionalValueC: " Optional value ", optionalValueD:" Optional value ", shouldRunInTestMode: true) - Add The following Delegate function to the class and check transaction status.
12345func transactionSuccessful(withCompletionhandler transactionData: TransactionDetails!){if(transactionData != nil){print(transactionData.status, transactionData.sessionkey,transactionData.bank_tran_id,transactionData.amount, transactionData.card_type, transactionData.tran_date)}}
Note:- Please follow the above step for integrating the SSLCOMMERZ payment gateway in your application if you fill any issue pls comment on the comment section.