Create specific paypal button for 3 types of payment options

Adriana2651
Contributor
Contributor

I'm trying to code a Paypal Buy Now button which discounts quantity items (none of the ones I found on the developers community works for me).

Here's what I need:

List price is $19.99

Buy one - $14.99

Buy two or more - $12.99

So far I have been able to create the button which takes the first discount off, but when someone orders 2 or more, the first item of the two still charges $14.99 and then second item charges $12.99.   

I need when someone buys 2 items they will both be charged at $12.99. (not $14.99 for the first and $12.99 for the second)

Login to Me Too
1 ACCEPTED SOLUTION

Accepted Solutions
Solved

Adriana2651
Contributor
Contributor

Thanks for your response GG. I really appreciate it.

Although I can use the original code you sent (and it works perfectly), I wanted to set up a better shopping cart checkout experience.  I'm linking a page where I set up my original button (which, even though I've tried everything I can think of, still does not take the discount off two items), and right below that, I set up the button you sent.  What I'd love to do is create the checkout experience for the first button, with of course the correct calculations of your button.  Is this possible?  

Just to be clear on the discounts - Original price is $19.99.  The sale price is $14.99.  If you buy 2 or more, the price is $12.99 each. My button, although nice experience for buyer, takes the first discount off - (19.99 becomes $14.99) but then continues to make the first item purchased $14.99 instead of 12.99 - so if you order 2, rather that $25.98 total, it's $27.98 total. That follows through on all the rest as well. It continues to charge 14.99 for the first and then 12.99 for all the rest. I need anything more than one to be charged at 12.99 each. So my client wants the experience of the first button.

Here is the link to both mine and your button.  Sorry for the long explanation. http://newness.cratestop.com/page1.html.  TY

View solution in original post

Login to Me Too
6 REPLIES 6

Anonymous_User
Not applicable

What you need is a custom coded item button that includes a script that manages the input and logic and then passes the end results to the PayPal Checkout Screens.  Although the item button creator is a great tool which can generate fast, basic code however, when you have a need that is outside the box, the code has to be manually created.   As an example - for learning purposes - check out the Buy Now example below.   As there are countless ways to do the same thing, below is just one example of how to apply a discount for various quantities.

 

<!doctype html>
<html lang="en">
<head>

<title>Buy Now Discount Example</title>

<!-- START META TAG SECTION -->
<meta name="Description" content="">
<meta name="KeyWords" content="">
<meta charset="UTF-8">
<!-- END META TAG SECTION -->


<!-- Start of Script -->
<SCRIPT type=text/javascript>
<!--
var ac = 0;    // table for qty/amt pairs
var aqty = new Array ();  // qty brkpt
var aamt = new Array ();  // amount to charge

var pc = 0;    // table for qty/percent pairs
var pqty = new Array ();  // qty brkpt
var pper = new Array ();  // percent to discount

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function ReadForm (obj1) { // quantity based discounts
var i,amt,des,qty;
  amt = obj1.baseamt.value*1.0; // base amount
  des = obj1.basedes.value;     // base description
  qty = obj1.qty.value;         // get user quantity
  if (isNaN (qty) || qty < 1) { // make sure it's good
    alert ('"' + qty + '"' + ' is not a valid number!');
    ac = 0;                     // always zap the table
    pc = 0;
    return false;               // th-th-that's all, folks.
  }
  qty = qty*1.0;                // force to numeric

  for (i=ac-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= aqty[i]) {       // use this entry
      amt = aamt[i];            // this is the real amount
      break;                    // get out, we're done
    }
  }
  for (i=pc-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= pqty[i]) {       // use this entry
      amt = amt - (amt/100.0 * pper[i]);
      break;                    // get out, we're done
    }
  }

  obj1.item_name.value = des + ", " + qty + " Widget(s) @" +
                         Dollar (amt) + " each.";
  obj1.amount.value = Dollar (amt * qty);
  ac = 0;  // reset item discount
  pc = 0;
}

function SetAmt (q1, a1) {  // set up a quantity-based amount table
var i;
  ac = 0;
  for (i=0; i<arguments.length; i=i+2) {  // build the table
    aqty[ac] = arguments[i];   // get real args and store 
    aamt[ac] = arguments[i+1];
    ac = ac + 1;               // number of pairs in table
  }
}
//-->
</SCRIPT>
<!-- End of Script -->


</head>

<body>

<!-- START SAMPLE CODE SECTION -->


<!-- PARAGRAPH 1 -->
Discount Example

<br><br>

Buy More, Pay Less - Buy Now Item Button.

<br><br>

Widgets 
<br><br>
1-4 Widgets - $5.00 each
<br>
5-9 Widgets - $4.20 each
<br>
10 or More&nbsp;  - $3.30 each
<br><br>

