fend
fend

Reputation: 21

Razorpay Signature and Order ID are not getting in success method of onPaymentSuccess

In test and live mode of Razorpay, I am only getting the payment_id in the success method. I am unable to get razorpay_signature and razorpay_order_id.

I have used the RazorpayPaymentCompletionProtocolWithData delegate to get my result.

Here is my code:

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"]
}
}

Upvotes: 2

Views: 4150

Answers (2)

user15007566
user15007566

Reputation: 71

Saved my day with the response:

If you don't get signature than it means your order id can be wrong, cross check your order id. I made the same mistake in android. I was not passing the order id which leads to empty signature.

Do pass the correct order id. Then you can try. you need to change andDelegate to andDelegateWithData

// razorpay = RazorpayCheckout.initWithKey(razorpayTestKey, andDelegate: self)
razorpay = RazorpayCheckout.initWithKey("razorpayTestKey", andDelegateWithData: self)


Then Use RazorpayPaymentCompletionProtocolWithData: 

extension ViewController: 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")
}

}

Upvotes: 3

Meet Thanki
Meet Thanki

Reputation: 71

if you don't get signature than it means your order id can be wrong, cross check your order id. I made the same mistake in android. i was not passing the order id which leads to empty signature.

Upvotes: 4

Related Questions