Professional CodeIgniter, Thomas Myer
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.
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='item_name_".$count
."' value='".$row[`name']."'/
>
\n";
echo "
<
input type='hidden' name='item_quantity_".$count
."' value='".$row[`count']."'/
>
\n";
echo "
<
input type='hidden' name='item_price_".$count
."' value='".$row[`price']."'/
>
\n";
echo "
<
input type='hidden' name='item_currency_".$count
c10.indd 301
c10.indd 301
6/10/08 5:38:36 PM
6/10/08 5:38:36 PM