Ad Code

Responsive Advertisement

Xamarin Forms PayUMoney Integration




Introduction

    Today, we are going to see how to integrate the PayUMoney Payment Gateway with Xamarin.Forms Application. I did this payment gateway using WebView and custom renderer, am not using any PayUMoney SDK. In Xamarin Forms WebView default HTTP method is GET. But here I write code for WebView renderer and changing the HTTP method GET into POST and passing an encoded string from shared to platform-specific and added this string as the Body of the POST method. My experience if parsing the Native PayU SKD to Xamarin Library, it has difficult and there is no support from the PayUMoney team. I think the story is enough. I don't like to tell a lot of stories, let go for action in code.

Let's Go
    Open Visual Studio and Create a new Empty Xamarin Forms Project. For creating an app, go to Visual Studio >> File >> Project >> Xamarin Forms app  and click create a new project. In the dialog window, give the app name, solution name, location and create it.



    After the project creation, create a new class named as PayWebView and it should be inherited from WebView and create new properties PostData and url, you code must be like below. 





Now design UI, open MianPage.xaml and add the namespace of PayWebView class, we created in the last step and add PayWebView control in UI. This page code is given below.



Next, open MainPage.xaml.cs file and create multiple variables like amount, mail id, product info, name, success url and failure url. If payment is success  it will redirect to success url or else goes to failure url, then only you will know the payment status in WebView. The code is given here.



It's time to go for platform-specific, just expand the android project and create new class named as PayWebView class. Get the control and set the post url and postData from the PayWebView variables we created in first. This code is given below.



Next, expand iOS project, and get the Native control and create NSMutualUrlRequest and set the url and data and Http method is POST, then call LoadRequest method.




Finally, we have done all the things, now rebuild and run the application, you will get output like below.



Source Code in GitHub

Conclusion
I hope you guys, this article will helps you, thanks for reading.


Reactions

Post a Comment

4 Comments

  1. Nice Post, CnX Player offers a fantastic Video Casting feature that gives an absolute freedom to all its users to cast ANY (literally ANY) video format and ANY video codec from PC to TV within a fraction of seconds! It is a Best Media Player.

    Features @ CnX Player - Best Media Player

    * Stream ANY video from PC to Chromecast
    * Cast ALL Videos From PC To All Smart TV
    * Stream ANY video from PC to Chromecast
    * Cast Videos from iPhone iPad to Firestick TV
    * Stream any videos from PC to MI TV
    * Cast ALL Videos from PC to Android TV
    * Stream ANY Video From PC To SAMSUNG TV

    For more information visit our website at Best Media Player - CnX Player

    ReplyDelete
  2. Nice Post, CnX Player offers a fantastic Video Casting feature that gives an absolute freedom to all its users to cast ANY (literally ANY) video format and ANY video codec from PC to TV within a fraction of seconds! It is a Best Media Player.

    Features @ CnX Player - Best Media Player

    * Stream ANY video from PC to Chromecast
    * Cast ALL Videos From PC To All Smart TV
    * Stream ANY video from PC to Chromecast
    * Cast Videos from iPhone iPad to Firestick TV
    * Stream any videos from PC to MI TV
    * Cast ALL Videos from PC to Android TV
    * Stream ANY Video From PC To SAMSUNG TV

    For more information visit our website at Best Media Player - CnX Player

    ReplyDelete
  3. Nice post, when i implement same code in xamarin forms i am facing the the below issue.

    Transaction failed due to incorrectly calculated hash parameter.

    Please help me bro. Thanks in advance.

    SORRY!
    We were unable to process your payment
    Error Reason
    Transaction failed due to incorrectly calculated hash parameter.

    Corrective Action
    Please ensure that the hash used in transaction request is calculated using the correct formula. Please note the correct formula for calculating the value of hash:
    sha512(key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5||||||SALT)

    Based on above formula and applying for this transaction, hash should be calculated as mentioned below :
    hash = sha512(gtKFFx|TXNE43CB0725D4202BDAE8B|100|test|Logesh palani|logesh@hakunamatata.in|||||||||||wia56q6O) = {"v1":"1c977f928ebfba169ff6fab50cb86a471b837745ff32e5ec6621d9040b5279f387e4b9b102d2c5a44f3578e26edca841cb102ec1f0a134172422eec3e63a0335","v2":"61d980fddcf538fcbb142b974c5f95d4419d435007442f5a8fb0062379a310be3e32c6f1208650b5d36e8324f23bc2aab6655bda2a99aac2fc02e01abd25d318"}

    As seen above, correct hash value should have been - {"v1":"1c977f928ebfba169ff6fab50cb86a471b837745ff32e5ec6621d9040b5279f387e4b9b102d2c5a44f3578e26edca841cb102ec1f0a134172422eec3e63a0335","v2":"61d980fddcf538fcbb142b974c5f95d4419d435007442f5a8fb0062379a310be3e32c6f1208650b5d36e8324f23bc2aab6655bda2a99aac2fc02e01abd25d318"}

    But the hash posted in the transaction request from your end was - f9d127eef56794512cc33eb2de0a36142b68f3a79f67233b4b9ba011356dc46a76d7b5789c2cb8e0b78c5602405ff945bd2f651262898b8e666b43325a216165

    Please re-initiate a transaction with correctly calculated hash value.
    © 2021 PayUBiz. All rights reserved.

    ReplyDelete
  4. Hi Logesh, Thanks for the nice idea, in this way using Web view how to get the payment response, once success the payment i want to get the response data, can you please give me sample code. Thanks

    ReplyDelete

You're comment here