Professional CodeIgniter

(singke) #1

Chapter 10: Launch


301


Integrating Checkout


Because Claudia is using Google Checkout as her preferred eCommerce vendor, you ’ re going to create a
very simple integration with Google ’ s HTML API. Essentially, the HTML API allows you to create a form
with hidden fields that designate products and their prices.

The names of the fields are important. Google Checkout is expecting fields that are named like this:

item_name_1
item_description_1
item_quantity_1
item_price_1

Obviously, if you have more than one product, you would need item_name_2 and so on. You can also
add some other fields for shipping:

ship_method_name_1
ship_method_price_1

For the purposes of this book (as opposed to working with a real, live customer), you ’ re going to assume
UPS Ground for shipping and a per - item cost of $5.00. You ’ ll be able to adjust this easily for anything
that you need to do.

Here ’ s the confirmorder view. It ’ s basically one big loop through the PHP session cart. Note that
anywhere you see “ change - this - now, ” you need to put in Claudia ’ s actual Merchant ID from Google.

< h1 > Please Confirm Your Order < /h1 >
< p > Please confirm your order before clicking the Buy Now button below. If you have
changes, < ?php echo anchor(“welcome/cart”, “go back to your shopping
cart”);? >. < /p >

< form method=”POST”
action=”https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/
change-this-now ”
accept-charset=”utf-8” >

< p >
< ?php
$TOTALPRICE = $_SESSION[‘totalprice’];

if (count($_SESSION[‘cart’])){
$count = 1;
foreach ($_SESSION[‘cart’] as $PID = > $row){
echo “ < b > ”. $row[‘count’]. “ “

. $row[‘name’]. “ @ “. $row[‘price’].” < br/ > ”;
echo “ < input type=’hidden’ name=’itemname”.$count
.”’ value=’”.$row[‘name’].”’/ > \n”;
echo “ < input type=’hidden’ name=’itemquantity”.$count
.”’ value=’”.$row[‘count’].”’/ > \n”;
echo “ < input type=’hidden’ name=’itemprice”.$count
.”’ value=’”.$row[‘price’].”’/ > \n”;
echo “ < input type=’hidden’ name=’itemcurrency”.$count

Free download pdf