Paypal Buy Now button with variable/dynamic price

Álvaro N. Franz picture Álvaro N. Franz · Jul 5, 2017 · Viewed 9.5k times · Source

This is not a duplicate of this post.

I quote from the linked post:

As of June 29, 2017 I see this not working. Paypal has again changed its rules, and I don't think it any longer accepts hidden HTML fields in the form submission: they must be set in the button editor at Paypal.

Paypal documentation is a mess. Half of the links are broken and the other half of the links point to the documentation index.

Does any brain out there know how to achieve a Paypal Payment Button where I can set the price dynamically?

Answer

Murugesh picture Murugesh · Jul 7, 2017

PayPal recommended to use Express checkout client side integration and you can send the amount dynamically from your website to PayPal code.

Refer the following links for PayPal Express checkout client side integration:

https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/client-side-REST-integration/

https://developer.paypal.com/demo/checkout/#/pattern/client

Otheriwse, please try with the below PayPal HTML button code.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
  <!-- Identify your business so that you can collect the payments. -->
  <input type="hidden" name="business" value="[email protected]"> <!-- Add your PayPal Seller/Business email address Required-->
  <!-- Specify a Buy Now button. -->
  <input type="hidden" name="cmd" value="_xclick">
  <!-- Specify details about the item that buyers will purchase. -->
  <input type="hidden" name="item_name" value=""> <!-- Add Description e.g your room type Required-->
  <input type="hidden" name="amount" value=""> <!-- Dynamically add Total Amount Required-->
  <input type="hidden" name="currency_code" value=""> <!-- Update to your currency -->
  <input id="invoice" type="hidden" value="" name="invoice"> <!-- Add Unique invoice for each transaction -->
  <input type="hidden" name="notify_url" value="www.yourwebsite.com/ipn.php"> <!-- Please add IPN URL You can use this service to automate back-office and administrative functions, including fulfilling orders, tracking customers, and providing status and other information related to transactions. -->
  <input type='hidden' name='cancel_return' value='' /> <!-- Take customers to this URL when they cancel their checkout -->
  <input type='hidden' name='return' value='' /> <!-- Take customers to this URL when they finish their checkout  -->
  <!-- Display the payment button. -->
  <input type="image" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif" alt="PayPal - The safer, easier way to pay online">
</form>

HTML Variables - https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/Appx_websitestandard_htmlvariables/  
Buy Now button - https://developer.paypal.com/docs/classic/paypal-payments-standard/integration-guide/buy_now_step_1/ 
IPN - https://developer.paypal.com/docs/classic/ipn/gs_IPN/ 
IPN - https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSetup/ 
IPN Sample: https://github.com/paypal/ipn-code-samples