Is it possible to POST the amount variable to PayPal? - php

I am trying to add PayPal checkout to my website. The total amount for each payment varies and so I use PHP to generate the total sum. I am trying to POST the amount to a hosted button so that it is more secure, using the advanced variables option on the 3rd step when creating a button but I can't seem to get it to work.
Does anybody know if it is possible to actually do this or does it have to be done another way?
Code on the website:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="GMENQCFMYUE46">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">
<input type="hidden" name="amount" value="<?php print("$total")?>"/>
<input type="hidden" name="quantity" value="1" />
<input type="hidden" name="item_name" value="<?php print("$origin - $destination Transfer $date")?>" />
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">
</form>
The item_name works fine but I understand that the amount variable wont carry over in this way so I am trying to find a way to do this.

Related

How to add specific amount in PayPal Donation

I'm trying to add a donation page with paypal integration. It works perfectly fine. But what I want to add is to first sign the form from my site and then send it to paypal as well as the selected amount of donation. I've also trid to put this code <input type="hidden" name="amount" value="<?php echo $total; ?>"> as per my research. But it's still not working. Please see my code below for your review/reference.
Code
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QWEVB36VTJYEG">
<input type="hidden" name="amount" value="88.00">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
The result would be just like this: (Blank Value) (The value must be 88.00)
As far as I know, donations on Paypal can't be restricted to one single value. The amount input is ignored, to be sure that people who will donate are not being manipulated and forced to pay a price they did not choose.
However, if you want to propose some fixed prices, here is a Paypal Community code which will help you doing that.
EDIT: Here is a StackOverflow answer which is pretty clear and confirms my thoughts.

How to make button paypal with our variable total in php

Hy guys, How to make button paypal with our variable $total, I make button paypal automatic in paypal.com, but I don't know how to change code with my variable total in my program, and change this value with my email <input type="hidden" name="hosted_button_id" value="6GRSJ868MQYPS">
this is my code can any solution with my problem ?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6GRSJ868MQYPS">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Hosted buttons hide those parameters, so you won't be able to dynamically adjust the $total when the page loads. If you want to do that you'll need to create a button that is not hosted, and then you would have an "amount" parameter you could pass your $total into.

Paypal Payment Buttons - Can You Dynamically Set the Price

I am certainly interested in using PayPal's Standard payment buttons; however, I would like to be able to set the amount myself in code, instead of being forced to create a button with a fixed amount through Paypal. For example, I thought the following code would work:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="amount" value="5.00">
<input type="hidden" name="encrypted" value="-----BEGIN PKCS7-----MIIH2wYJKoZIhvcNAQcEoIIHzDCCB8gCAQExggE6MIIBNgIBADCBnjCBmDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBKb3NlMRUwEwYDVQQKEwxQYXlQYWwsIEluYy4xFjAUBgNVBAsUDXNhbmRib3hfY2VydHMxFDASBgNVBAMUC3NhbmRib3hfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwuY29tAgEAMA0GCSqGSIb3DQEBAQUABIGAH+DqNBRlDwSh687j3TxNmxEdl5QzHnS7yVrZpgBots7qg9fODfjYUlgXXMPz35gB65jiD+jsCd1dc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0GCSqGSIb3DQEBAQUABIGAdbJUsYUTVyNZ/0/ivmpPr1xSzk9okSRA6lrmgSOWwZP7/sukM/mSZ9b/nvjStbspSK1HPgmDyeDmKy355dX83/42P04b/faGikPPaBHSvEsoL4MmMSj/Jqfzg1iV8tbynyf/VT9DlitZlho54CygGaT/ZcML6M/JRJlECWzsnc0=-----END PKCS7-----
">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
This does not work either:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="U7K937HLYPW6L">
<input type="hidden" name="amount" value="5.00">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
Instead of directing the user to a page where they could make a payment of 5.00, the page instead allows users to input their own amount. In my real application, I would use PHP to calculate the total (at a cart style page) and associate that value with the 'amount' key, but I cannot even get it to work even with static values. What is the solution?
Thanks much!
You would need to utilise their API to produce dynamic pricing to break away from the "cart" type system provided by paypal. Essentially you would look to replace the paypal "cart" page with your own by coding using the API.

Paypal return url with hash tag?

I've got a PayPal form which has return url with hashtag. When the payment is ready and the user press their link return to the page the link is with %23 insted #, is there a way to fix that? I need that hash tag to show the correct tab.
I know the question is a bit out of programming, and it may is a some PayPal api issue but maybe I'm doing something wrong.
For the protocol, I've tried with urlencode straight into my form, but the problem is still there, it seems that paypal encode that url and when is returned my browser can't decode it again.
Hashtag should work fine in the return url:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" target="paypal" method="post">
<input type="hidden" name="cmd" value="_xclick" />
<input type="hidden" name="business" value="hbsawnhdglv#paypal.com" />
<input type="hidden" name="item_name" value="item" />
<input type="hidden" name="currency" value="USD" />
<input type="hidden" name="amount" value="0" />
<input type="hidden" name="return" value="http://localhost/test.php#test" />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>
and on jsfiddle. I also tried with ExpressCheckout and it works as well, however using standard anchors this may not work as the hashtag may be in the wrong place. Also, if you are trying to put it at the end of a GET variable it will think it is part of the variable and encode it:
<input type="hidden" name="return" value="http://localhost/test.php?v=1#test" />
Produces: http://localhost/test.php?v=1%23test

PayPal simple upload cart using one button - why is shopping cart empty?

I'm trying to upload a cart with the following code, but when the user hits the "buy now" button, then instead of showing PayPal's order summary page where the user can sign in to pay, I get an error that says Your shopping cart is empty.
This is my code, what's wrong with it?
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<a href='cart.php?type=current' class='buttonlink previous'>Edit Order</a> <a href='checkout4_confirm.php' class='buttonlink next'>Submit Order</a>
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="hosted_button_id" value="JRECLRTYAJDKY">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="XXX#XXX.XXX">
<input type="hidden" name="item_name_1" value="<?php echo $order_number; ?>">
<input type="hidden" name="item_number_1" value="1">
<input type="hidden" name="quantity_1" value="1">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynow_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
This is most likely being caused by the fact that you are creating a hosted button from your account, but then you are making modifications to the code. If you are going to do this, you need to create a clear text, non hosted button.
When creating the button from within your account, uncheck the option on step 2 to save button at PayPal. Then once the code is generated, click the link to remove code protection. This will create a clear text non hosted button. Then you should be able to modify the button.

Categories