Skip to content

Instantly share code, notes, and snippets.

Created July 29, 2014 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9cee818dd6ad7a5f9f10 to your computer and use it in GitHub Desktop.
Save anonymous/9cee818dd6ad7a5f9f10 to your computer and use it in GitHub Desktop.
public class FacebookPay : MonoBehaviour{
public string ProductURL;
public int Quantity;
void OnMouseDown()
{
#if !UNITY_EDITOR
FB.Canvas.Pay(product: ProductURL,
action: "purchaseitem",
quantity: 1,
callback: PayCallback);
#else
MockResponse();
#endif
}
void MockResponse()
{
Invoke("GiveItem",1.5f);
}
void PayCallback(FBResult result)
{
if (result != null)
{
var response = Json.Deserialize(result.Text) as Dictionary<string, object>;
if(Convert.ToString(response["status"]) == "completed")
{
GiveItem();
}
else
{
// Payment Failed
}
}
}
void GiveItem()
{
// Implement your give item here
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment