【问题标题】:Few Google Checkout Questions几个 Google Checkout 问题
【发布时间】:2010-11-16 04:31:45
【问题描述】:

我计划在社交网站上集成 Google Checkout 支付系统。这个想法是,会员可以用真钱购买“代币”(这是一种网站货币),然后他们可以购买对网站上一些额外内容等的访问权。

我想做的是创建一个 Google Checkout 按钮,该按钮将会员带到结帐页面,他在该页面使用信用卡或借记卡付款。我想要的是 Google Checkout 通知我的服务器令牌购买是否成功(如果信用卡/借记卡已收费),以便我可以更新本地数据库。

网站使用 PHP/MySQL 编码。

我已从此处下载示例 PHP 代码:code.google.com/p/google-checkout-php-sample-code/wiki/Documentation

我知道如何创建 Google 结帐按钮,并且我还在我的服务器上放置了 responsehandlerdemo.php 文件。这是 Google Checkout 应该发送响应的文件(当然我在 Google 商家帐户中设置了文件的路径)。

现在在响应处理程序文件中有一个带有多个 case 语句的 switch 块。哪一项表示支付成功,我可以在本地数据库的会员账户中添加代币?

  switch ($root) {
case "request-received": {
  break;
}
case "error": {
  break;
}
case "diagnosis": {
  break;
}
case "checkout-redirect": {
  break;
}
case "merchant-calculation-callback": {
  // Create the results and send it
  $merchant_calc = new GoogleMerchantCalculations($currency);

  // Loop through the list of address ids from the callback
  $addresses = get_arr_result($data[$root]['calculate']['addresses']['anonymous-address']);
  foreach($addresses as $curr_address) {
    $curr_id = $curr_address['id'];
    $country = $curr_address['country-code']['VALUE'];
    $city = $curr_address['city']['VALUE'];
    $region = $curr_address['region']['VALUE'];
    $postal_code = $curr_address['postal-code']['VALUE'];

    // Loop through each shipping method if merchant-calculated shipping
    // support is to be provided
    if(isset($data[$root]['calculate']['shipping'])) {
      $shipping = get_arr_result($data[$root]['calculate']['shipping']['method']);
      foreach($shipping as $curr_ship) {
        $name = $curr_ship['name'];
        //Compute the price for this shipping method and address id
        $price = 12; // Modify this to get the actual price
        $shippable = "true"; // Modify this as required
        $merchant_result = new GoogleResult($curr_id);
        $merchant_result->SetShippingDetails($name, $price, $shippable);

        if($data[$root]['calculate']['tax']['VALUE'] == "true") {
          //Compute tax for this address id and shipping type
          $amount = 15; // Modify this to the actual tax value
          $merchant_result->SetTaxDetails($amount);
        }

        if(isset($data[$root]['calculate']['merchant-code-strings']
            ['merchant-code-string'])) {
          $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']
              ['merchant-code-string']);
          foreach($codes as $curr_code) {
            //Update this data as required to set whether the coupon is valid, the code and the amount
            $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
            $merchant_result->AddCoupons($coupons);
          }
         }
         $merchant_calc->AddResult($merchant_result);
      }
    } else {
      $merchant_result = new GoogleResult($curr_id);
      if($data[$root]['calculate']['tax']['VALUE'] == "true") {
        //Compute tax for this address id and shipping type
        $amount = 15; // Modify this to the actual tax value
        $merchant_result->SetTaxDetails($amount);
      }
      $codes = get_arr_result($data[$root]['calculate']['merchant-code-strings']
          ['merchant-code-string']);
      foreach($codes as $curr_code) {
        //Update this data as required to set whether the coupon is valid, the code and the amount
        $coupons = new GoogleCoupons("true", $curr_code['code'], 5, "test2");
        $merchant_result->AddCoupons($coupons);
      }
      $merchant_calc->AddResult($merchant_result);
    }
  }
  $Gresponse->ProcessMerchantCalculations($merchant_calc);
  break;
}
case "new-order-notification": {
  $Gresponse->SendAck();
  break;
}
case "order-state-change-notification": {
  $Gresponse->SendAck();
  $new_financial_state = $data[$root]['new-financial-order-state']['VALUE'];
  $new_fulfillment_order = $data[$root]['new-fulfillment-order-state']['VALUE'];

  switch($new_financial_state) {
    case 'REVIEWING': {
      break;
    }
    case 'CHARGEABLE': {
      //$Grequest->SendProcessOrder($data[$root]['google-order-number']['VALUE']);
      //$Grequest->SendChargeOrder($data[$root]['google-order-number']['VALUE'],'');
      break;
    }
    case 'CHARGING': {
      break;
    }
    case 'CHARGED': {
      break;
    }
    case 'PAYMENT_DECLINED': {
      break;
    }
    case 'CANCELLED': {
      break;
    }
    case 'CANCELLED_BY_GOOGLE': {
      //$Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'],
      //    "Sorry, your order is cancelled by Google", true);
      break;
    }
    default:
      break;
  }

  switch($new_fulfillment_order) {
    case 'NEW': {
      break;
    }
    case 'PROCESSING': {
      break;
    }
    case 'DELIVERED': {
      break;
    }
    case 'WILL_NOT_DELIVER': {
      break;
    }
    default:
      break;
  }
  break;
}
case "charge-amount-notification": {
  //$Grequest->SendDeliverOrder($data[$root]['google-order-number']['VALUE'],
  //    <carrier>, <tracking-number>, <send-email>);
  //$Grequest->SendArchiveOrder($data[$root]['google-order-number']['VALUE'] );
  $Gresponse->SendAck();
  break;
}
case "chargeback-amount-notification": {
  $Gresponse->SendAck();
  break;
}
case "refund-amount-notification": {
  $Gresponse->SendAck();
  break;
}
case "risk-information-notification": {
  $Gresponse->SendAck();
  break;
}
default:
  $Gresponse->SendBadRequestStatus("Invalid or not supported Message");
  break;

}

