Paytm Integration in iOS Swift

Posted By : Varun Wadhwa | 25-Dec-2016

Paytm Integration iOS Swift

 

Before integration we must have mid , website and retail which are provided by Paytm at time of Merchant signup process.


Steps to integrate Paytm:  

Step 1.  Add Paytm target header in Bridging-Header file of your project.

 

#import "PaymentsSDK.h

 

Step 2.  In the ViewController from where have to do payment implement protocol  PGTransactionDelegate  , we have to implement four delegate methods for PGTransactionDelegate.

 

    // MARK: Delegate methods.
   
   // On Successful Payment
    func didSucceedTransaction(controller: PGTransactionViewController, response: [NSObject : AnyObject]) {              
        print(response)
        print("Deducted amount :Rs. \(response["TXNAMOUNT"]!)")
        self.removeController(controller) 
    }
    
    // On Failure
    func didFailTransaction(controller: PGTransactionViewController, error: NSError, response: [NSObject : AnyObject]) {
        print(response)
        if response.count == 0 {
            print(response.description)
        }
        else if error != 0 {
           print(error.localizedDescription)
        }
        self.removeController(controller)
    }
    
    //On Cancellation
    func didCancelTransaction(controller: PGTransactionViewController, error: NSError, response: [NSObject : AnyObject]) {
        print("Transaction has been Cancelled")
        self.removeController(controller)     
    }
    
    func didFinishCASTransaction(controller: PGTransactionViewController, response: [NSObject : AnyObject]) {  
        print(response);    
    }

Step 3:  Create  merchant config object.

 

let merchantConfig = PGMerchantConfiguration.defaultConfiguration();

 

Step 4: Set checksum genration and validation urls which will be configured on Backend Server. 

 

merchantConfig.checksumGenerationURL = "CheckSum_Genration_URL"
merchantConfig.checksumValidationURL = "CheckSum_Validation_URL"

 

Step 5:  Prepare the parameters of order , Make sure the orderId must be unique so its good practice if order id , customer id  is provided by your backend server.  

 

var odrDict: [NSObject : AnyObject] = NSMutableDictionary() as [NSObject : AnyObject]
       
       odrDict["MID"] = "MID"
       odrDict["CHANNEL_ID"] = "WAP"
       odrDict["INDUSTRY_TYPE_ID"] = "Retail"
       odrDict["WEBSITE"] = "Website"
       odrDict["TXN_AMOUNT"] = "100"
       odrDict["ORDER_ID"] = "Random_Number"
       odrDict["REQUEST_TYPE"] = "DEFAULT"
       odrDict["CUST_ID"] = "1234567890"
       let order: PGOrder = PGOrder(params: odrDict)

 

Step 6: Select the PG server type . eServerTypeProduction for production and eServerTypeStaging for testing on Staging server 

 

let transactionController = PGTransactionViewController.init(transactionForOrder: order)
transactionController .serverType = eServerTypeStaging 
transactionController .merchant = merchantConfig
transactionController .delegate = self
self.showController(transactionController)

THANKS

About Author

Author Image
Varun Wadhwa

Varun is a mobile developer with experience in various technologies like Titanium , Cordova and native iOS development.

Request for Proposal

Name is required

Comment is required

Sending message..