问题描述
在Razorpay的测试和实时模式下,成功方法仅获得payment_id
。我无法获得razorpay_signature
和razorpay_order_id
。
我已经使用RazorpayPaymentCompletionProtocolWithData
委托来获取结果。
这是我的代码:
extension ViewController: RazorpayPaymentCompletionProtocolWithData {
func openRazorpayCheckout(){
//Register RazorpayTestKey
razorpay = RazorpayCheckout.initWithKey(kRazorpayLiveKey,andDelegateWithData: self)
let options: [String:Any] = [
"description": ServerConfig.shared.businessDescription!,"order_id": viewmodel.model.orderID!,"image": ServerConfig.shared.businessImage!,"name": ServerConfig.shared.businessName!,"prefill": [
"contact": LoggedInUser.shared.phoneNumber!,"email": LoggedInUser.shared.email!
]
]
if let rzp = razorpay {
rzp.open(options)
} else {
print("Unable to initialize")
}
}
func onPaymentError(_ code: Int32,description str: String,andData response: [AnyHashable : Any]?) {
_ = response!["razorpay_payment_id"]
_ = response!["razorpay_order_id"]
_ = response!["razorpay_signature"]
}
func onPaymentSuccess(_ payment_id: String,andData response: [AnyHashable : Any]?) {
_ = response!["razorpay_payment_id"]
_ = response!["razorpay_order_id"]
_ = response!["razorpay_signature"]
}
}
解决方法
如果您没有签名,则表明您的订单ID可能是错误的,请交叉检查您的订单ID。我在android中犯了同样的错误。我没有传递导致空签名的订单ID。
,通过回复拯救了我的一天:
如果您没有得到签名,则意味着您的订单 ID 可能有误,请交叉检查您的订单 ID。我在android中犯了同样的错误。我没有传递导致空签名的订单 ID。
请传递正确的订单 ID。那你可以试试。您需要将 andDelegate 更改为 andDelegateWithData
// razorpay = RazorpayCheckout.initWithKey(razorpayTestKey,andDelegate: self)
razorpay = RazorpayCheckout.initWithKey("razorpayTestKey",andDelegateWithData: self)
Then Use RazorpayPaymentCompletionProtocolWithData:
扩展视图控制器:RazorpayPaymentCompletionProtocolWithData {
func onPaymentError(_ code: Int32,description str: String,andData response: [AnyHashable : Any]?) {
print("error: ",code)
// self.presentAlert(withTitle: "Alert",message: str)
}
func onPaymentSuccess(_ payment_id: String,andData response: [AnyHashable : Any]?) {
print("success: ",payment_id)
print("Response is: ",(String(describing: response)))
let paymentId = response?["razorpay_payment_id"] as! String
let rezorSignature = response?["razorpay_signature"] as! String
print("rezorSignature",rezorSignature)
print(" paymentId",paymentId)
//self.presentAlert(withTitle: "Success",message: "Payment Succeeded")
}
}