2013-02-06 104 views
1

facebook付款對話框僅顯示信用點數,當我點擊購買信用而不是它應該轉到下一個對話框,它應該問我付款選項,它只是說您的購買成功。不知道我在做什麼嘗試了一切,但它不工作。facebook付款對話框不顯示本地貨幣對話框

這裏是我的javascript函數

function buy_tokens(p){ 

FB.init({appId: "myappid", status: true, cookie: true}); 

    var obj = { 
    method: 'pay', 
    action: 'buy_item', 
    order_info: {'item_id': 'tokens', 'price':p}, 
    dev_purchase_params: {'oscif': true} 
    }; 
    //FB.ui(obj, js_callback); 
    FB.ui(obj, function(paydata) { 
     // response back   
    }); 

} 

這裏是我的callback.php

<?php 

$facebook = new Facebook(array(
'appId' => APP_ID, 
'secret' => SECRET, 
'cookie' => true, 
)); 

$api_key = 'appid'; 
$secret = 'app secret'; 

// prepare the return data array 
$data = array('content' => array()); 

//parse signed data 
$request = parse_signed_request($_REQUEST['signed_request'], $secret); 

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

$payload = $request['credits']; 

// retrieve all params passed in 
$func = $_REQUEST['method']; 
$order_id = $payload['order_id']; 


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 sig 
$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, '-_', '+/')); 
} 


if ($func == 'payments_status_update') { 
$status = $payload['status']; 

// write your logic here, determine the state you wanna move to 
if ($status == 'placed') { 
$next_state = 'settled'; 
$data['content']['status'] = $next_state; 
} 
// compose returning data array_change_key_case 
$data['content']['order_id'] = $order_id; 
} else if ($func == 'payments_get_items') { 
// remove escape characters 
$order_info = stripcslashes($payload['order_info']); 
$item_info = json_decode($order_info, true); 
//Per the credits api documentation, 
//you should pass in an item reference 
// and then query your internal DB for the proper 
//information. Then set the item 
//information here to be returned to facebook 
//then shown to the user for confirmation. 

if($item_info['price']=='0.69'){ 
    $tokens = 150000; 
}elseif($item_info['price']=='1.49'){ 
    $tokens = 350000; 
}elseif($item_info['price']=='2.49'){ 
    $tokens = 600000; 
}elseif($item_info['price']=='3.99'){ 
    $tokens = 1000000; 
} 

$fb = $facebook->api('/me/?fields=currency'); 
$credit = round($item_info['price']*$fb[currency]  ['currency_exchange_inverse']*$fb[currency]['currency_offset']*$fb[currency] ['currency_exchange']); 
// $symbol = array('GBP'=>'£','EUR'=>'€','USD'=>'$'); 


if ($item_info['item_id'] != "") { 
$item['title'] = $tokens.' Tokens '; 
$item['price'] = $credit; 
$item['description']= 'You will get '.$tokens.' Tokens'; 
$item['image_url']='url'; 
$item['product_url']='url'; 
} 
//for url fields, if not prefixed by http:, 
//prefix them 
$url_key = array('product_url', 'image_url'); 
foreach ($url_key as $key) { 
if (substr($item[$key], 0, 7) != 'http://') { 
$item[$key] = 'http://'.$item[$key]; 
} 
} 
$data['content'] = array($item); 
} 

// required by api_fetch_response() 
$data['method'] = $func; 
echo json_encode($data); 

?> 

回答

0

的dev_purchase_params:{ 'oscif':真正}如果你不使用的測試參數只會工作考慮購買。嘗試使用未在應用設置中列爲付款測試工具的Facebook帳戶。

0

可以使用不是該應用程序的管理員/開發人員的任何其他帳戶進行試用,並且您將看到帶有貝寶和其他付款選項的付款對話框