Google Checkout PHP提交问题


Google Checkout PHP Submission Question

我刚刚开始熟悉Google Checkout API,但是有些事情我有一个问题。在Google Checkout文档中,提交实际购物车的唯一方法是通过echo调用创建的按钮,例如echo $cart->CheckoutButtonCode("LARGE");,但这不是我需要的。我想从我的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();类型函数,我该怎么办?

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

那应该能解决你的问题。当您使用PHP api时,我可以推荐PHP演示。本例(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
 */