Created
July 29, 2014 17:23
-
-
Save anonymous/9cee818dd6ad7a5f9f10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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