2011-09-18 94 views
1

我刚开始熟悉Google Checkout API,但是我有一个问题。在Google Checkout文档中,提交实际购物车的唯一方法是通过一个通过echo呼叫创建的按钮,如echo $cart->CheckoutButtonCode("LARGE");这不是我所需要的。我想从我的PHP脚本手动提交我的购物车。Google Checkout PHP提交问题

但是,与PayPal API不同,Google Checkout脚本似乎没有提交类型功能。经过一些进一步的研究,我注意到HTML的例子发布到https://sandbox.google.com/checkout/api/checkout/v2/checkout/Merchant/MERCHANT_ID_HERE

我该如何在PHP中做到这一点?我正在使用他们的官方API。这是我迄今所做的:

$merchant_id = $google_merchant_ID; 
    $merchant_key = $google_merchant_key; 

    if ($enable_Google_Sandbox == 1) 
    { 
     $server_type = "sandbox"; 
    } 

    $currency = $currency_code; 
    $cart = new GoogleCart($merchant_id, $merchant_key, $server_type, 
    $currency); 

    $shop_cart = $_SESSION['cart']; 

    foreach ($shop_cart as $value) 
    {  
    $k_product = $value['Product']; 
    $k_quantity = $value['Quantity']; 
    $k_price = $value['Price']; 
    $k_orderID = $_SESSION['order_id']; 

    if (isset($_SESSION['Discount'])) 
    { 
     $k_discount = $_SESSION['Discount']; 

     $k_price = $k_price - $k_discount; 
    } 

    $cart_item = new GoogleItem($k_product, 
          "Some Product", 
          $k_quantity, 
          $k_price); 

    $cart_item->SetMerchantItemId(generateProductID()); 

    $cart->AddItem($cart_item); 
    } 

    // Specify <edit-cart-url> 
    $cart->SetEditCartUrl("http://192.168.100.100:8888/order.php?action=showCart"); 

    // Specify "Return to xyz" link 
    $cart->SetContinueShoppingUrl("http://192.168.100.100:8888/store.php"); 

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

有没有$cart->submitCart();型功能,所以我该怎么办?

回答

2
list($status, $error) = $cart->CheckoutServer2Server(); 

这应该可以解决您的问题。当你使用PHP API时,我可以推荐PHP demos。在this示例(DigitalUsecase())中演示了CheckoutServer2Server。 (digitalCart.php

CheckoutServer2Server文档:

/** 
* Submit a server-to-server request. 
* Creates a GoogleRequest object (defined in googlerequest.php) and sends 
* it to the Google Checkout server. 
* 
* more info: 
* {@link http://code.google.com/apis/checkout/developer/index.html#alternate_technique} 
* 
* @return array with the returned http status code (200 if OK) in index 0 
*    and the redirect url returned by the server in index 1 
*/ 
+0

感谢您详细的解答。然而,没有重定向到Google发生... – Pripyat

+0

出现错误:[0] => ERR [1] =>服务器内部错误 – Pripyat

+0

我正在使用旧的API。它适用于新的。我会尽快给你赏金。 – Pripyat