1

我試圖將Facebook Credits作爲使用as3-sdk的支付方式進行整合。我設法獲得「earn_credits」和「buy_credits」的工作。然而,第三個也是最重要的選項「buy_item」沒有顯示薪酬對話框。以某種方式連接到callback.php似乎是問題的原因。注意:我在我的應用程序設置中輸入了回調網址,所以我沒有忘記。我使用Facebook Developer文檔中的示例php文件。集成Facebook Credits與AS3-SDK

這是我的as3代碼。

public static function buyItem():void 
     { 
      var theAction:String = "buy_item"; 
      var order_info:Object = { "item_id":"1a" }; 
      var jOrder:String = JSON.encode(order_info); 
      var data:Object = { 
       action:theAction, 
       order_info:jOrder, 
       dev_purchase_params: {"oscif":true} 
      }; 

      Facebook.ui("pay", data, purchaseCallback); 

     } 

我認爲json編碼可能是問題,但我不確定。

我使用Facebook的開發者文檔(節選)的例子php文件:

<?php 

$app_secret = '***********************'; 

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

// Get request type. 
// Two types: 
// 1. payments_get_items. 
// 2. payments_status_update. 
$request_type = $_POST['method']; 

// Setup response. 
$response = ''; 

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 == '1a') { 
    $item = array(
     'title' => '100 some game cash', 
     'description' => 'Spend cash in some game.', 
     // Price must be denominated in credits. 
     'price' => 1, 
     'image_url' => '**********************/banner1.jpg', 
    ); 

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

任何幫助,真是感激。

回答

1

好了,所以我無法證實這個工作,但according to this forum,它的作用:

var title:String = "TITLE FOO"; 
var desc:String = "FOO"; 
var price:String = "200"; 
var img_url:String = [some image url]; 
var product_url:String = [some product url]; 

// create order info object 
var order_info:Object = { 
    "title":title, 
    "description":desc, 
    "price":price, 
    "image_url":img_url, 
    "product_url":product_url 
}; 


// calling the API ... 
var obj:Object = { 
    method: 'pay.prompt', 
    order_info: order_info, 
    purchase_type: 'item', 
    credits_purchase: false 
}; 

Facebook.ui('pay', obj, callbackFunction); 

我看到這個例子從你上稍微有些不同AS3側所以希望這NFO將幫助您解決您的問題。我意識到這不是回答問題的最好方式,但是在這裏幾天後我可以看到,沒有人回答你,所以我認爲在這一點上任何事情都可以提供幫助。 :)

+0

非常感謝!我注意到,你沒有使用json編碼的字符串,但fb開發者頁面中的creditsbacks callback.php期望order_info是一個json編碼的字符串。你知道一個callback.php例子aw/o的json代碼嗎? – TicketToRide 2012-04-08 13:22:45

+0

對不起,我不得不更多地研究它......就像我說的,這不是我的解決方案,我甚至沒有嘗試過我。 – 2012-04-08 14:30:20

0

謝謝@Ascension Systems!

這個結果不錯,比創建通過HTML彈出,並且使用的navigateToUrl等要好得多......

一個警告,雖然,這導致您的解決方案不是爲我工作開始:

如果你是依靠Facebook提供的callback.php樣品(在本頁面的結尾:http://developers.facebook.com/docs/credits/callback/),那麼你就需要把這個標記添加到您的order_info對象:

var item_id:String = "1a"; 

var order_info:Object = { 
    "title":title, 
    "description":desc, 
    "price":price, 
    "image_url":img_url, 
    "product_url":product_url, 
    "item_id":item_id 
}; 

沒有ITEM_ID定義的,如果在Facebook的ca llback.php(if($ item_id =='1a')...)將失敗,並且您將看到一個不愉快的窗口:「應用程序未響應 您正在使用的應用程序未響應。 「