1

I’m trying to integrate Facebook Credits as a paying method using the as3-sdk. I managed to get “earn_credits” and “buy_credits” working. However the third and most important option, “buy_item”, doesn’t show up the pay dialog. Somehow the connection to the callback.php seems the reason for the issue. Note: I have typed in the callback URL in my apps settings, so I didn’t forget that. I use the example php file from the Facebook Developer docs.

This is my as3 code.

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);

        }

I think the json encoding might be the problem, but i'm not sure.

I use the example php file from the Facebook Developer docs (excerpt):

<?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);
  }

Any help, is really appreciated.

2 Answers2

1

Okay so I cannot confirm that this works but according to this forum, it does:

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);

I see that this example differs from yours slightly on the AS3 side so hopefully this nfo will help you resolve your problem. I realize that this isn't the best way to go about answering questions but I can see after a couple of days on here, no one has a answered you so I figured anything could help at this point. :)

  • Thank you very much! I noticed, that you doesn't use a json encoded string. But the credits callback.php from the fb developers page expects the order_info to be a json encoded string. Do you know of a callback.php example a w/o the json code? – TicketToRide Apr 08 '12 at 13:22
  • I'm sorry I'll have to look into it more... like I said this isn't my solution and I haven't actually even tried this myself. –  Apr 08 '12 at 14:30
0

Thank you @Ascension Systems!

This worked out well and is much better than creating a pop-up via html, and using navigateToURL etc...

One caveat though, which caused your solution not to work for me initially:

If you are relying on the callback.php sample provided by Facebook ( at the end of this page: http://developers.facebook.com/docs/credits/callback/ ), then you need to add this tag to your order_info object:

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
};

Without item_id defined, the if statement in Facebook's callback.php ( if ($item_id == '1a') ... ) will fail, and you'll get an unpleasant window: "App Not Responding The app you are using is not responding. Please try again later."

andrewsi
  • 10,807
  • 132
  • 35
  • 51
Pascal S.
  • 41
  • 3