When implementing Paypal I have managed to set it up to send a set value such as £25 however not a variable from the basket e.g. 'GrandTotal' which is dependent on what the customer has entered into the cart (I have created my own cart.)
<form action="paypal.com/cgi-bin/webscr"; method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="you#youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="amount" value="25.00">
<input type="image" src="paypal.com/en_US/i/btn/x-click-but01.gif"; name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form>
Do you know how to send the variable rather than a set amount? Is the code below anywhere near a solution?
<input type="hidden" name="amount" value="GrandTotal">
You cannot insert your form tag in ASP.Net page (unless iframe), because ASP.Net only allows one form tag in a page.
You want similar like this in code behind. It basically collect user entered Amount and Quantity, and then post it back to PayPal.
protected void PayButton_Click(object sender, EventArgs e) {
string paypalUrl = IsTestMode ?
"https://www.sandbox.paypal.com/us/cgi-bin/webscr" :
"https://www.paypal.com/us/cgi-bin/webscr";
var builder = new StringBuilder();
builder.Append(paypalUrl);
builder.AppendFormat("?cmd=_xclick&business={0}",
HttpUtility.UrlEncode(you#youremail.com));
builder.Append("&lc=US&no_note=0¤cy_code=GBP");
builder.AppendFormat("&item_name={0}",
HttpUtility.UrlEncode(YourItemName));
builder.AppendFormat("&amount={0}", AmountTextBox.Text);
builder.AppendFormat("&return={0}",
HttpUtility.UrlEncode("http://mysite.cm/ReturnUrl"));
builder.AppendFormat("&cancel_return={0}",
HttpUtility.UrlEncode("http://mysite.cm/CancelUrl"));
builder.AppendFormat("&undefined_quantity={0}", QuantityTextBox.Text);
HttpContext.Current.Response.Redirect(builder.ToString());
}
You can make input field server side by adding runat="server" in input field tag and can set it value from .cs file
field.value=GrandTotal;
Your aspx page code
<form name="_xclick" target="paypal" action="https://www.paypal.com/cgi-bin/webscr"
method="post" runat="server">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="you#youremail.com" />
<input type="hidden" name="item_name" value="Item Name" />
<input type="hidden" name="currency_code" value="GBP" />
<input type="hidden" name="amount" id="amount" runat="server" />
<input type="image" src="https://www.paypal.com/en_US/i/btn/view_cart.gif" border="0"
name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<input type="hidden" name="display" value="1">
</form>
Your code behind page code
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
amount.Value = "25.25";
}
}
Related
I have some code that i wrote many years ago to integrate Paypal within my site. So a user adds multiple products to their cart and then checks out which then automatically takes the user to the paypal site.
I decided to revisit it today and created the following HTML
<form name="myForm" method="POST" action="https://www.sandbox.paypal.com/cgi-bin/webscr" >
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value="myemail-facilitator#myDomain.com"/>
<input type="hidden" name="item_name" value="Product 1"/>
<input type="hidden" name="amount" value="500.00"/>
<input type="hidden" name="quantity" value="1"/>
<input type="hidden" name="upload" value="1"/>
<input type="hidden" name="currency_code" value="GBP"/>
<input type="hidden" name="return" value="http://XX/paypal/completed.aspx"/>
<input type="hidden" name="rm" value="2"/>
<input type="hidden" name="cancel_return" value="http://XX/paypal/Cancel.aspx"/>
<input type="hidden" name="shopping_url" value="http://XX/paypal/MyShop"/>
<input type="hidden" name="notify_url" value="http://XX/paypal/MyShop/checkout.aspx"/>
<input type="hidden" name="lc" value="GB"/>
<input type="hidden" name="image_url" value="http://XX/paypal/shop.gif"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="invoice" value="ZZZ1234567890"/>
<script type="text/javascript">document.myForm.submit();</script></form>
This came up with an error "Error Detected Your shopping cart is empty".
Logged into my sandbox account and no error listed to determine what ive done wrong.
Googled around which suggested to change _cart to _xclick - which resolved the issue, however when i read the documentation at
https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/
I dont understand why _cart didnt work? Is there a more appropriate way to do this or _xclick fine with my site setup as described above?
For multiple items i was looping the item_name and amount and adding each value, but this doesnt work the way i expected i.e. I've seen sites where they display each product, quantity and amount for each product in the cart and then total - where did i go wrong?
Finally once a transaction is complete i have set up the IPN value to send the details to my site..... Do i need the site to be using https in order for this to work or would http work?
I tried searching for these answers but some are quite dated or using 3rd part components.
Please make below changes to your HTML codes to make your form work again.
<input type="hidden" name="item_name" value="Product 1"/>
<input type="hidden" name="amount" value="500.00"/>
<input type="hidden" name="quantity" value="1"/>
↓↓
<input type="hidden" name="item_name_1" value="Product 1"/>
<input type="hidden" name="amount_1" value="500.00"/>
<input type="hidden" name="quantity_1" value="1"/>
Hello guys i have gatting issue on loading asp.net
i have using master page for sub pages there is a form tag in materpage i have add a paypal button in sub page which is this in master page form tag is also important
in masterpage <form id="form1" runat="server"></form>
and in sup age
<form id="form2" runat="server" name="Paypal" action="https://www.paypal.com/cgi-bin
/webscr"
method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="
<%=System.Web.Configuration.WebConfigurationManager.AppSettings["email"] %>
" />
<input type="hidden" name="item_name_1" value="<%=Session["ItemName"].ToString()%>"
/>
<input type="hidden" name="amount_1" value="<%=Session["ItemCost"].ToString() %>"/>
<input type="hidden" name="quantity_1" value="1" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value="<%=Session["returnUrl"].ToString() %>"/>
<input type="hidden" name="lc" value="Stronger" />
<input type="image" src="images/paynow.png" border="0" name="submit" alt="Make
payments with PayPal - it's fast, free and secure!"
style="background: url(images/update-account.png);"/>
</form>
I'm getting bug this with sub page below
Server Error in '/Project' Application.
A page can have only one server-side Form tag.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: A page can have only one server-side Form tag.
anybody have a idea how can i use form tag in sub page also.
Please check how many <form> tags are written on your aspx/html page. Make sure you are not using masterpage for this page.
Hi I have found this solution and its work solution is below:
<form name="Paypal" action="https://www.paypal.com/cgi-bin/webscr"
method="post" target="_blank"></form>
<form name="Paypal" action="https://www.paypal.com/cgi-bin/webscr"
method="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1" />
<input type="hidden" name="business" value="
<%=System.Web.Configuration.WebConfigurationManager.AppSettings["email"] %>
" />
<input type="hidden" name="item_name_1" value="<%=Session["ItemName"].ToString()%>"
/>
<input type="hidden" name="amount_1" value="<%=Session["ItemCost"].ToString() %>"/>
<input type="hidden" name="quantity_1" value="1" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="return" value="<%=Session["returnUrl"].ToString() %>"/>
<input type="hidden" name="lc" value="Stronger" />
<input type="image" src="images/paynow.png" border="0" name="submit" alt="Make
payments with PayPal - it's fast, free and secure!"
style="background: url(images/update-account.png);"/>
</form>
This code is working good as i want.
If you'are under a MasterPage Don't use the form tag as long as you're inside a form, just delete it, delete the hidden input that causes the SUBMIT and, instead, use the following ImageButton:
<asp:ImageButton ID="cmdpay" runat="server" PostBackUrl="https://www.paypal.com/cgi-bin/webscr" Text="" ImageUrl="images/paynow.png" ></asp:ImageButton>
It works
I am trying to incorporate a reservation widget within my wordpress install and I have everything working fine except sending the data or it not populating on the other sites form. The site I am trying to send data to is an online reservation software: http://www.directinn.com/demo/
Here is how I am doing my form:
<form name="bookingform" action="http://www.directinn.com/demo" method="get" target="_blank">
<input type="text" name="date1" id="Text1" class="ftxt MyDate three columns" maxlength="10" value="" placeholder="Arrival Date"/>
<input type="text" name="date2" id="Text2" class="ftxt MyDate three columns" maxlength="10" value="" placeholder="Departure Date" />
<input type="submit" name="bookingformsubmit" class="book-now" value="Book Now">
<input type="hidden" name="arrivalDay" value="" />
<input type="hidden" name="arrivalMonth" value="" />
<input type="hidden" name="arrivalYear" value="" />
<input type="hidden" name="departureDay" value="" />
<input type="hidden" name="departureMonth" value="" />
<input type="hidden" name="departureYear" value="" />
<input type="hidden" name="numAdults" value="1" />
Any help would be greatly appreciated ;)
So they are saying if you can iFrame in their Form on your page and if you add the USERNAME for example to the URL, your USERNAME will appear on the invoice. Like this I believe:
http://www.directinn.com/iframefull.html/BOB
I do not think you can make your own form and POST to their page. I see no indication that that is possible from the link you posted of the example.
The code you have will submit a load of Query String data to the receiving site.
The target site may implement some type of cross-site posting prevention which is causing the blockage - or they may ignore your query string parameters entirely.
I have created a simple button, on a click of it direct it to the paypal site for the payment.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="abhish_1347270213_biz#gmail.com" />
<input type="Show" name="item_name" value="My painting" />
<input type="Show" name="amount" value="10.00" />
<input type="submit" value="Buy!" />
</form>
Now what I am trying to do is to redirect to my own page with the transaction successful notification.
I have read websites articles but nothing is providing me with the Solution. Need help regarding to this issue.
Use PayPal Instant Payment Notification (IPN), more information here: https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/article_pdn_intro-outside.
Here's a code sample:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="alanb#alanb.com">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value="doodad from alanb.com">
<input type="hidden" name="item_number" value="dd01">
<input type="hidden" name="amount" value="4.99">
<input type="hidden" name="return" value="http://alanb.com/doodads/thanks.html">
<input type="hidden" name="cancel_return" value="http://alanb.com/doodads/canceled.html">
<input type="image" border="0" name="submit" src="http://images.paypal.com/images/x-click-but5.gif" alt="Effectuez vos paiements via PayPal : une solution rapide, gratuite et sécurisée">
</form>
The trick is done by the "return" input element ;).
Another thing that helped me a lot when setting up PayPal Integral Evolution on my website, was this PDF: https://cms.paypal.com/cms_content/FR/en_US/files/developer/IntegralEvolution.pdf. It documents all fields, possible values and how to use them.
Hope this helps,
Carl
I am having problem in integrating paypal IPN.I am implementing this code but it is not returning me the values to IPN
My form that is made after executing the code is as follow
<form method="post" name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="rm" value="2"/>
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value="info#something.com"/>
<input type="hidden" name="return" value="http://abc.com/test.php?action=success"/>
<input type="hidden" name="cancel_return" value="http://abc.com/test.php?action=cancel"/>
<input type="hidden" name="notify_url" value="http://abc.com/test.php?action=ipn"/>
<input type="hidden" name="item_name_1" value="Adob photoshop"/>
<input type="hidden" name="item_number_1" value="10"/>
<input type="hidden" name="amount_1" value="15"/>
<input type="hidden" name="upload" value="1"/>
<input type="hidden" name="cn" value="1"/>
<input type="hidden" name="tx" value="TransactionID"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="no_shipping" value="1"/>
<center><br/><br/>If you are not automatically redirected to paypal within 5 seconds...<br/><br/>
<input type="submit" value="Click Here"></center>
</form>
The problem is that the code is working fine for the return and cancel part but when I use this code for IPN it does not give me any value.My code for the IPN is as under
if ($pay->validate_ipn()) {
//do the insertion I have tested this insertion it is working fine
}
Have a look at History > IPN History inside your PayPal account. This should show the status of the IPN messages that were sent to you. Click on the message ID if you wish to find out more detailed information.
If it's retrying, double-check your error logs and ensure it's returning a proper HTTP/1.1 200 OK response when accessed by the PayPal IPN service (notify.paypal.com).