iosobjective-cswiftpayment-gatewaypaytm

PayTM All-In-One SDK payment stuck on processing and delegates are not getting called


I was trying to integrate Paytm payment sdk using the All-In-One SDK they provides. I was using the SDK based integration . But after payment is done, it gets stuck on a page with "Processing Payment" text. Even if the payment is done, it is not calling the didFinish delegate function. This issue only occurs when the payment is done using openPaymentWebVC, if we use paytm app directly everything works fine.

self.handler.openPaytm(merchantId: PayTmKeys.mId, orderId: payTmOrderId, txnToken: payTmTxnToken, amount:strPayment, callbackUrl: PayTmKeys.verifyUrl+self.payTmOrderId, delegate: self, environment: .production)

The delegate functions are as follows.

extension CAPaymentGatewayViewController: AIDelegate {
    
    func openPaymentWebVC(_ controller: UIViewController?) {

        if let vc = controller {                
            DispatchQueue.main.async {[weak self] in
                self?.present(vc, animated: true, completion: nil)
            }
        }
    }
    
    
    
    
    func didFinish(with status: AIPaymentStatus, response: [String : Any]) {
        print("Response: \(response)")
    }
}

The callback URL used is

https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=payTmOrderId


Solution

  • I have tried a lot to get a proper solution for this, but didnt get any. However I found a workaround solution.

    First I looped through the paytm viewcontroller's subview to get the WKWebview and added an observer to know the url change in webview.

    func openPaymentWebVC(_ controller: UIViewController?) {
            if let vc = controller {
                paytmPaymentController = vc
                DispatchQueue.main.async {[weak self] in
                    self?.present(vc, animated: true, completion: {
                        print(" super view type: \(type(of: vc.view))")
                        vc.view.loopViewHierarchy { (view, stop) in
                            if view is WKWebView {
                                /// use the view
                                print("This view is WKWebview")
                                if let wkview = view as? WKWebView {
                                    print("Entered in column")
                                    
                                    wkview.addObserver(self!, forKeyPath: "URL", options: .new, context: nil)
                                }
                                stop = true
                            }
                        }
                    })
                }
            }
        }
    

    It will get called whenever the url changed in paytm webview. When I get the callback url(processing screen), I dismiss the paytm viewcontroller.

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
            if let key = change?[NSKeyValueChangeKey.newKey] as? NSURL {
                print(type(of: key))
                print("observeValue \(key)") // url value
                if key.absoluteString == "https://merchant.com/callback" {
                    paytmPaymentController?.dismiss(animated: true, completion: nil)
                }
            }
        }
    

    The next step is to verify the payment status using api from your backend using this api