Amount Variable for PayPal.

Problems installing or using the NOP Design Free Shopping Cart that do not fit into one of the above categories.

Moderators: Koibito, Stefko, Randy

Amount Variable for PayPal.

Postby ernieknolfson » Thu Dec 22, 2005 1:34 pm

i run a one item nopcart shop and have a paypal option with following paypal form:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="info@domain.net">
<input type="hidden" name="undefined_quantity" value="1">
<input type="hidden" name="item_name" value="TheItem">
<input type="hidden" name="item_number" value="zl01">
<input type="hidden" name="amount" value="XXXXXXXXXXX">
<input type="hidden" name="return" value="http://domain.net/danke_pp.html">
<input type="hidden" name="cn" value="Comments">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="design/kaufen_pp.gif" border="0" name="submit2" alt="PayPal">
</form>

instead of the
"XXXXXXXXXXX"
i would like to have included the total amount of the cart
which has to be decimal formatted like this:
1,00 (<--- yes, decimal separator must be a comma in the language the shop uses paypal with)

i need somekind of a formatted variable to put there. any help? thanks heaps.

ernie.
ernieknolfson
 
Posts: 5
Joined: Thu Dec 22, 2005 10:59 am
Location: europe

Postby Randy » Thu Dec 22, 2005 2:15 pm

Add this function to nopcart.js:

Code: Select all
//---------------------------------------------------------------------||
// FUNCTION:    EuroFormat                                             ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Euro Amount to #,## format                   ||
//---------------------------------------------------------------------||
function EuroFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents.length <2 )
      cents = "0" + cents;

   return(dollars + "," + cents);
}


when you want the comma decimal point use
EuroFormat(fTotal) in place of MoneyFormat(fTotal)

You will get a NaN error if you try to do math with the Euro format.

Randy
JRS SERVICES
e-commerence solutions
www.jrsservices.net
Randy
Guru
 
Posts: 1511
Joined: Tue Apr 22, 2003 12:21 pm
Location: Thunder Bay, Ontario

still doesn't ...

Postby ernieknolfson » Thu Dec 22, 2005 3:03 pm

thanks for your reply, i really appreciate it.

i have added the code to nopcart.js and changed to form to

<input type="hidden" name="amount" value=EuroFormat(fTotal)>

but i still get the paypal wrongly formatted amount error messge. really strange ...
ernieknolfson
 
Posts: 5
Joined: Thu Dec 22, 2005 10:59 am
Location: europe

Postby Randy » Thu Dec 22, 2005 10:50 pm

Wouldn't you have to do something like this:
Code: Select all
strOutput += "<input type=hidden name=\"amount\" value=\""+ EuroFormat(fTotal) + "\">";
   .
   .
   .
   .
   document.write(strOutput);


For the variable to be included with the input hidden value and not just the text "EuroFormat(fTotal)" as in

<input type="hidden" name="amount" value=EuroFormat(fTotal)>

R
JRS SERVICES
e-commerence solutions
www.jrsservices.net
Randy
Guru
 
Posts: 1511
Joined: Tue Apr 22, 2003 12:21 pm
Location: Thunder Bay, Ontario

not quite ...

Postby ernieknolfson » Sat Dec 24, 2005 11:32 am

hi and thanks for your reply. i am new to javascript. now i checked several ways like this:

.
.
<input type="hidden" name="item_name" value="TheItem">
<input type="hidden" name="item_number" value="zl01">

<script language="JavaScript" type="text/javascript">
strOutput += "<input type=\"hidden\" name=\"amount\" value=\""+ EuroFormat(fTotal) + "\">";
document.write(strOutput);
</script>

<input type="hidden" name="return" value="http://domain.net/danke_pp.html">
.
.

paypal doesn't show an error anymore, but it does not take across the amount (paypal just gives you an empty amount field). it's the same result as if the whole "amount" line is not there at all.
ernieknolfson
 
Posts: 5
Joined: Thu Dec 22, 2005 10:59 am
Location: europe

Re: Amount Variable for PayPal.

Postby nickc » Thu May 16, 2013 11:59 am

I use a centFormat function to change a comma decimal to a dot in hidden fields sent to Paypal.
Code: Select all
{
    var finalcenttotal = centFormat((fTotal + fTax));
    strOutput += "<input type=hidden name=\"PBX_TOTAL\" value=\"" +  finalcenttotal + "\">";
         }
         {
    var finalcenttaxtotal = centFormat(fTax);
    strOutput += "<input type=hidden name=\"PBX_TAX\" value=\"" +  finalcenttaxtotal + "\">";
         }

The total PBX_TOTAL works fine and the PBX_TAX amount works perfectly for single items, even multiple orders of the same item.
However when the customer orders multiple items, the hidden PBX_TAX field prints out "0.00, 0.00" (etc. according to the number if different items), or "5.00, 5.00" when the €5 tax is applicable.

Where am I going wrong?
nickc
WebMaster
 
Posts: 9
Joined: Fri Sep 30, 2005 7:52 am
Location: south west france


Return to Help: Cart / General

Who is online

Users browsing this forum: No registered users and 3 guests

cron