Button Help

rkrocker77
Contributor
Contributor

Hello,

 

I understand that I need to update my PayPal button for the new checkout experience. Below is my HTML and Javascript used for my button. Can someone help me change what I need to here? I'm not sure what in the code needs to be updated for the new checkout.

 

<form name="Payments">
<div align="center"><center>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<p class="bodytext"><strong>Invoice Number(s):</strong></p>
</td>
<td><input type="text" name="Invoices" size="20" /></td>
</tr>
<tr>
<td>
<p class="bodytext"><strong>Payment Amount:</strong></p>
</td>
<td><input type="text" name="Amount" size="20" />
<input type="hidden" name="Currency" value="CAD" size="1" /></td>
</tr>
<tr>
<td></td>
<td align="right" valign="bottom">[btn href="javascript&colon;update_paypal_link();" color="black"]Pay Now[/btn]</td>

</tr>
</tbody>
</table>
</center></div>
</form>
function update_paypal_link(form) {
	var strINV = document.Payments.Invoices.value
	var strAMT = document.Payments.Amount.value
	var strCUR = document.Payments.Currency.value
	var strPaymentURL = ""
	if (!(strINV) || !(strAMT))    {
          alert ("You must Enter the Invoice Number and the Amount")
	}
	else {
	  // Validate Amount Field
	  var Chars = "0123456789.,";
	  for (var i = 0; i < strAMT.length; i++) {
	    if (Chars.indexOf(strAMT.charAt(i)) == -1) {
	      alert("Only numbers (0-9) and a decimal are allowed in the Amount Field.");
	      return;
	    }
          }
          if (strCUR == "CAD") {
	    var strCOU = "CA";
	  }
	  else {
	    var strCOU = "US";
	  }
	  strPaymentURL = "https://www.paypal.com/xclick/business=&item_name=" + strINV + "&country=" + strCOU + "&currency_code=" + strCUR + "&amount=" + strAMT;
	  openWindow (strPaymentURL, 800, 600)
	}
}

// Validate $$
function validateDollar( fld )
{
   var temp_value = fld.value;

   if (temp_value == "")
   {
     fld.value = "0.00";
     return;
   }
   var Chars = "0123456789.";
   for (var i = 0; i < temp_value.length; i++)
   {
       if (Chars.indexOf(temp_value.charAt(i)) == -1)
       {
           alert("Only numbers (0-9) and a decimal are allowed in the Amount Field.");
           fld.focus();
           fld.select();
           return;
       }
   }
}


// Open popup window
function openWindow(url, iwidth, iheight) {
  var params = 'resizable,scrollbars,menubar,location,status,width='+iwidth+',height='+iheight
  popupWin = window.open(url, 'popup', params)
}

 

Login to Me Too
8 REPLIES 8

MTS_Nacho
Moderator
Moderator

@rkrocker77 Checking our logs, I can find a few instances (only 8 in the last 30 days) of incorrect parameters sent from your PayPal integration, being the last one on March 11th.

 

This is an example of such parameters:

 

business=***
item_name=1234
country=CA
currency_code=CAD
amount=$124
cmd=_xclick

 

The issue here would be with the "amount" variable, that shouldn't contain any currency symbol.

Login to Me Too

rkrocker77
Contributor
Contributor

Thanks for your help on this. I don't understand why only some of the instances would send incorrect parameters. Is this still an issue with my code or an issue with the user input? According to my code only numbers and decimals are allowed for the user to enter, so I'm not sure how it could be sending incorrect parameters. Can you help me with more specifics? I can provide you the site address if that helps you to see it in action.

 

Ryan

Login to Me Too

MTS_Nacho
Moderator
Moderator

Are you letting the buyers to input the amount in your site?

If that's the case, please validate that the amount written conforms to our rules and that they are not entering the currency symbol, before redirecting the buyer to PayPal.

 

Also, note that if we don't receive any amount or if we receive "0" (are you validating this?) we would present the buyer with an intermediate screen where they can input the amount they want to pay, and we would flag such amount if entered incorrectly.

 

 

 

 

Login to Me Too

rkrocker77
Contributor
Contributor

Yes the buyers can input their amount on the site. Here's the link to the site: https://goo.gl/iq913p

 

The user shouldn't be allowed to enter any currency symbols in the field. If you take a look at my link perhaps you can verify this and see where the problem may be?

Login to Me Too

MTS_Nacho
Moderator
Moderator

The PayPal code you are using looks fine.

 

However, it allows entering "0" as the amount, and that will trigger an intermediate PayPal page where the buyer must enter an amount, so that could explain those attempts where buyer introduced the "$" symbol.

 

So perhaps you can add extra validation to your JavaScript to prevent redirection when "0" amount.

 

Also, I can enter a comma (eg: 10,123) in your site and it's redirecting to PayPal as well. That could be another validation we'd recommend, as the amount must be in the following format:

 

12345.67

 

with no thousands separator, and only two decimal points.

 

 

Login to Me Too

rkrocker77
Contributor
Contributor

So the code I have now on the site will work after March 29th? I've tried using the form and entering a number (other than 0) with no commas and it still redirects me to the old PayPal checkout. Will this just change over for me on the 29th? Some clarification would be appreciated.

 

Thanks,

Ryan

Login to Me Too

MTS_Nacho
Moderator
Moderator

I wasn't able to reproduce this scenario when I tried last week, or today.

 

I'm always being redirected to the new checkout.

 

Are you able to consistently reproduce this? What are the exact values you are writing down for invoice + amount?

Login to Me Too

rkrocker77
Contributor
Contributor

There must be a cache issue on my end because I tried on a different computer and it redirects me to the new checkout as well. So we are good to go then. Thanks for your help!

 

Ryan

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.