Вопрос

Okay so I am trying to set up payments in my app that I am developing, I have the dialog working and it confirms the purchase of the item. I have no idea what it does after here tbh, I have read articles after articles, but no joy. I need information on how I can update mysql database on the purchase. I know the question is vague, but any guidance will be appreciated!

The code i have so far is below.

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.

  }
}

Above is part of the payment callback

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

Above is what i need the payment to do.

Это было полезно?

Решение

It sounds like you're attempting to handle two very separate parts of the process at the same time in one file (your second code sample). The first code sample you posted (looks like their sample code, which is fine) is the proper place to award the user - your mysql query belongs inside the block which starts on line 43 (if ($current_order_status == 'placed') {). I'll leave the details of that for you to work out.

The second half of what you want to do (redirect the user to a confirmation page) does not belong in that callback, but rather on the page with the payment dialog. If you're using the sample code there as well, it belongs inside the js_callback function - try window.location.href='purchase_complete.php' (ensuring that this only happens on successful orders, ofc).

Hope that gets you pointed in the right direction!

Другие советы

else if ($request_type == "payments_status_update") {mysql_query("update users_table set payment_column='isok' where kulid like 'getFacebookUserId'");}    
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top