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+jsCd1dc3yVZ5mNRtMu8uyLkKO4APlg4qJZETM5zmtoMeom4AMXCm+1hagsWjMEE3o5oUGyjEkFwz+pflNqviUoEQwdCv2OwVTUD3sxCzAJBgUrDgMCGgUAMIIBJQYJKoZIhvcNAQcBMBQGCCqGSIb3DQMHBAg6YkTw6MwNS4CCAQDYJ/09z9A6ApCy4d4xtEkMuTkTvCESa5b9Lk00U+hNiOEaEW8e8aO/08AzeKG9PmnZE+GC59Esr4TMMpxoLRyl5nyWk0jfGQX4CwRYlWQXgLRcfe2psN1iFy2vdMOpa5mruZB65iWZvd432790pmYP24Tmq3mAhJLKfkeR0Hqyc9n2bW/al3DuGvjZROSLw9z63FxZI8Hmvzcms2TBTNij1i72+jXB1yyIUBFVd0H5xk5l5hrpSm12+dCm/sIR5NNKfPFreJ84h3xef2dXDR62fGhP3vHfSJ0xr4s/bfcIFeDBB5LDGReKllsFwP9tJ8AsRmvFiJ+dcW5HGXsovrnHoIID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FAAOBgQBXNvPA2Bl/hl9vlj/3cHV8H4nH/q5RvtFfRgTyWWCmSUNOvVv2UZFLlhUPjqXdsoT6Z3hns5sN2lNttghq3SoTqwSUUXKaDtxYxx5l1pKoG0Kg1nRu0vv5fJ9UHwz6fo6VCzq3JxhFGONSJo2SU8pWyUNW+TwQYxoj9D6SuPHHRTGCAaQwggGgAgEBMIGeMIGYMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8GA1UEBxMIU2FuIEpvc2UxFTATBgNVBAoTDFBheVBhbCwgSW5jLjEWMBQGA1UECxQNc2FuZGJveF9jZXJ0czEUMBIGA1UEAxQLc2FuZGJveF9hcGkxHDAaBgkqhkiG9w0BCQEWDXJlQHBheXBhbC5jb20CAQAwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcNAQkFMQ8XDTE2MDUxNDAyMTQ1NlowIwYJKoZIhvcNAQkEMRYEFEZCu52pVGGuQnysWYPrliEa73/0MA0GCSqGSIb3DQEBAQUABIGAdbJUsYUTVyNZ/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.
Related
I've been trying for over a week to get a value that I send to paypal returned. I've tried everything I have found on the internet to no avail, and I have very little hair left to pull out...
<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="XXXXXXXXXXXX">
<input type="hidden" name="custom" value="<?=$pno;?>">
<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>
and
<form action="https://www.paypal.com/cgi-bin/webscr?custom=<?$pno;?>>" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXXXXXXX">
<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>
and many many variations on those themes. None of it works. When I try to assign $_POST['custom'], it's empty - every time.
The client's PayPal account is a business account and auto-return is on.
What am I doing wrong?
With an integration that uses no API you can never depend on any return to happen, so that is your first mistake.
The best solution is to use this API-based integration: https://developer.paypal.com/docs/business/checkout/server-side-api-calls/#server-side-api-calls
You'll need two routes, one for 'Create Order' and one for 'Capture Order', which return JSON.
Pair the routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server
The purchase_unit object can contain a custom_id https://developer.paypal.com/docs/api/orders/v2/#definition-purchase_unit_request
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.
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.
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.
I need to paste this code at admin panel and then display Paypal Button on website.
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="6UKjJ8hU6ML5f">
<input type="hidden" name="custom" value="<?php print($_SESSION['mid'].'-'.$_SESSION['mps']);?>">
<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>
Then, need to display this code on website using following code.
print $rs->fields("ppbutton");
Now, problem is that due to PHP code inside Paypal form, whenever I try to print above value (paypal button) on website, it's giving error because of PHP code inside another PHP code.
I also think, print htmlentities($rs->fields("ppbutton"));
is the best option for you.
You can get the most recent updates about the function from this site.
http://php.net/manual/en/function.htmlentities.php
print htmlentities($rs->fields("ppbutton"));