Note: Get the latest Paytm All-in-one SDK for iOS here.
Step 1: Call openPaytm method with following mandatory parameters
AIHandler().openPaytm(merchantId: merchantId, orderId: orderId, txnToken: token, amount: amount, callbackUrl : callback_url, delegate: self)
Delegate is a type of AIDelegate which have 2 protocols.
public protocol AIDelegate {
func openPaymentWebVC(_ controller: UIViewController?)
func didFinish(with status: PaymentStatus, response: [String:Any])
}
STEP 2: In Case Paytm App is not installed, redirect user to Paytm hosted Checkout Page
- In case Paytm app does not exist then user has to implement delegate methods of AIDelegate. openPaymentWebVC will provide the merchant the controller to present/push which handles the paytm hosted checkout page as described below.
/ MARK: - AIDelegate
extension ViewController: AIDelegate {
func openPaymentWebVC(_ controller: UIViewController?) {
if let vc = controller {
DispatchQueue.main.async {[weak self] in
self?.present(vc, animated: true, completion: nil)
}
}
}
}
AIHandler().openPaytmSubscription(merchantId: String, orderId: String, txnToken: String, amount: String, callbackUrl: String?, delegate: AIDelegate)
Step 3 : In case merchant don’t have callback URL, Add an entry into Info.plist LSApplicationQueriesSchemes(Array) Item 0 (String)-> paytm
- Add a URL Scheme “paytm”+”MID”
- Define the app delegate method to handle Paytm response. Client will get the response in Appdelegate Method.
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let dict = separateDeeplinkParamsIn(url: url.absoluteString, byRemovingParams: nil)
//get paytm params from dictionary
return true
}