开发人员响应-付款回调。PHP-让我发疯

开发人员响应-付款回调。PHP-让我发疯,php,facebook,facebook-graph-api,payment,facebook-credits,Php,Facebook,Facebook Graph Api,Payment,Facebook Credits,好的,我正在尝试在我正在开发的应用程序中设置付款,我有一个对话框,它确认购买该项目。我不知道在这里之后它会做什么,我读了一篇又一篇的文章,但没有乐趣。我需要关于如何在购买时更新mysql数据库的信息。我知道这个问题很模糊,但任何指导都将不胜感激 到目前为止,我的代码如下 if ($request_type == 'payments_get_items') { // Get order info from Pay Dialog's order_info. // Assumes order_

好的,我正在尝试在我正在开发的应用程序中设置付款,我有一个对话框,它确认购买该项目。我不知道在这里之后它会做什么,我读了一篇又一篇的文章,但没有乐趣。我需要关于如何在购买时更新mysql数据库的信息。我知道这个问题很模糊,但任何指导都将不胜感激

到目前为止,我的代码如下

if ($request_type == 'payments_get_items') {
  // Get order info from Pay Dialog's order_info.
  // Assumes order_info is a JSON encoded string.
  $order_info = json_decode($request['credits']['order_info'], true);

  // Get item id.
  $item_id = $order_info['item_id'];

  // Simulutates item lookup based on Pay Dialog's order_info.
  if ($item_id == '10Kremeggs') {
    $item = array(
      'title' => '10 Kremeggs',
      'description' => 'Spend Kremeggs in Alien Abduction.',
      // Price must be denominated in credits.
      'price' => 5,
      'image_url' => 'https://afternoon-snow-5267.herokuapp.com/images/bung.png',
      'product_url' => 'https://afternoon-snow-5267.herokuapp.com/Purchase/10xKremeggs.php'
    );

    // Construct response.
    $response = array(
                  'content' => array(
                                 0 => $item,
                               ),
                  'method' => $request_type,
                );
    // Response must be JSON encoded.
    $response = json_encode($response);
  }

} else if ($request_type == "payments_status_update") {
  // Get order details.
  $order_details = json_decode($request['credits']['order_details'], true);

  // Determine if this is an earned currency order.
  $item_data = json_decode($order_details['items'][0]['data'], true);
  $earned_currency_order = (isset($item_data['modified'])) ?
                             $item_data['modified'] : null;

  // Get order status.
  $current_order_status = $order_details['status'];

  if ($current_order_status == 'placed') {
    // Fulfill order based on $order_details unless...

    if ($earned_currency_order) {
      // Fulfill order based on the information below...
      // URL to the application's currency webpage.
      $product = $earned_currency_order['product'];
      // Title of the application currency webpage.
      $product_title = $earned_currency_order['product_title'];
      // Amount of application currency to deposit.
      $product_amount = $earned_currency_order['product_amount'];
      // If the order is settled, the developer will receive this
      // amount of credits as payment.
      $credits_amount = $earned_currency_order['credits_amount'];
    }

    $next_order_status = 'settled';

    // Construct response.
    $response = array(
                  'content' => array(
                                 'status' => $next_order_status,
                                 'order_id' => $order_details['order_id'],
                               ),
                  'method' => $request_type,
                );
    // Response must be JSON encoded.
    $response = json_encode($response);

  } else if ($current_order_status == 'disputed') {
    // 1. Track disputed item orders.
    // 2. Investigate user's dispute and resolve by settling or refunding the order.
    // 3. Update the order status asychronously using Graph API.

  } else if ($current_order_status == 'refunded') {
    // Track refunded item orders initiated by Facebook. No need to respond.

  } else {
    // Track other order statuses.

  }
}
以上是付款回调的一部分

<? mysql_query("UPDATE users SET Kremeggs = Kremeggs+10 WHERE Facebook_id = '$PurchaseUpdate'");
header ("Location: http://apps.facebook.com/alien_abduction/purchaseComplete.php");
?>
</body>
</html>

听起来您试图在一个文件(第二个代码示例)中同时处理流程的两个非常独立的部分。您发布的第一个代码示例(看起来像他们的示例代码,这很好)是奖励用户的合适位置-您的mysql查询属于从第43行开始的块(
if($current_order_status='placed'){
),我将把详细信息留给您解决

您想做的事情的后半部分(将用户重定向到确认页面)不属于该回调,而是属于带有付款对话框的页面。如果您也在使用示例代码,则它属于js_回调函数的内部-try
window.location.href='purchase\u complete.php'
(确保这只发生在成功的订单上,ofc)


希望这能为您指明正确的方向!

在此之前,我已经使用了第一部分,但暂时保留了第二部分,但这非常好,非常有效谢谢您:D
else if ($request_type == "payments_status_update") {mysql_query("update users_table set payment_column='isok' where kulid like 'getFacebookUserId'");}