Paytm Integration in Swift

This blog is about how to integrate Paytm with the iOS App.

Steps to integrate paytm via SDK

1. Import the library :

A library can be imported by two process :

a) Via pods

  • Add pod ‘Paytm-Payments’ in the pod file.
  • Run ‘pod install’ from terminal.
  • Now open the xcworkspace
  • Go to “Link Binary With Libraries” in the “Build Phases” in the project settings, and add SystemConfiguration.framework
  • Now Check if PaytmSDK.framework is added in both “Link Binary With Libraries” and “Embedded Binaries”. If not, add by clicking on the plus icon

b) Via direct add library to the project

  • Download SDK from the https://github.com/Paytm-Payments/Paytm_iOS_App_Kit/tree/master/Swift
  • Add Paytm.framework to the project
  • Go to “Link Binary With Libraries” in the “Build Phases” in the project settings, and add SystemConfiguration.framework
  • Now Check if PaytmSDK.framework is added in both “Link Binary With Libraries” and “Embedded Binaries”. If not, add by clicking on the plus icon

2. Add PaytmSDK to ViewController

3. Generate Checksum

Checksumhash is a unique id used by the paytm to ensured that the transaction has not been tempered. Checksumhash has been generated from serverside.

4. Start the payment process

A transaction can be done via the following process

  1. Firstly choose the paytm server based on the environment. For Staging Create an instance of the  PGServerEnvironment and set the serverType to eServerTypeStaging. For Production Create an instance of the  PGServerEnvironment and set the serverType to eServerTypeProduction.
  2. Now create the PGOrder instance with all the parameters.
  3. Create the PGTransactionViewController instance by calling initTransactionForOrder and pass the instance of PGOrder as a parameter.

5. Implement protocol  ‘PGTransactionDelegate’ 

Implement protocol  ‘PGTransactionDelegate’ to the viewcontroller from where have to do payment

6. Verify checksum

Checksumhash needs to be verified so that response have not been tampered. Verification is done on the server side.

Leave a Reply