<?php
/*
 * ##################################################################
 * Created on: Jun 12, 2007
 * File name:  googlecheckout.php 
 * ##################################################################
 * This code is a sole property of netenberg.com 
 * ##################################################################
 */
$name = "Google checkout";
$googlecheckout = array (
                    array ("Merchant ID", "googlecheckout_id"), 
                    array ("Merchant Key", "googlecheckout_key"),
                    array ("Active", "active", "No", "Yes"),             
                    array ("Title", "title")
                 );
$send_method = "POST";
$pay = new googlecheckout($demo_mode);
/*
 * Class to do all google
 * Google Version 
 */
class googlecheckout
{
    /*
     * Constructor
     */
    function googlecheckout($demo_mode = 0)
    {
        $this->demo_mode = $demo_mode;
        $this->pay_url = "ipn.php";
    }
    /*
     * Function to send variables
     */
    function sendVariables($path_url, $pp_vals)
    {
        $this->pay_url= "https://checkout.google.com/cws/v2/Merchant/".$pp_vals['googlecheckout_id']."/checkout";
        if ($this->demo_mode == 1)
            $this->pay_url= "https://checkout.google.com/cws/v2/Merchant/".$pp_vals['googlecheckout_id']."/checkout/diagnose";
            
        $this->_POST1 = array ();
        $this->_POST1['item_number'] = time().rand(0, 1000);
        if (isset ($_POST['force_inv_no']))
        {
            $this->_POST1['item_number'] = $_POST['force_inv_no'];
        }
        $str = '<?xml version="1.0" encoding="UTF-8" ?> 
        <checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">
        <shopping-cart>
        <items>
        <item>
        <item-name>'.$_POST['desc'].'</item-name> 
        <item-description /> 
        <quantity>1</quantity> 
        <unit-price currency="USD">'.number_format($_POST['gross_amount'],2).'</unit-price> 
        </item>
        </items>
        <merchant-private-data>
        <merchant-note>'.$this->_POST1['item_number'].'</merchant-note>
        </merchant-private-data>
        </shopping-cart>
        <checkout-flow-support>
        <merchant-checkout-flow-support /> 
        </checkout-flow-support>
        </checkout-shopping-cart>';
          
        $this->_POST1['cart'] = base64_encode($str);
        $hashhmac = hash_hmac('sha1', $str, $pp_vals['googlecheckout_key'], TRUE);
        $this->_POST1['signature']= base64_encode($hashhmac);
    }
    /*
     * IPN=Internet Payment Notifier
     */
    function ipn(& $BL)
    {
        return false;
    }
}
?>