views:

1537

answers:

2

I'm building a website where I basically want my checkout to work like this website: http://www.solutionkaizen.com/html/boutique.php

It allows you to enter the quantity for each item and then press a button which brings you to PayPal and lists how many Products you have.

On PayPal's website, all the info I found seems to lead to me needing a shopping cart. If this is absolutely necessary, how could I implement that?

Thanks

A: 

In theory, that page is the "shopping cart".

Mez
So how would I be able to tell PayPal how many items they user has selected at runtime? Like I think you have to define like item_name_x etc... where x is the item number, but if the quantity is 0 what do I do?
Milo
Look at the shady answer below because it actually works in practice for me.
David Grayson
+7  A: 

I just had to do this.

I use this form in my HTML:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="payPalForm" onsubmit="if (verify()) { get_items(); return true; } else return false;">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="[PAYPAL EMAIL HERE]" />
<input type="hidden" name="currency_code" id="currency_code" value="USD" />
<input type="hidden" name="return" value="http://www.mysite.org/thank_you_kindly.html" />
<p style="text-align: center"><input type="submit" name="Submit" value="Join (via PayPal)" id="register_button" /></p>
</form>

The particular form I made can also change the currency by setting the currency_code hidden field value.

Here's the javascript function I used to add an item:

function add_item(item_number, item_name, amount, qty) {
    // item number
    var inp1 = document.createElement("input");
    inp1.setAttribute("type", "hidden");
    inp1.setAttribute("id", "item_number_"+curitem);
    inp1.setAttribute("name", "item_number_"+curitem);
    inp1.setAttribute("value", item_number);

    // item name
    var inp2 = document.createElement("input");
    inp2.setAttribute("type", "hidden");
    inp2.setAttribute("id", "item_name_"+curitem);
    inp2.setAttribute("name", "item_name_"+curitem);
    inp2.setAttribute("value", item_name);

    // amount
    var inp3 = document.createElement("input");
    inp3.setAttribute("type", "hidden");
    inp3.setAttribute("id", "amount_"+curitem);
    inp3.setAttribute("name", "amount_"+curitem);
    inp3.setAttribute("value", amount);

    // qty
    var inp4 = document.createElement("input");
    inp4.setAttribute("type", "hidden");
    inp4.setAttribute("id", "quantity_"+curitem);
    inp4.setAttribute("name", "quantity_"+curitem);
    inp4.setAttribute("value", qty);

    document.getElementById('payPalForm').appendChild(inp1);
    document.getElementById('payPalForm').appendChild(inp2);
    document.getElementById('payPalForm').appendChild(inp3);
    document.getElementById('payPalForm').appendChild(inp4);
    curitem++;
}

Paste the form code into your page and call the add item function:

add_item('001- New Product', 'New Product', 1, 1);

You won't see the product, but it will be there when you actually submit the form to paypal. This is really a bit of a hack, it's answers your question, but I would look into the paypal pro code. This should get you started.

shady
So, just so we're all clear: This js snippet adds new item number, name, amount (price), and quantity, appends these to the form, which are submitted to paypal together, and paypal will accept all these as separate products? Also, it's apparent that the number after the underscore ties each individual item order together. That's excellent, and exactly what I'm looking for. Why cant I find anything about this on paypal's site?
Peter
Try searching for "simple paypal integration" with google or bing or whatever you use. Don't look at the paypal documentation links, look at the development blog links.
shady