<!-- Start of Buy Now Form -->
<!-- Note: target="paypal" was replaced with target="_self" -->
<!-- Note: shopping_url also added to code -->
<FORM onsubmit="this.target = '_self'; SetAmt (1, 5.00, 5, 4.20, 10, 3.30); return ReadForm (this);" 
action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" value="_xclick" name="cmd">
<!-- Replace "business" value with your PayPal Email Address or your Merchant Account ID -->
<input type="hidden" name="business" value="your PayPal Email Address or your Merchant Account ID">
<input type="hidden" name="item_name">
<input type="hidden" value="01-001" name="item_number"> 
<input type="hidden" name="amount">
<input type="hidden" value="2" name="no_shipping">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<!-- Replace value with the web page you want the customer to return to after a successful transaction -->
<input type="hidden" name="return" value="http://www.yourwebsite.com/ThankYou.html">
<!-- Replace value with the web page you want the customer to return to after item cancellation -->
<input type="hidden" name="cancel_return" value="http://www.yourwebsite.com/Cancel.html">
<input type="hidden" value="USD" name="currency_code">
<input type="hidden" value="US" name="lc">
<input type="hidden" value=5.00 name="baseamt">
<input type="hidden" value="Widget" name="basedes"> 
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHosted">
Enter Desired Quantity:&nbsp;&nbsp;
<input size="3" value="1" name="qty">
<br><br>
<input type="reset" name="reset" value="Clear Selections" />
<br><br>
<input type="image" src="https://www.paypalobjects.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.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</FORM>
<!-- End of Form -->

<!-- END BUTTON EXAMPLES -->



<!-- END SAMPLE CODE SECTION -->

<br><br>


<br><br><br><br>
<hr align="left" width="50%" noshade>
<br><br>
NOTES:
<br>
In order to test the code, you must replace the &quot;business&quot; value variable with your PayPal Email Address or your Merchant Account ID.


</body>
</html>

 

Login to Me Too

Adriana2651
Contributor
Contributor

Thanks so much for your response.  I was able to get the code to work for me. I really appreciate your quick response as well!

 

I would love to use this code in a nicer looking button, such as the 

buy now button I had originally used  but couldn't find a way to set up the first item to reduce in price when someone bought two. However I did like the look of that whole check out experience and was wondering if there's a way to use this code (which works!) to make it look like the one here when you click the 'buy now' button:  http://icebones.com/page2.html

Is that possible? 

Adriana

Login to Me Too

Anonymous_User
Not applicable

I'm guessing you want the button to have a Buy Now graphic but, the actual function is to work like an Add to Cart.    Yep, that's possible, what you need to do is change the command line from a Buy Now to an Add to Cart.

First look for this line:

<input type="hidden" value="_xclick" name="cmd">

Now replace that line with these two lines:

<input type="hidden" value="_cart" name="cmd">
<input type="hidden" value="1" name="add"> 

You can then follow up with including the View Cart code if that's something you want to add.  Which would look something like this:

<!--  Start of View Cart Button Code  -->
<form target="_self" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="display" value="1">
<!-- Replace "business" value with your PayPal Email Address or your Merchant Account ID -->
<input type="hidden" name="business" value="your PayPal Email Address or your Merchant Account ID">
<!-- Replace value with the web page you want the customer to return to -->
<input type="hidden" name="shopping_url" value="http://www.yourwebsite.com/Shop.html">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_viewcart_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> 
<!--  End of View Cart Button Code  -->
Login to Me Too
Solved

Adriana2651
Contributor
Contributor

Thanks for your response GG. I really appreciate it.

Although I can use the original code you sent (and it works perfectly), I wanted to set up a better shopping cart checkout experience.  I'm linking a page where I set up my original button (which, even though I've tried everything I can think of, still does not take the discount off two items), and right below that, I set up the button you sent.  What I'd love to do is create the checkout experience for the first button, with of course the correct calculations of your button.  Is this possible?  

Just to be clear on the discounts - Original price is $19.99.  The sale price is $14.99.  If you buy 2 or more, the price is $12.99 each. My button, although nice experience for buyer, takes the first discount off - (19.99 becomes $14.99) but then continues to make the first item purchased $14.99 instead of 12.99 - so if you order 2, rather that $25.98 total, it's $27.98 total. That follows through on all the rest as well. It continues to charge 14.99 for the first and then 12.99 for all the rest. I need anything more than one to be charged at 12.99 each. So my client wants the experience of the first button.

Here is the link to both mine and your button.  Sorry for the long explanation. http://newness.cratestop.com/page1.html.  TY

Login to Me Too

ginamcc12
New Community Member

ginamcc12:united states business account

Login to Me Too

saviodesigns
New Community Member

Hi I am trying to do something similar.  I tried the above, and while it does work, the issue I am having on the PayPal page is that the quantity is in the Description, not the Quantity field and this is breeding confusion.

 

Is there any way to make it so that the quantity entered shows on the Quantity field in the paypal check out?

 

Currently it shows as follows:

 

Description:  3 widgets @$5.oo        Quantity: 1     Total: $15.00

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.