关于谷歌结帐商家私人数据的问题

时间:2011-02-08 19:54:13

标签: php google-checkout

我正在整合sample code

我想启用商家私有商品数据,以便我可以传递用户ID,期间和属性

我无法理解我该怎么做。

我的googlecheckout按钮在此处显示如下:。

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");

我是否必须在googlecart.php中启用它?

1 个答案:

答案 0 :(得分:0)

如果查看来源,您会看到GoogleItem::SetMerchantPrivateItemData,它只会设置GoogleItem::$merchant_private_item_data属性。检查GoogleItem::GetXML会显示GoogleItem::$merchant_private_item_data can be a MerchantPrivate(看似未实现,但只要有MerchantPrivate::AddMerchantPrivateToXML(gc_XmlBuilder $xml)方法就可以自己编写)或字符串(之后)传递htmlentities)成为merchant-private-item-data元素的内容。如果要使用XML构建私有数据,则必须实现类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);
    }
}