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

RazorpayPaymentCompletionProtocol delegate not called #84

Closed AkshayNG closed 4 years ago

AkshayNG commented 4 years ago

Hi, I'm using RazorPay version 1.1.2 with cocoapods on Xcode 10.3.

The Code:

class RazorPayment: NSObject, RazorpayPaymentCompletionProtocol
{
private var razorpay: Razorpay!
.
init(withSomeParameters) { 
}
.
.
self.razorpay = Razorpay.initWithKey(self.apiKey, andDelegate: self)
let optinos = ...
self.razorpay.open(options)
.
.
func onPaymentError(_ code: Int32, description str: String) {
        ToastView.shared.show(message:"This is not called")
}

func onPaymentSuccess(_ payment_id: String)
{
       paymentSucessful()
}
.
}

I'm using test API key. The issue is in checkout, on clicking Success Or Error button the form is getting dismissed but the delegate functions are not being called. Also when we simply close, it dismisses the form/controller but the func onPaymentError not called at all. Whats going wrong with delegates ?

UPDATE

So now I moved my logic from helper class to actual viewcontroller, and delegates got called. The question now is why delegate not called inside for helper class(subclass of nsobject as in above code).

AkshayNG commented 4 years ago

I've managed to get this work with the help of UIViewController extension:

Neeraj204 commented 4 years ago

@AkshayNG I am also using the extension still not getting called.

extension CheckoutViewController: RazorpayPaymentCompletionProtocol {

    func onPaymentSuccess(_ payment_id: String) {}

    func onPaymentError(_ code: Int32, description str: String) {}
}

Any idea or help you can provide?

Getting this error when RazorPay payment screen dismissed:

/Users/travis/build/razorpay/razorpay-ios/RazorpayIOS/CheckoutOtpelf/Classes/RazorpayCheckoutVC.swift deinitialized

Nautiyalsachin commented 4 years ago

@Neeraj204, please verify your passed parameters again. Also please verify your passing parameters.

Neeraj204 commented 4 years ago

@Nautiyalsachin All the parameters are ok it is problem of RazorpayPaymentCompletionProtocol which not being called with extension.

AkshayNG commented 4 years ago

@Neeraj204 Below is the extension I've implemented, working fine for me:

extension UIViewController: RazorpayPaymentCompletionProtocol
{
    func purchaseUsingRazorPay(price : Int)
    {
        . . .
        let rp = Razorpay.initWithKey(RazorPayment.apiKey, andDelegate: self)
        rp.open(opt)
    }

    public func onPaymentError(_ code: Int32, description str: String) {
        if code == 2 { return }
        ToastView.shared.show(message:str)
        RazorPayment.shared.clear()
    }

    public func onPaymentSuccess(_ payment_id: String)
    {
        RazorPayment.shared.paymentSucessful()
    }
}

So you can call purchaseUsingRazorPay() from any viewController.