Facebook Payer Promotion callback success or failure? - facebook

I'm trying to integrate Payer Promotions for our facebook game. I put a link to initiate payer promotion with js-sdk and created a callback function. using this sample:
<!-- Simple unit for Payer Promotion (payer_promotion)
Determine visibility of the unit from the above eligibility API -->
<button onclick="payer_promotion();">Payer Promotion</button>
<script>
// On load, the user hasn't clicked on the payer_promotion unit
var has_clicked = false;
var dialog_window;
function payer_promotion() {
if (!has_clicked) {
// If first click, open payer_promotion dialog
var obj = {
method: 'fbpromotion',
display: 'popup',
quantity: 10,
product: 'http://currency.object.url'
};
FB.ui(obj, function(){
// call back to your server to see if user's balance changed
});
// Mark unit as clicked by user
has_clicked = true;
} else {
// For subsequent clicks, alert user
alert("Payer Promotion already clicked!");
}
}
</script>
So everything works expected with my payment tester account and i claimed my free promotion... or so facebook says. once the transactions is completed and user closes the new popup facebook opened, I'm left with just a callback with no arguments and no idea whatever happened between facebook and the user. callback function has "// call back to your server to see if user's balance changed" comment but since facebook changed to local currency I'm doing payment processing locally with order_id (not facebook->my server it used to be). So if I don't get order_id I have no means to figure out if I should process the promotion or not.
The question is, am I missing something? is there a way to figure out if the promotion succeeded or not?

Related

How to bind Facebook onlogin event to customized button?

