void OnBuyMobilePricePoint(MobilePricePoint pricePoint, CoinPackage priceData) { Util.Log("OnBuyCoins mobile priceid = " + pricePoint.id); activeCoinPackage = priceData; mainMenu.SetFullscreenMode(false); FB.Canvas.Pay(priceData.url, "purchaseitem", 1, pricepointId: pricePoint.id, callback: PaymentCallback); }
void BuyPackage(CoinPackage package) { // Play sound SoundManager.PlayButtonClick(); if (!Helper.IsOnline()) { Manager.Instance.ShowMessage(Settings.NoInternetConnection); return; } // Close popup Close(); // Purchase CompleteProject.Purchaser purchaser = GetComponent <CompleteProject.Purchaser>(); if (purchaser != null) { if (_purchaseCallback != null) { purchaser.BuyPackage(package, _purchaseCallback); } else { purchaser.BuyPackage(package, (purchasedPackage) => { //Debug.Log("Purchase finish: add " + purchasedPackage.GetCoins() + " coins"); NotificationManager.CoinChanged(UserData.Instance.Coin + purchasedPackage.GetCoins()); MyAdmob.Instance.isPurchased = true; PlayerPrefs.SetInt(MyAdmob.purchaseText, 1); }); } } }
void OnBuyCoins(CoinPackage priceData) { Util.Log("OnBuyCoins"); activeCoinPackage = priceData; mainMenu.SetFullscreenMode(false); FB.Canvas.Pay(priceData.url, "purchaseitem", 1, callback: PaymentCallback); }
// Prompt the user to purchase a virtual item with the Facebook Pay Dialog // See: https://developers.facebook.com/docs/payments/reference/paydialog public static void BuyCoins(CoinPackage cPackage) { // Format payment URL string paymentURL = string.Format(PaymentObjectURL, PaymentObjects[cPackage]); // https://developers.facebook.com/docs/unity/reference/current/FB.Canvas.Pay FB.Canvas.Pay(paymentURL, "purchaseitem", 1, null, null, null, null, null, (IPayResult result) => { Debug.Log("PayCallback"); if (result.Error != null) { Debug.LogError(result.Error); return; } Debug.Log(result.RawResult); object payIdObj; if (result.ResultDictionary.TryGetValue("payment_id", out payIdObj)) { string payID = payIdObj.ToString(); Debug.Log("Payment complete"); Debug.Log("Payment id:" + payID); // Verify payment before awarding item if (VerifyPayment(payID)) { GameStateManager.CoinBalance += (int)cPackage; GameStateManager.CallUIRedraw(); PopupScript.SetPopup("Purchase Complete", 2f); } } else { Debug.Log("Payment error"); } }); }
// Prompt the user to purchase a virtual item with the Facebook Pay Dialog // See: https://developers.facebook.com/docs/payments/reference/paydialog public static void BuyCoins (CoinPackage cPackage) { // Format payment URL string paymentURL = string.Format(PaymentObjectURL, PaymentObjects[cPackage]); // https://developers.facebook.com/docs/unity/reference/current/FB.Canvas.Pay FB.Canvas.Pay(paymentURL, "purchaseitem", 1, null, null, null, null, null, (IPayResult result) => { Debug.Log("PayCallback"); if (result.Error != null) { Debug.LogError(result.Error); return; } Debug.Log(result.RawResult); object payIdObj; if (result.ResultDictionary.TryGetValue("payment_id", out payIdObj)) { string payID = payIdObj.ToString(); Debug.Log("Payment complete"); Debug.Log("Payment id:" + payID); // Verify payment before awarding item if (VerifyPayment(payID)) { GameStateManager.CoinBalance += (int)cPackage; GameStateManager.CallUIRedraw(); PopupScript.SetPopup("Purchase Complete",2f); } } else { Debug.Log("Payment error"); } }); }
public void BuyPackage(CoinPackage package, Action <CoinPackage> callback) { _purchaseCallback = callback; if (package == CoinPackage.Package1) { BuyProductID(kProductIDConsumable1); } else if (package == CoinPackage.Package2) { BuyProductID(kProductIDConsumable2); } else if (package == CoinPackage.Package3) { BuyProductID(kProductIDConsumable3); } else if (package == CoinPackage.Package4) { BuyProductID(kProductIDConsumable4); } }
bool DeserializeCoinPackage(string text, ref CoinPackage coinPackage) { try { var data = Json.Deserialize(text) as Dictionary <string, object>; coinPackage.url = (string)data["url"]; List <object> prices = (List <object>)(((Dictionary <string, object>)(data["data"]))["price"]); foreach (object priceObj in prices) { var price = (Dictionary <string, object>)priceObj; coinPackage.price[(string)price["currency"]] = (double)(double)price["amount"]; } coinPackage.valid = true; Util.Log("coinPackage" + Convert.ToString(coinPackage.valid)); return(true); } catch (System.InvalidCastException e) { Util.Log("InvalidCastException"); Util.Log(e.Message); Util.Log(e.StackTrace); } catch (System.Collections.Generic.KeyNotFoundException e) { Util.Log("KeyNotFoundException"); Util.Log(e.Message); Util.Log(e.StackTrace); } catch (System.NullReferenceException e) { Util.Log("NullReferenceException"); Util.Log(e.Message); Util.Log(e.StackTrace); } return(false); }
public static int GetCoins(this CoinPackage package) { if (package == CoinPackage.Package1) { return(500); } if (package == CoinPackage.Package2) { return(3000); } if (package == CoinPackage.Package3) { return(6500); } if (package == CoinPackage.Package4) { return(14000); } return(0); }
bool DeserializeCoinPackage(string text, ref CoinPackage coinPackage) { try { var data = Json.Deserialize(text) as Dictionary<string,object>; coinPackage.url = (string)data["url"]; List<object> prices = (List<object>)(((Dictionary<string,object>)(data["data"]))["price"]); foreach (object priceObj in prices) { var price = (Dictionary<string,object>)priceObj; coinPackage.price[(string)price["currency"]] = (double)(double)price["amount"]; } coinPackage.valid = true; Util.Log("coinPackage" + Convert.ToString(coinPackage.valid)); return true; } catch(System.InvalidCastException e){Util.Log ("InvalidCastException"); Util.Log (e.Message);Util.Log (e.StackTrace);} catch(System.Collections.Generic.KeyNotFoundException e){Util.Log ("KeyNotFoundException"); Util.Log (e.Message);Util.Log (e.StackTrace);} catch(System.NullReferenceException e){Util.Log ("NullReferenceException"); Util.Log (e.Message);Util.Log (e.StackTrace);} return false; }
void OnBuyMobilePricePoint(MobilePricePoint pricePoint, CoinPackage priceData) { Util.Log("OnBuyCoins mobile priceid = " + pricePoint.id); activeCoinPackage = priceData; mainMenu.SetFullscreenMode(false); FB.Canvas.Pay(priceData.url, "purchaseitem",1, pricepointId:pricePoint.id, callback:PaymentCallback); }
void OnBuyCoins(CoinPackage priceData) { Util.Log("OnBuyCoins"); activeCoinPackage = priceData; mainMenu.SetFullscreenMode(false); FB.Canvas.Pay(priceData.url, "purchaseitem",1, callback:PaymentCallback); }