Not able to specify "amount" per payment request on PayPal HTMLButton - paypal

I am trying to integrate with PayPal using the "HTML Buttons" approach.
The checkout flow is rather simple,
user clicks "Buy Now" -> transferred to PayPal -> payment processed -> returned to the site.
Based on the item that the customer wants to "Buy Now", the "amount" in the submitted form will vary, and I am unable to get PayPal to accept the value I am sending. I always see a text input which is empty when redirected to PayPal.
I tried hosted and unhosted buttons but still not able to see the desired effect.
hosted button HTML example:
<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="HOSTEDBTNVALUE">
<input type="image" src="https://www.sandbox.paypal.com/en_GB/SG/i/btn/btn_buynowCC_LG.gif" name="submit" alt="PayPal – The safer, easier way to pay online!" style="border: 0;">
<img alt="" src="https://www.sandbox.paypal.com/en_GB/i/scr/pixel.gif" style="border: 0; width: 1; height: 1;">
<input type="text" readonly="true" name="item_name" value="Test PayPal integration payment">
<div class="form-group" id="amount_field">
<label class="control-label col-md-2" for="amount">Amount</label>
<div class="col-md-5">
<input type="text" id="amount" name="amount" value="100" aria-describedby="amount_info_0" class="form-control"><span id="amount_info_0" class="help-block">Real</span></div>
</div>
<div class="form-group" id="txnRef_field">
<label class="control-label col-md-2" for="txnRef">Transaction Ref</label>
<div class="col-md-5">
<input type="text" id="txnRef" name="txnRef" value="8d724ad470af4d9d91d49f84068c4bab" aria-describedby="txnRef_info_0" class="form-control"><span id="txnRef_info_0" class="help-block">Required</span></div>
</div>
<input type="hidden" name="currency_code" value="SGD">
</form>
The "amount" above is a text input at the moment because this is my integration testing page, in the actual application it will be a hidden/readonly input embedded in the form.
Here is the unhosted button example code:
<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="encrypted" value="-----BEGIN PKCS7-----ReallyLongKey-----END PKCS7-----">
<input type="image" src="https://www.sandbox.paypal.com/en_GB/SG/i/btn/btn_buynowCC_LG.gif" name="submit" alt="PayPal – The safer, easier way to pay online!" style="border: 0;"><img alt="" src="https://www.sandbox.paypal.com/en_GB/i/scr/pixel.gif" style="border: 0; width: 1; height: 1;">
<input type="hidden" name="notify_url" value="https://myapplication.com/transaction/paypal/status">
<input type="hidden" name="currency_code" value="SGD">
<input type="hidden" name="custom" value="ad4a63e2f2f04b908ddb8e7c67f9c67a">
<input type="text" readonly="true" name="item_name" value="Test PayPal integration payment">
<div class="form-group" id="amount_field">
<label class="control-label col-md-2" for="amount">Amount</label>
<div class="col-md-5">
<input type="text" id="amount" name="amount" value="100" aria-describedby="amount_info_0" class="form-control"><span id="amount_info_0" class="help-block">Real</span></div>
</div>
<div class="form-group" id="txnRef_field">
<label class="control-label col-md-2" for="txnRef">Transaction Ref</label>
<div class="col-md-5">
<input type="text" id="txnRef" name="txnRef" value="ad4a63e2f2f04b908ddb8e7c67f9c67a" aria-describedby="txnRef_info_0" class="form-control"><span id="txnRef_info_0" class="help-block">Required</span></div>
</div>
</form>
I have screenshots below for the application page and what I see as a result on the PayPal payment page. Please excuse the lack of alignment and styling. This is meant to be a proof of concept before it is pretty.
my application test page for integration
paypal page where amount is expected to be fixed based on my request and not editable.
Not sure what I'm doing wrong here. Please help.
thanks.

I was able to get it going by making PayPal generate the button with the following settings:
1. Merchant account IDs: Use my primary email address [did not use secure merchant account ID]
2. unchecking the save button at PayPal checkbox. Also, in the html button generation interface, I clicked the link remove code protection which made the cmd value from _s-xclick to _xclick

Related

PayPal web error: We're sorry, but we couldn't complete your purchase using the funding source you selected

