2009-08-02 57 views
1

我打算在社交网站上集成Google Checkout支付系统。这个想法是,会员可以购买真实货币(这是网站货币)的“代币”,然后他们可以购买访问网站上的一些额外内容等。很少Google结帐问题

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

本网站以PHP/MySQL编码。

我从这里下载了示例PHP代码:code.google.com/p/google-checkout-php-sample-code/wiki/Documentation

我知道如何创建一个谷歌Checkout按钮和我还将responsehandlerdemo.php文件放在我的服务器上。这是Google Checkout应该向其发送回复的文件(当然,我在Google商家帐户中设置了该文件的路径)。

现在,在响应处理程序文件存在与几个case语句的开关块。哪一个意味着支付是成功的,我可以将标记添加到本地数据库中的成员帐户中?

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; 

}

我想这种情况下, '带电' 是一个,对吗?

第二个问题,我需要一个SSL证书接收来自谷歌Checkout的反应呢?根据这个我做:groups.google.com/group/google-checkout-api-php/browse_thread/thread/10ce55177281c2b0

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

谢谢。

回答

5

我在6个月前将其整合到了我的网站中。这是非常低的量,但迄今为止工作良好。


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

请注意,您可能需要等待“风险 - 信息 - 通知”并确定风险检查是否在批准收费之前通过($ data [$ root] ['risk-information'] ['eligible-for - 防护 '] [' VALUE'])。虽然,似乎你在谈论数字商品,但退款的可能性可能与你无关。

在某一点上,我相信你也应该检查请求有足够的信息,为您的资金链接到一些帐户在充电之前,但也许这只是我的妄想。


我使用的另一种状态是'charge-amount-notification'。有一种方法可以使用'充电',但我没有'充电'提供实际充电的数额。 ($ amount_charged = $数据[$根] [ '总电荷量'] [ 'VALUE'];)


对于SSL,如果选中在其中输入回调URL它的位置声明如下:“指定网址为谷歌为了状态通知您的新订单和变化,您必须提供运行128位的SSLv3或TLS的服务器的URL”


回答您的评论: 我在'new_order_notification'下执行此操作,不确定您是否可以在别处执行此操作。

 
$items = get_arr_result($data[$root]['shopping-cart']['items']['item']); 
foreach($items as $item) { 
    if(!isset ($item['merchant-item-id']['VALUE'])) { 
    //error 
    return; 
    } 
    $request_item_id = $item['merchant-item-id']['VALUE']; 
    //save your item id with corresponding google order id for further processing 
} 
+0

谢谢,还有一件事。我如何访问商家项目ID(ID为手动设置项目与$ item-> SetMerchantItemId($ id)方法)。这会工作吗? $ order_id = $ data [$ root] ['merchant-item-id'] ['VALUE']; – 2009-08-03 11:49:42

1

是的,“收费”是您需要在Google Checkout订单中查看的第一件事。当您点击“收费”时,会弹出一个窗口,让您实际收取订单但是在实际收取订单之前请确保“合格保护”为真。这可确保您的付款被Google付款担保覆盖。您可以在Google Checkout的“买方信用验证”部分看到它。