Search code examples
c#asp.net-mvchttp-redirectrealex-payments-api

Realex MVC Solution (Redirect method)


I have a solution that I built using Webforms that passes over approximately 10 fields to the Realex payments processor server (I use the redirect method), and all works fine there. I'm brand new to MVC and am trying to put in place the same functionality using MVC as I currently have set up with Webforms. With my Webforms solution, I use a buttonclick event handler and a Postback URL, to gather the data I need to pass to Realex and the URL is managed in the Postback.

Using MVC, I don't seem to have the use of an event handler or a Postback URL declaration, or if I do, I can only post back to the form, whereas I need to post my data to an external website.

So in my MVC controller, I have hardcoded in the values (for testing purposes), that I am trying to pass to Realex.

The last line above (return Redirect), is bringing me to the Realex page (it is not letting me see the boxes though for entering credit card details, instead it is returning a 506 error saying "Invalid MerchantID or account number)...

I've been onto Realex and they are telling me that they can see the data above that I'm trying to pass to their server, like my account ID, my order reference, etc.

I've also tried doing it this way within my View, just to get this to post properly:

    <input id="ORDER_ID" name="ORDER_ID" type="hidden" value="6264286038162642860381" />
    <input id="ACCOUNT" name="ACCOUNT" type="hidden" value="XXXXXXXXX" />
    <input id="AMOUNT" name="AMOUNT" type="hidden" value="100" />

/>

But I don't know how to hook up my form fields with my controller, I know I'm still thinking "Webforms" here, and am just not thinking MVC, because I've so little experience with MVC and am finding the transition to MVC more difficult than I though.

Thanks in advance for any help with this...


Solution

  • I think you want something like this, I'm sure there's a more elegant solution but this should work.

     public ActionResult ShoppingCart(decimal _TotalPriceBox = 1)
     {
        //After populating your shopping cart model
    
        ViewBag.MerchantId = My_Cart.MYUSERIDSTRING;
        ViewBag.Account = My_Cart.ACCOUNT;
        ViewBag.OrderId = My_Cart.ORDER_ID;
        ViewBag.Amount = My_Cart.AMOUNT;
        //Rest of needed properties
        return View()
      }
    

    Then in the form inside your view

    <form action="https://epage.payandshop.com/epage.cgi" method="post">
      <input id="ORDER_ID" name="ORDER_ID" type="hidden" value="@ViewBag.OrderId" />
      <input id="ACCOUNT" name="ACCOUNT" type="hidden" value="@ViewBag.Account" />
      <input id="AMOUNT" name="AMOUNT" type="hidden" value="@ViewBag.Amount" />
      //Rest of inputs needed
      <input type="submit" value="send" />
     </form>