Jonathan Mall
Jonathan Mall

Reputation: 1

Facebook Credit Implementation is not working

I am developer and trying to implement FB credits in my app "mindmatcher". I created an app with name "mindmatcher" and then created two scripts as per the sample given here:

http://developers.facebook.com/blog/post/489/

You can access the page I created by clicking here:

http://apps.facebook.com/mindmatcher/testBeforeCallback.php

I have set the Call Back URL in the app settings.

This callback.php is also created as per the sample given on the above URL. But when I click on Pay Now FB button, it always shows error which can be seen by clicking on this URL:

"There Was a Problem Processing Your Payment

Sorry, but we're having trouble processing your payment. You have not been charged for this transaction. Please try again."

Need help to fix this issue asap because I need to make the app live very soon.

Thanks in advance.

Upvotes: 0

Views: 361

Answers (1)

Animesh
Animesh

Reputation: 11

You are missing the function given below.

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

Make sure that you call this function properly.

Upvotes: 1

Related Questions