question on google checkout merchant private data

615 Views Asked by At

I'm integrating the sample code

I want to enable merchant-private-item-data,so that i can pass the userid,period and attribute

I'm not able to understand how do i do it .

My googlecheckout button appears here as given below.:

require_once($jconfig->gc_path.'/googlecart.php');
require_once($jconfig->gc_path.'/googleitem.php');
require_once($jconfig->gc_path.'/googleshipping.php');
require_once($jconfig->gc_path.'/googletax.php');

$merchant_id = "SAMPLE";  // Your Merchant ID
$merchant_key = "SAMPLE";  // Your Merchant Key
$server_type = "sandbox";
$currency = "USD";
$cart = new GoogleCart($merchant_id, $merchant_key, $server_type,
$currency); 
$total_count = 1;
$item_1 = new GoogleItem('title',      // Item name
                         'descriptiom', 
                         $price,
                         1); 
$cart->AddItem($item_1);
$cart->SetContinueShoppingUrl($jconfig->response_handler.$generate_url);

// Request buyer's phone number
$cart->SetRequestBuyerPhone(true);  

// Display Google Checkout button
//echo $this->product[0]['welcome_pack']+$this->product[0]['airport_pick_up']+$this->product[0]['airport_drop_off']+$this->product[0]['textbooks']+$totle;
echo $cart->CheckoutButtonCode("SMALL");

Do I have to enable it in googlecart.php?

1

There are 1 best solutions below

0
On

If you look at the source, you'll see a GoogleItem::SetMerchantPrivateItemData, which simply sets the GoogleItem::$merchant_private_item_data property. Examining GoogleItem::GetXML reveals GoogleItem::$merchant_private_item_data can be a MerchantPrivate (which appears to be unimplemented, but you can write your own as long as it has a MerchantPrivate::AddMerchantPrivateToXML(gc_XmlBuilder $xml) method) or a string, which (after a pass through htmlentities) becomes the content of the merchant-private-item-data element. If you want to structure your private data with XML, you'll have to implement class MerchantPrivate.

class MerchantPrivate {
    function AddMerchantPrivateToXML(gc_XmlBuilder $xml) {
        $xml->Push('merchant-private-item-data');
        $this->_addMyData($xml);
        $xml->Pop('merchant-private-item-data');            
    }

    abstract protected function _addMyData($xml);
}

class ItemData extends MerchantPrivate {
    public $userid, $period, $attribute;
    function _addMyData(gc_XmlBuilder $xml) {
        $xml->Element('userid', $this->userid);
        $xml->Element('period', $this->period);
        $xml->Element('attribute', $this->attribute);
    }
}