我猜是“CHARGED”这个案例,对吗?

第二个问题,我是否需要 SSL 证书才能接收来自 Google Checkout 的响应?根据这个我做:groups.google.com/group/google-checkout-api-php/browse_thread/thread/10ce55177281c2b0

但我在官方文档中没有看到任何地方提到它。

谢谢。

【问题讨论】:

    标签: php mysql curl payment-gateway google-checkout


    【解决方案1】:

    我在 6 个多月前将其集成到我的网站中。它的音量非常小,但到目前为止效果很好。


    您首先应该担心的是“CHARGEABLE”。这意味着信用卡已被批准用于交易,但在您采取行动之前它不会实际收取资金。为了发送充电请求,只需取消注释 CHARGEABLE 下的两行。您可以更改设置,使其在“设置”>“首选项”中自动向卡收费,但您也可以取消注释这两行并保持选项打开。

    请注意,您可能需要等待“风险信息通知”并确定风险检查是否通过,然后再批准收费 ($data[$root]['risk-information']['eligible-for-保护']['价值'])。虽然,您似乎在谈论数字商品,但退款的可能性对您来说可能并不重要。

    在某些时候,我相信您还应该检查该请求是否有足够的信息,以便您在收费之前将资金链接到某个帐户,但这也许只是我的偏执。


    我使用的另一个状态是“charge-amount-notification”。完全有可能使用“收费”的方法,但我不认为“收费”提供了实际收费的金额。 ($amount_charged = $data[$root]['total-charge-amount']['VALUE'];)


    对于 SSL,如果您检查输入回调 URL 的位置,则会显示以下内容: "为 Google 指定一个 URL,以通知您新订单和订单状态的变化。您必须提供运行 128 位 SSLv3 或 TLS 的服务器的 URL"


    回答您的评论: 我在“new_order_notification”下执行此操作,不确定您是否可以在其他地方执行此操作。

    $items = get_arr_result($data[$root]['shopping-cart']['items']['item'] ); foreach( $item 作为 $item ) { if( !isset ( $item['merchant-item-id']['VALUE'] ) ) { //错误 返回; } $request_item_id = $item['merchant-item-id']['VALUE']; //保存您的商品ID和相应的谷歌订单ID以供进一步处理 }

    【讨论】:

    • 谢谢,还有一件事。如何访问商家商品 ID(我使用 $item->SetMerchantItemId($id) 方法为商品手动设置的 ID)。这行得通吗? $order_id = $data[$root]['merchant-item-id']['VALUE'];
    • 我需要它来知道要更新本地数据库中的哪一行。
    • 再次感谢,这非常有帮助:) 如果可以的话,还有一个问题。 Hostgator 共享 SSL 对 responsehandler.php 文件是否足够好?还是必须买私人的?此外,responsehandler.php 是唯一需要使用 SSL 保护的文件,我不需要在其他页面上使用 SSL(我网站上的购物车等)。
    • 因为我的 responsehandler.php 似乎不起作用。我放在那里的任何代码都不会被执行。
    • 假设它满足 128 位 SSL v3 或 TLS 要求,我知道他们无法告诉他们它是共享的。我相信它也应该在沙箱上没有 SSL 的情况下工作。当您访问您的响应处理程序 URL 时,您会得到什么?
    【解决方案2】:

    是的,“收费”是您在 Google Checkout 订单中首先需要查看的内容。当您点击“Chargeable”时,会弹出一个窗口让您对订单进行实际收费请确保“Eligible for Protection”为真,然后才能实际对订单进行收费.这可确保您的付款受到 Google 付款保证的保护。您实际上可以在 Google Checkout 的“买家信用验证”部分中看到它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-30
      相关资源
      最近更新 更多