我试图使用他们提供的All-In-One sdk集成Paytm支付sdk。我使用的是基于SDK的集成。但在付款完成后,它被卡在一个页面上,上面写着";处理付款";文本即使付款完成,它也不会调用didFinish
委托函数。只有当使用openPaymentWebVC
进行支付时才会出现此问题,如果我们直接使用paytm应用程序,一切都会正常工作。
self.handler.openPaytm(merchantId: PayTmKeys.mId, orderId: payTmOrderId, txnToken: payTmTxnToken, amount:strPayment, callbackUrl: PayTmKeys.verifyUrl+self.payTmOrderId, delegate: self, environment: .production)
委派功能如下。
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)")
}
}
使用的回调URL是
https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=payTmOrderId
请确保您在生成txn令牌时在initiate transaction API中发送回调url。
我已经尝试了很多,但都没有找到合适的解决方案。然而,我找到了一个变通的解决方案。
首先,我循环浏览paytm视图控制器的子视图以获得WKWebview,并添加了一个观察者来了解webview中的url更改。
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
}
}
})
}
}
}
每当paytm网络视图中的url发生更改时,就会调用它。当我得到回调url(处理屏幕(时,我会关闭paytm视图控制器。
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)
}
}
}
下一步是使用此api 从后端使用api验证支付状态