Google Checkout PHP提交问题

时间:2011-09-18 10:39:35

标签: php

我刚刚开始熟悉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();类型的功能,所以我该怎么办?

1 个答案:

答案 0 :(得分:2)

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

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

CheckoutServer2Server docs:

/**
 * 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
 */