How to pass custom data via PayPal IPN - c#

I use following code for the RETURN URL.
#foreach (var item in Model)
{
<form action='#item.PayPalURL2 ' method='post'>
<input type='hidden' name='cmd' value='_xclick' />
<input type='hidden' name='business' value='#item.BusinessEmail' />
<input name='item_name' value='#item.Name' class="ppField" readonly="readonly"/>
<input type='hidden' name='item_number' value='#item.ID' />
<input name='amount' value='#item.Price2' class="ppField" readonly="readonly"/>
<input type='hidden' name='return' value='#item.ReturnURL' />
<input type='hidden' name='custom' value='#item.UserID' />
<input type='submit' value='Buy' />
</form>
}
Any clue how to pass custom filed to IPN message and get it via Listener?
Thank you!!!

You've already got the "custom" field included in your form. Whatever value you have in #item.UserID will be getting sent along with the payment and will come back as a POST value called "custom" within your IPN solution.
So, it looks like you're already got what you need. You just need to make sure $item.UserID actually contains what you expect it to contain, and that you're looking for the custom field in your IPN listener.

Related

Paypal Return URL is not triggering properly

Our website has following one time payment buttons.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="custom" value="#Model.UserId.ToString()">
<input type="hidden" name="notify_url" value="http://www.testweb.com/paypal/IpnHandler">
<input type="hidden" name="return" value="http://www.testweb.com/paypal/Onetimeyearlysuccess">
<input type="hidden" name="cancel_return" value="http://www.testweb.com/paypal/cancel">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="8xxxxxxC">
<input type="image" src="#Url.Content("~/images/OneTime55year.png")" border="0" name="submit" style="width: 130px !important; height: 47px !important;" alt="PayPal - The safer, easier way to pay online!" >
</form>
After done the paypal payment, we could see we are getting 404 error.
The issue is that we are getting wrong URL.
https://www.testweb.com/PaypalOnetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
We don’t know why the slash missing after paypal.
The correct URL should be
https://www.testweb.com/Paypal/Onetimeyearlysuccess?amt=55.00&cc=USD&cm=22028&item_name=oneTimeAnnual55&st=Completed&tx=59M0424544743135Y
There needs to be slash symbol after paypal in the address URL.
You can see the correct URL from the return URL of the paypal button also.
Why it is redirecting to wrong address?
Also for testing purpose,we changed the return URL of the paypal button. We simply modified to “http://www.testweb.com/paypal/Onetimeyearlysuccesstest.”
But we could see after changed the return URL , paypal is not redirecting to modified URL.
Actually we are confused ,we need to know where the return URL is creating.
PayPal only recognize the value of 'return' variable. The key point is located at this URL (http://www.testweb.com/paypal/Onetimeyearlysuccess). You are advised to create a fixed single page without redirect function like .html, .php, .aspx, etc., to see the result.

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...
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>

Get input value on server side

I'm having some trouble and not sure what's going on.
I have a form with input value and want to be able to get that input value and send it back to my controller (server side).
My html code
<form action="/Home/Search" method="get">
<button class="search-btn-widget"></button>
<input class="search-field" id="sub" type="text" onblur="if(this.value=='')this.value='Search';" onfocus="if(this.value=='Search')this.value='';" value="Search" />
</form>
Then in my controller I have
string sub = Request["sub"];
However it ends up being null and not sure what's going on. Any ideas?
Just to make it work: add the name attribute
<input class="search-field" id="sub" name="sub" ...
but check this.
You need to add the name attribute to the input tag.
If you pull up the developer console and take a look at the HTTP GET request that is being sent, you will see that no query string is being associated with the request. This will let you know that the issue on the HTML side and not the ASP.Net MVC side.
Update input tag:
<input class="search-field" id="sub" name="sub" type="text" onblur="if(this.value=='')this.value='Search';" onfocus="if(this.value=='Search')this.value='';" value="Search" />
Update Controller Action to:
public ActionResult Search(string sub)
1) If you wanna see your input into the Request you must send your Form as POST:
<form action="/Home/Search" method="POST">
2) Make sure that input has a name:
<input class="search-field" id="sub" name="name"
type="text"
onblur="if(this.value=='')this.value='Search';"
onfocus="if(this.value=='Search')this.value='';"
value="Search" />
Then you will be able so see It in the request
You should add the name attribute to the input element.

How to send data from one page to another page with querystring and input form?

I am working in C#(asp.net). I have two pages 'abc.aspx' and 'xyz.aspx'. I want to send data from 'abc.aspx' to 'xyz.aspx'. I am using this code.
In 'abc.aspx'
<form action='xyz.aspx?site=google&code=123' method='get'>
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
Now, I want to access all three values (site,code and name1). But, in 'xyz.aspx', I got only one value i.e name1. How to get all three values.
You need to put the values into hidden <input /> elements and hard-code the values if you want to have them end up in the query string. You're correct in setting the method='get':
<form action='xyz.aspx' method='get'>
<input type='hidden' name='site' value='google' />
<input type='hidden' name='code' value='123' />
<input type='text' name='name1' />
<input type='submit' value='submit' />
</form>
I think this one is the best.
In abc.aspx
<form action="xyz.aspx?site=google" method="post">
<input type="text" name="name1" />
<input type="submit" value="Submit" />
</form>
In xyz.aspx, access the data like this..
string site = Request.QueryString["site"];
string name = Request.Form["name1"];
//Remaining code...

Submit a form that is saved in a string (ASP.NET)?

I have a HTML form a string variable.
e.g: there are below string in FormBody variable string.
<form id='paymentUTLfrm' action='...' method='post'>
<input type='hidden' name='CardAcqID' value='131211234234667' />
<input type='hidden' name='AmountTrans' value='1' />
<input type='hidden' name='ORDERID' value='1' />
<input type='hidden' name='TerminalID' value='1723429902234254' />
<input type='hidden' name='TimeStamp' value='1282408234231473657' />
<input type='hidden' name='FP' value='56-85-2E-A6-F4-4B-7F-AD-17-E1-D9-97-D5-40-62' />
<input type='hidden' name='RedirectURL' value='http://localhost:1903/Service1.asmx?op=MelliSale' />
<input type='hidden' name='MerchantAdditionalData' value='' />
<input type='hidden' name='Version' value='3.22' />
</form>
Now I wanna submit it via ASP.NET and C# !!!
Could you please guide me how I can do it ?
see this page
How to: Send Data Using the WebRequest Class
or do pablo answer
You need an HttpClient in C#. You can take a look at this MS support document with some help on how to do that or you can just use WebClient class.
With that Http Client, you will have to implement the POST HTTP command to send your data with application/x-www-form-urlencoded content type. That encoded data will contain each variable have in your string. To get their values, you will have to parse it.

Categories