Payment gateway integration in Xamarin Form .Net MAUI using RazorPay

Brief: In this post we can see how to integrate payment gateway using RazorPay in Xamarin form for iOS and Android.




Description: 

Right now i'm seeing very limited support for Xamarin with payment SDK from the top payment gateway providers like Stripe,RazorPay,PayU,JustPay. Few are providing the SDK but that is outdated and not supporting in the latest version. 

Even RazorPay does not support with any SDK for Xamarin but we can use binding library created on top of native SDK, but for iOS even binding library doesn't work so alternate approach here taken is Webview based payment with proper callbacks.

 User interface output is very identical for Webview and SDK based payment, but few options looks like restricted in webview as there is some restrictions for opening popup from iOS WKWebview, more details in razor pay document page.

Need to be cautious with webview based payment as it has certain limitation like Netbanking is not supported as it tries to open view window which is not supported inside webview. So the Netbanking option is hidden in the below example.

Before getting started need to create Razorpay_key and Razorpay_password from razor pay dashboard.

Code:

Add new Content page for Webview in common project and create CustomRenderer for the same.

 

Implement Custom renderer for iOS:

Android Custom renderer:

For Android i prefer the razorpay SDK created by using binding library. Still we can use the webview based implementation for Android in similar way as we did for iOS. We can follow this below link for reference:

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview

https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/webview/


RazorPay sdk based payment:

Download the binding project created for RazorPay SDK in Xamarin.Android using link RazorPayAndroidBindingLibrary.

Build the binding project and create the dll's and the project reference for your project.

Create the dependency service for the pay button click event and follow the below code.


Conclusion: This is the walkthrough for the payment integration using webview for Xamarin.iOS as there is no clear alternate available for iOS using SDK and for Android binding project based SDK. 

Follow the CodeLog FB page for all the updates and Keep supporting, Happy coding!!!. 


No comments:

Post a Comment