查找facebook本地货币回调

查找facebook本地货币回调,facebook,callback,facebook-php-sdk,payment,Facebook,Callback,Facebook Php Sdk,Payment,在将本地货币集成到我的应用程序时,我在理解如何使用回调时遇到了一个小问题 基本上,我正在寻找的是负责数据库更新的代码部分。确认付款的地点 代码如下: $app_secret = ''; // Validate request is from Facebook and parse contents for use. $request = parse_signed_request($_POST['signed_request'], $app_secret); // Get request typ

在将本地货币集成到我的应用程序时,我在理解如何使用回调时遇到了一个小问题

基本上,我正在寻找的是负责数据库更新的代码部分。确认付款的地点

代码如下:

$app_secret = '';

// Validate request is from Facebook and parse contents for use.
$request = parse_signed_request($_POST['signed_request'], $app_secret);

// Get request type.
$request_type = $_POST['method'];

// Setup response.
$response = '';

if ($request == null) {
// handle an unauthenticated request here
}

if ($request_type == 'payments_get_item_price') {
// Retrieving the user's info
$user_currency = $request['payment']['user_currency'];
$user_country = $request['user']['country'];

// Here we verify the product by passing back the URL of the OG product
$item['product'] = $request['payment']['product'];

// This is the quantity passed from the JS call to render the pay dialog.
// This parameter is optional and defaults to 1.
$quantity = $request['payment']['quantity'];

// Based on the user's currency and country, we set the price.
// We use fixed values here for testing.
  switch($user_currency) {
  case 'EUR':
      $item['amount'] = 2.99;
      $item['currency'] = 'EUR';
      break;
      case 'GBP':
      $item['amount'] = 2.49;
    $item['currency'] = 'GBP';
    break;
case 'BRL':
    $item['amount'] = 6.99;
    $item['currency'] = 'BRL';
    break;
// Here we default to USD. If a user's preferred currency is different than one
// that you specify, we will convert from the developer provided currency
// and amount to a new amount in the user's currency. You can choose whatever
// default currency works best for you.
default:
    $item['amount'] = 3.99;
    $item['currency'] = 'USD';
    break;
 }

 // Optionally, you may also choose to override the quantity_min / quantity_max values
  // which were passed in when invoking the Pay Dialog.
   $item['quantity_min'] = 1;
  $item['quantity_max'] = 100;

  // Optionally, it's also possible to override the OG product object's title, 
  // plural_title and description.
  $item['title'] = 'Override Title';
  $item['plural_title'] = 'Override Title Plural';
  $item['description'] = 'Override Description';

  // Finally we add the item information to the response 'content'
  $response['content'] = $item;
}

// Return the identical method
$response['method'] = $request_type;

// Send data back
echo json_encode($response);

// You can find the following functions and more details
// on https://developers.facebook.com/docs/authentication/canvas
function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2);

  // Decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check signature
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
  }
  return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

您需要首先在应用程序设置中设置回拨url,
yourdomain.com/mycallback.php
当购买或取消时,Facebook将发布到该页面

参考:


一旦完成,Facebook将返回订单客户端的订单id,您可以使用graph api检查订单并执行更新


另一种解决方案是“实时更新”,我还没有完全理解。

这是不正确的,因为在以当地货币进行的静态支付中,回拨url不再是facebook的呼叫,只在动态定价时,它将使用您的回拨url。我将更新我的回答,以反映付款的最新变化,但你仍然可以在应用程序设置中禁用该更改。。
$request_type = $_POST['method'];  // catches the post from facebook with purchase info.