I know how to use custom button as Facebook login.
Now I'd like to bind onlogin event to customized button, but I don't know how to do.
Original code
<fb:login-button scope="public_profile,email" onlogin="afterLogin();">
</fb:login-button>
<script>
/* Assume that Facebook SDK loaded asyncronously and initilized */
function afterLogin() {
// Do stuff
}
</script>
My code
<button id="cusomized-button" onclick="fbLogin();" onlogin="afterLogin();">
Customized button
</button>
<script>
/* Assume that Facebook SDK loaded asynchronously and initialized */
// Show facebook login modal
function fbLogin() {
FB.login(function() {}, {
scope: 'email,public_profile'
});
};
function afterLogin() {
// Do stuff
}
</script>
Assuming you use version 2.4 of the Graph API, you are able to subscribe to an event called auth.login which is fired whenever the login status changes.
So, if you want to react to when the user logs in, you can do this and your function named afterLogin would be called once the user logs in to your app:
FB.Event.subscribe('auth.login', afterLogin);
Do note that Facebook recommends everyone to listen to auth.statusChange instead, otherwise your application will not know if the user has logged out or deauthorized the application, which would invalidate the token.
Here's an example using auth.statusChange, the response argument passed to the function contains a response object which is detailed here:
FB.Event.subscribe('auth.statusChange', function(response) {
if(response.status === 'connected') {
// `connected` means that the user is logged in and that your app is authorized to do requests on the behalf of the user
afterLogin();
} else if(response.status === 'not_authorized') {
// The user is logged in on Facebook, but has not authorized your app
} else {
// The user is not logged in on Facebook
}
});
As an alternative, the first argument to FB.login is a function which is called after the user returns from Facebook, so you could do something like this:
FB.login(function(response) {
if (response.authResponse) {
afterLogin();
} else {
// The user cancelled the login or did not authorize your app
}
}, {
scope: 'email,public_profile'
});
Here's an alternative using onlogin() in the way you originally wanted.
There's a subtle reason why you may need this:
You are using Facebook login just as a way to login to your own website
User is already connected (has previously connected to your FB)
User is NOT logged into your website.
You don't want to magically log someone in just because they're 'connected' It's not a good user experience.
So you show them the 'Login' button and once clicked you log the user in locally (provided you've established a linkage before).
In that case you do the following in the button code.
onlogin="window.fbOnLogin()"
Then depending upon your environment, somewhere in your code you would need to create a function on window. I'm using an Angular service and doing the following. This is typescript, so omit the <any> part if you're using pure JS.
constructor()
{
// Pure JS
// window.fbOnLogin = this.onLogin;
// Typescript (use lambda to keep 'this')
(<any>window).fbOnLogin = () => this.onLogin();
}
onLogin() {
call_my_server_to_login(token);
alert('Thanks for logging in with Facebook');
}
Now you can display the button to the user (and you secretly already know they're a user because the auto.authResponseChange event (or FB.getLoginStatus()) has told you they are "connected".
Note: None of the events, including auth.login will actually get triggered if you just click the button.
Once they click it FB returns immediately (becuase you're already logged in and connected) and calls your function. You then login the user your own website (you have to do a server side lookup to make sure they already logged in before). If you don't know who the user is then you have to do one of those 'associate your username' pages.

Why do I get this warning message on my facebook login page?

I'm trying the Facebook login API for the first time on a web app deployed locally.
I init the API with the snippet in their documentation and have a button on my HTML page
<button type="button" onclick="fbLogin()">
Where fbLogin() is
function fbLogin() {
FB.login(function(response) {
console.log(response);
// handle the response
if (response.status === 'connected') {
// Logged into your app and Facebook.
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
}
}, {scope: 'public_profile,email,user_friends'}); // TODO: If the user doens't provide the email address prompt it for email. Also, don't ask for friend list when its a simple logout maybe? Specify why it's needed first. If it doesn't provide the friends access, re-prompt the request, explaining him it can have a more social experience if he accepts (can see when its friends win and congratulate with them, (we can also prom him to invite some friends))
}
When I try to log in the message
"You are using a display type of 'popup' in a large browser window or tab. For a better user experience, show this dialog with our JavaScript SDK without specifying an explicit display type. The SDK will choose the best display type for each environment. Alternatively, set height and width on your window.open() call to properly size this dialog if you have special requirements precluding you from using the SDK. This message is only visible to developers of your application."
shows up.
Screenshot
As you can see though, I am not specifying any specific display type; so I really don't know what to do with this message.
Other Google entries didn't have a solution for this problem.
What action do I need to take in order to remove it?

New facebook payment flow "App not allowed to use new flow."

I've been attempting to implement the new facebook payment flow for local currency as per their documentation (https://developers.facebook.com/docs/howtos/payments/)
Have the company set up, have the product set up, have the payment FB.ui call set up, have the payments callback set up as required for it.
The issue I have is as soon as I call the FB.ui method to invoke a pay dialogue I get the error "Your Action Could Not Be Processed" on screen. Then once I hit ok my javascript callback gets the error message "App not allowed to use new flow." error code "1383005". I can't seem to find any help about this error message or error code (the error code is listed as "PermissionDenied - Facebook system issue" in the Error codes section). My question is am I missing something? There is nothing I can see in the docs that tells me how to allow my app to use the new flow or even telling me that I have to.
My payment dialogue code just in case:
var purchaseProduct = function (productUrl, callback) {
var obj = {
method: 'pay',
action: 'purchaseitem',
product: productUrl
};
FB.ui(obj, function(response) {
callback(response);
});
};
(The quantity and request_id parameters are optional)
Thanks

Facebook new payer promotion not working

Facebook new payer promotion spec at https://developers.facebook.com/docs/payments/payer_promotion/#user_eligibility
says it will return 1 if user is eligible, and nothing if not.
But, this code in PHP:
$fbdata = $facebook->api('/me?fields=id,locale,third_party_id,is_eligible_promo');
returns is_eligible_promo => '1';
But when i use that query on Graph API explorer, or with JavaScript:
FB.api('/me?fields=id,locale,third_party_id,is_eligible_promo', function(response) {});
it doesn't return is_eligible_promo field.
Also, calling this payement popup:
var obj = {
method: 'fbpromotion',
display: 'popup',
package_name: 'zero_promo',
product: '---my-open-graph-currency---'
};
FB.ui(obj, function() {});
, it returns something like "Sorry, the promotion is currently unavailable.".
But when i use that query on Graph API explorer, or with JavaScript […] it doesn't return is_eligible_promo field.
I think this is an access_token issue – whether a player is eligible for a promotion depends on the individual app, I guess.
Try choosing your own app in the Graph API explorer (dropdown on the upper right), and see if then you get the same result as from within your PHP script.
It resolved that user_is_eligible depends on IP of the user requests.
Since my servers are in country A, php request from that server to facebook returned that user is eligible. But when i request same params with javascript (i'm in country B), facebook says that user is not eligible.
Fixed this by moving all checks to javascript since it depends on user location.

"Request Dialog" requestCallback when clicking Cancel or Close button

I am new into Facebook application development and also newbie about JavaScript and PHP programming.
I currently developing a Facebook application but currently stuck with Request Dialog window.
When the Request Dialog appears, I choose friends I want and then click "Send Requests", the requestCallback(response) are executed and friends who getting requests are notified as expected. But, If I click "Cancel" or the blue-colored close button, the requestCallback(response) is also executed but selected friends are not getting notified about the request.
Here is my code:
function requestCallback(response)
{
//console.log(response);
location.href='step2.php';
}
So, whether I click "Cancel" or close button, the script above are still executed (moving to page step2.php I specify.)
What I want is when the user clicking cancel button or close modal window button, the page stay at the same page.
Anyone know how to solve this problem?
Thanks!
You can just check what's inside the Facebook response object, because it won't be the same if requests have been sent or not !
Something like :
function requestCallback(response)
{
if(response && response.request_ids) {
// Here, requests have been sent, facebook gives you the ids of all requests
//console.log(response);
location.href='step2.php';
} else {
// No requests sent, you can do what you want (like...nothing, and stay on the page).
}
}
Or if you are using the new structure (Request 2.0 Efficient):
function requestCallback(response)
{
if(response && response.request) {
// Here, requests have been sent, facebook gives you the request and the array of recipients
//console.log(response);
location.href='step2.php';
} else {
// No requests sent, you can do what you want (like...nothing, and stay on the page).
}
}
Look at the structure of the response object to make your condition. The callback is fired even when you hit close in order to have the possibility to notice when your user quits the dialog. It's up to you to verify if he sent requests, and act like you want ! :)
Also, something important :
Facebook updated their request system a few weeks ago, making available "Requests 2.0" in your apps settings. It's turned off by default, but if you activate it, the structure of the response object when sending requests to people will change. So you'd have to update your condition in the callback !
Everything is explained here :
http://developers.facebook.com/blog/post/569/