razorpay / razorpay-pod

:iphone: CocoaPod implementation of Razorpay's Payment SDK. Refer for instructions:
https://docs.razorpay.com/v1/page/ios-integration
MIT License
21 stars 18 forks source link

RazorpayPaymentCompletionProtocolWithData Methods - onPaymentSuccess doesn't gets called #110

Closed Karthikmoback closed 3 years ago

Karthikmoback commented 3 years ago

I have integrated Razorpay SDK using cocoapod for IOS app - pod 'razorpay-pod', '1.1.6' , also tried with 1.1.7 with swift 5.1+ and Xcode 11.6.

Using RazorpayPaymentCompletionProtocolWithData I am able to make the payment and on click on success, the view gets dismissed, But below method doesn't gets called func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?)

whereas if i use RazorpayPaymentCompletionProtocol func onPaymentSuccess(_ payment_id: String) - works fine to get payment id But i need order id and signature to verify the transaction.

Here is my code

extension HTCourseInfoViewController: RazorpayPaymentCompletionProtocolWithData {
    func onPaymentError(_ code: Int32, description str: String, andData response: [AnyHashable : Any]?) {
        print("Payment failed with code: \(code), msg: \(str)")
    }

    func onPaymentSuccess(_ payment_id: String, andData response: [AnyHashable : Any]?) {
         print("Payment Success payment id: \(payment_id), andData: \(String(describing: response))")
    }

    func showPaymentFormForStandalone(orderInfo:HTCreateOrder){

        // Razorpay
        let razorpayKey = "<MYTestKeyUsed>"

        let razorpay = RazorpayCheckout.initWithKey(razorpayKey, andDelegate: self)
                let options: [String:Any] = [
                            "amount": Int(orderInfo.amount ?? "0")!, //This is in currency subunits. 100 = 100 paise= INR 1.
//                            "key_id":orderInfo.keyID!,
                            "currency": "INR",//We support more that 92 international currencies.
                            "notes": [
                              "shipping address": orderInfo.transactionInfo
                            ],
                            "name": orderInfo.companyName ?? "",
                            "prefill": [
                                "name": orderInfo.name,
                                "email": orderInfo.email,
                                "contact": orderInfo.phone
                            ],
                            "description": orderInfo.companyDescription ?? "",
                            "order_id": orderInfo.orderID!,
                            "image": orderInfo.companyLogo ?? "",
                            "theme": [
                                "color": "#F37254"
                            ]
                        ]

                razorpay.open(options)
        }
}

Here is the console logs, when razorpay screen closes /Users/sachinnautiyal/Documents/Razorpay/razorpay-ios/RazorpayIOS/CheckoutOtpelf/Classes/RazorpayCheckoutVC.swift deinitialized /Users/sachinnautiyal/Documents/Razorpay/razorpay-ios/RazorpayIOS/CheckoutOtpelf/Classes/RazorpayCheckoutWebView.swift:["/Users/sachinnautiyal/Documents/Razorpay/razorpay-ios/RazorpayIOS/CheckoutOtpelf/Classes/RazorpayCheckoutWebView.swift deinitialized"] 2020-10-13 16:57:01.345088+0530 MyApp[2153:1184634] [ProcessSuspension] 0x1146e2190 - ProcessAssertion::processAssertionWasInvalidated() 2020-10-13 16:57:01.350226+0530 MyApp[2153:1184634] [ProcessSuspension] 0x1146e21f0 - ProcessAssertion::processAssertionWasInvalidated()

Sumit738 commented 3 years ago

Please refer to the link- https://razorpay.com/docs/payment-gateway/ios-integration/standard/#step-5-handle-success-and-errors-events

Karthikmoback commented 3 years ago

@Sumit738 I have referred the same link, as i mentioned, i was able to get the payment id when i use RazorpayPaymentCompletionProtocol public func onPaymentSuccess(_ paymentid: String) But i need order id and signature. Which i can get by using (as per doc link) RazorpayPaymentCompletionProtocolWithData func onPaymentSuccess( payment_id: String, andData response: [AnyHashable : Any]?) , But this method is not getting called.

Nautiyalsachin commented 3 years ago

Hey @Karthikmoback, we have two initialising methods,

  1. RazorpayCheckout.initWithKey(razorpayKey, andDelegate: self)

  2. RazorpayCheckout.initWithKey(razorpayKey, andDelegateWithData: self)

If you use the second option then you will be able to invoke the data delegate functions.

Karthikmoback commented 3 years ago

@Nautiyalsachin Thanks that worked.