I created an account in PayPal and integrated with PHP in live mode. But when I enter my card details and submit then error message found.
We're sorry, but we couldn't complete your purchase using the funding source you selected. Please add a debit or credit card.
<form action="<?php echo $paypalUrl; ?>" method="post" name="frmPayPal1">
<div class="panel price panel-red">
<input type="hidden" name="business" value="<?php echo $paypalId; ?>">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" value="It Solution Stuff">
<input type="hidden" name="item_number" value="2">
<input type="hidden" name="amount" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="AUD">
<input type="hidden" name="cancel_return" value="http://localhost/paypal/cancel.php">
<input type="hidden" name="return" value="http://localhost/paypal/success.php">
<div class="panel-heading text-center">
<h3>PRO PLAN</h3>
</div>
<div class="panel-body text-center">
<p class="lead" style="font-size:40px"><strong>$20 / month</strong></p>
</div>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item"><i class="icon-ok text-danger"></i> Personal use</li>
<li class="list-group-item"><i class="icon-ok text-danger"></i> Unlimited projects</li>
<li class="list-group-item"><i class="icon-ok text-danger"></i> 27/7 support</li>
</ul>
<div class="panel-footer">
<button class="btn btn-lg btn-block btn-danger" href="#">BUY NOW!</button>
</div>
</div>
</form>
Some variables used in redirection are:
<?php
$paypalUrl='https://www.paypal.com/cgi-bin/webscr';
$paypalId='xxx#xxxxxxxx.xxx';
?>
This isn't an issue for Stackoverflow. There is no technical problem, and certainly no programming problem.
The issue is in the title: "We couldn't complete your purchase using the funding source you selected.", and the solution follows in the quoted message: "Please add a debit or credit card."
This is a normal business exception. When a user sees this message, they need to pay with a different payment method, such as a different card.

Passing Donation Amount to PayPal Page

In the past I was able to add a form so a user could add a donation amount on the website and it would send that amount to the PayPal checkout page. It seems that PayPal has changed how this works and I am having issues figuring out how to pass that amount. I am hoping someone here has gotten this to work. Here is my current code and dev site for testing purposes.
<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="VMUWQGHWEATL8" />
<input type="hidden" name="currency_code" value="USD">
<!-- Text Input Boxes -->
<div class="donate-wrapper">
<input type="text" id="amount" name="amount">
<p style="color: #fff">Monthly donation options on the next screen.</p>
<input type="submit" name="submit" value="continue" alt="PayPal - The safer, easier way to pay online!">
</div>
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>
Dev site: https://braindonordev.wpengine.com/support-us/
You can do it. Create a new button via http://www.paypal.com/buttons , and in Step 2 uncheck the option to save the button at PayPal. Then when you have generated your button code, click the option to remove the code protection.
Now you have "unhosted" HTML you can edit.
The unfortunate thing when passing a donation amount is there won't be an option to make the donation recurring, so you would need a separate relabeled "Subscribe" button for that. Relabled meaning, replace the image with one that says "Donate".
Alternatively, just keep the basic Donate button that you have to serve both use cases (recurring and non-recurring). It's intuitive enough, and has a nice big amount box on the next screen and checkbox to make it recurring:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="paypal#redcross.org">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="USD">
<input type="text" name="amount">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_donateCC_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_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>

PayPal Not Passing Amount For Donation

I'm building a website for a client that has to take donations. I want to have the donation value passed through and automatically filled when they land on PayPal. I have two different sets of code with two different errors.
I do not have access to my clients PayPal account so please let me know if it's not solvable on my end. I do have their merchant ID, which has been redacted in the below code with "merchantidgoeshere".
Code 1: Goes To Merchant Donation Form But Doesn't Pass The Value
<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="merchantidnumberhere" />
<input type="hidden" name="item_name" value="Donation Description">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="amount" value="15.00">
<br /><input name="submit" type="image" alt="PayPal - The safer, easier way to pay online!" src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_donate_92x26.png" /><span class="lazy_container" style="width: 1px;"><span class="lazy_preloader" style="padding-top: 100%;"></span><img width="1" height="1" alt="" src="plugins/system/tmlazyload/blank.gif" class="lazy" data-src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" border="0" /></span>
</form>
Code 2: Doesn't Go To Page And Redirects To Error Page With The Message:
We cannot process this transaction because there is a problem with the PayPal email address supplied by the seller. Please contact the seller to resolve the problem. If this payment is for an eBay listing, you can contact the seller via the "Ask Seller a Question" link on the listing page. When you have the correct email address, payment can be made at www.paypal.com.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations" />
<input type="hidden" name="business" value="merchantidnumberhere" />
<input type="hidden" name="item_name" value="Donation Description">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="tax" value="0">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="amount" value="15.00">
<br /><input name="submit" type="image" alt="PayPal - The safer, easier way to pay online!" src="https://www.paypalobjects.com/webstatic/en_US/i/btn/png/btn_donate_92x26.png" /><span class="lazy_container" style="width: 1px;"><span class="lazy_preloader" style="padding-top: 100%;"></span><img width="1" height="1" alt="" src="plugins/system/tmlazyload/blank.gif" class="lazy" data-src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" border="0" /></span>
</form>
The first button is a hosted button, so the amount details would have to be set at in the button wizard within the PayPal account. You won't be able to pass your own dynamic value using a hosted button.
The second one is working fine for me when I replace "merchantidnumberhere" with a valid account email address. Did you make sure to update the business parameter with a valid email address or account ID?
Just as a note, to force English as the language the code shouldn't be:
<input type="hidden" name="lc" value="US">
It should be:
<input type="hidden" name="lc" value="en_US">
Cheers from Spain!

PayPal button with custom amount

I'm trying to add a PayPal 'Buy Now' button to my website. Because the price of my product is customer per order I need to pass in custom amount which is pulled in by the variable {{ order.invoiceValue }}. My code snippet is below, but it does not seem to be recognized by PayPal (see screenshot below). Any help would be appreciated!
<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="XXXYYYZZZ">
<input type="hidden" name="business" value="service#mycompany.com">
<input type="hidden" name="amount" value="{{ order.invoiceValue }}">
<input type="hidden" name="quantity" value="1">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0"`enter code here` src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
You do not need to add the code {{ order.invoiceValue }}. Instead, just leave the value as a blank. When your customers put the amount, the price it will be passed to PP.

PayPal Donation Button: Adding 'Amount' and 'Currency'

I have the "normal" PayPal donation button. I want to add two multiple choice fields: Amount and Currency as the image below. So the user dont need to put the amount of the PayPal website:
This is the 'normal paypal donation button code':
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXXXXXXXX">
<input type="image" src="https://www.paypalobjects.com/es_ES/ES/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/es_ES/i/scr/pixel.gif" width="1" height="1">
</form>
I have read on this post that you have to add the following lines, but I dont know where or how to do it. It doesnt work.
<label for="amount">Select the amount you wish to donate:</label>
<select name="amount" id="amount">
<option value="5.00">$5.00</option>
<option value="25.00">$25.00</option>
<option value="50.00">$50.00</option>
</select>
Can anyone tell me how to do it correctly? Thanks!
Hosted PayPal buttons allow you to send option variables, but when not for a donation button, be sure that the option values (for drop downs / text boxes) match exactly what is saved in your PayPal account. i.e. do not edit drop down boxes PayPal creates for you.
As for adding drop down boxes / text boxes to a hosted button, perfectly possible, as long as they do not alter the payment amount. So, for creating a hosted donation button that allows you to edit the amount, I advise the following:
Create a buy now button on PayPal, adding the drop down boxes and/or text boxes you wish to add to your donation button. Create this button as if you were creating your donation button, because that is exactly what we will be doing, changing this button into a donation button.
Copy the the whole buy now button HTML code, paste into notepad, or an editor where you can use 'find and replace'.
Replace all occurances of 'buynow' with 'donate' (This usually just changes the image). Also, replace '_xclick' with '_donations'. (to tell PayPal how to generate the checkout page)
You now have a donation button
I had the similar problem, I solved it by the following steps:
Created a basic 'Buy Now' button (without any options or text fields, just the bare button), made sure i unchecked 'save button at PayPal' before clicking 'create button'.
Then After the button is created, and code is generated, clicked 'Remove code protection' on the top-right where the generated code is shown.
added one additional text input with name 'amount'
replaced value _xclick with _donations (on the input field with name='cmd')
the result is the following code, and it works for me (for now) (you need to add some validations though)
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="XXXXXXXXXXXXX">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="Sample Name Here">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="cn" value="Add special instructions to the seller:">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHosted">
<input type="hidden" name="on0" value="Donate">
<input type="text" name="amount" value="23.00">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynow_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>
Paypal has specific HTML data requirements when you post to their page.
The 'host_button_id' can only be used for one specific value and it's data that paypal holds on their site as a convenience to their clients.
In order to pass variable data you have to pass all the information they need. The 'host_button_id' is no longer needed.
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<!-- Identify your business so that you can collect the payments. -->
<input type="hidden" name="business" value="herschelgomez#xyzzyu.com">
<label for="amount">Select the amount you wish to donate:</label>
<select name="amount" id="amount">
<option value="5.00">$5.00</option>
<option value="25.00">$25.00</option>
<option value="50.00">$50.00</option>
</select><br/>
<label for="currency_code">Select the currency:</label>
<select name="currency_code" id="currency_code">
<option value="USD">USD</option>
<option value="GBP">GBP</option>
<option value="CAD">CAD</option>
</select><br/>
<input type="hidden" name="currency_code" value="USD">
<input type="image"
src="https://www.paypalobjects.com/es_ES/ES/i/btn/btn_donateCC_LG.gif" border="0"
name="submit" alt="PayPal.">
<img alt="" border="0" src="https://www.paypalobjects.com/es_ES/i/scr/pixel.gif"
width="1" height="1">
</form>
You can find more currency codes here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_currency_codes
and more html info here: https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_html_buynow_buttons#id08A2G0920QN
Also for the hidden 'cmd' I'm not sure if that will have to change to '_xclick' only. You'll have to test it out and see what works.
Please try this :
<head>
<title>Get Selected Item - DevCurry.com</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js">
</script>
<script type="text/javascript" language="javascript">
$(function () {
$('#ddl').change(function () {
$('#divone').text($(this).find(":selected").val());
});
});
</script>
</head>
<body>
<select id="ddl">
<option value="Tomatoes">Tomatoes</option>
<option value="Potatoes">Potatoes</option>
<option value="Onion">Onion</option>
<option value="Olives">Olives</option>
</select>
<br />
<div id="divone" />
<input type="hidden" id="txt" />
</body>
</html>