public static RegisterAndroidInAppPurchase ( IAPState purchaseState, string purchaseToken, string productId, string orderId, DateTime purchaseTime, string developerPayload, double price, string currency ) : void | ||
purchaseState | IAPState | |
purchaseToken | string | |
productId | string | |
orderId | string | |
purchaseTime | DateTime | |
developerPayload | string | |
price | double | |
currency | string | |
return | void |
private void GetSkuInfo(List <GooglePurchase> purchaseInfo, List <GoogleSkuInfo> skuInfo) { GoogleIABManager.queryInventorySucceededEvent -= GetSkuInfo; if (savedPurchase == null) { //Debug.LogError("FuseSDK_Prime31_IAB::GetSkuInfo - savedPurchase was null!"); return; } string priceString = skuInfo[0].price; double price = 0; try { price = double.Parse(priceString, NumberStyles.Currency); } catch { var re = new System.Text.RegularExpressions.Regex(@"\D*(?<num>[\d\s\.,]+?)(?<dec>([\.,]\s*\d?\d?)?)\D*$"); var match = re.Match(priceString); if (match.Success) { string stripped = ""; try { var dec = System.Text.RegularExpressions.Regex.Replace(match.Groups["dec"].Value, @"\s", ""); stripped = System.Text.RegularExpressions.Regex.Replace(match.Groups["num"].Value, @"[^\d]", "") + dec; price = double.Parse(stripped, NumberStyles.Currency); //Just in case the culture info is broken and double.Parse can't parse the decimal part properly if (price % 1 == 0 && dec.Length > 1) { price /= 100; } } catch { Debug.LogError("FuseSDK_Prime31_IAB::GetSkuInfo: Error parsing " + priceString + " >> Unable to parse " + stripped); } } else { Debug.LogError("FuseSDK_Prime31_IAB::GetSkuInfo: Error parsing " + priceString + " >> String did not match regex"); } } GooglePurchase purchase = savedPurchase; // purchaseTime from GoogleIAB is milliseconds since unix epoch DateTime time = new DateTime(purchase.purchaseTime * TimeSpan.TicksPerMillisecond, DateTimeKind.Utc); FuseSDK.RegisterAndroidInAppPurchase((FuseMisc.IAPState)purchase.purchaseState, purchase.purchaseToken, purchase.productId, purchase.orderId, time, purchase.developerPayload, price, null); savedPurchase = null; }
/// <summary>Records an in-app purchase in the Fuse system made using the Unity IAP plugin.</summary> /// <remarks> /// This function is meant to be called from Unity's IStoreListener.ProcessPurchase function passing in the /// purchasedProduct property of the PurchaseEventArgs parameter. /// </remarks> /// <param name="product">The product that was purchased.</param> public static void RegisterUnityInAppPurchase(Product product) { if (product == null) { return; } #if UNITY_ANDROID FuseSDK.RegisterAndroidInAppPurchase(FuseMisc.IAPState.PURCHASED, product.receipt, product.definition.storeSpecificId, product.transactionID, System.DateTime.Now, string.Empty, (double)product.metadata.localizedPrice, product.metadata.isoCurrencyCode); #elif UNITY_IOS FuseSDK.RegisterIOSInAppPurchase(product.definition.storeSpecificId, product.transactionID, System.Text.Encoding.UTF8.GetBytes(product.receipt), FuseMisc.IAPState.PURCHASED); #endif }
private void onMarketPurchase(PurchasableVirtualItem pvi, string payload, Dictionary <string, string> extra) { // pvi is the PurchasableVirtualItem that was just purchased // payload is a text that you can give when you initiate the purchase operation and you want to receive back upon completion // extra will contain platform specific information about the market purchase. // Android: The "extra" dictionary will contain "orderId" and "purchaseToken". // iOS: The "extra" dictionary will contain "receipt" and "token". #if UNITY_ANDROID string purchaseToken, orderId; if (!extra.TryGetValue("purchaseToken", out purchaseToken)) { purchaseToken = string.Empty; } if (!extra.TryGetValue("orderId", out orderId)) { orderId = string.Empty; } var item = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem; FuseSDK.RegisterAndroidInAppPurchase(FuseMisc.IAPState.PURCHASED, purchaseToken, item.ProductId, orderId, DateTime.Now, payload, item.Price, item.MarketCurrencyCode); #elif UNITY_IOS string token, receipt; if (!extra.TryGetValue("token", out token)) { token = string.Empty; } if (!extra.TryGetValue("receipt", out receipt)) { receipt = string.Empty; } var item = ((PurchaseWithMarket)pvi.PurchaseType).MarketItem; FuseSDK.RegisterIOSInAppPurchase(item.ProductId, token, System.Text.Encoding.UTF8.GetBytes(receipt), FuseMisc.IAPState.PURCHASED); #endif }
void purchaseSuccessful(PurchaseEvent e) { if (e != null) { //The Recipt is a json with the contents we need to pass in, parse it here JSONObject jObj = new JSONObject(e.Receipt); JSONObject json = new JSONObject(jObj.GetField("json").ToString().Replace("\\\"", "\"").Trim('"')); JSONObject sig = jObj.GetField("signature"); string sigstr = sig.ToString(); FuseLog("json = " + json.Print(true)); FuseLog("sig = " + sigstr); int purchaseState = 0; string purchaseToken = ""; string productId = ""; string orderId = ""; double purchaseTime = 0; json.GetField(ref purchaseState, "purchaseState"); json.GetField(ref purchaseToken, "purchaseToken"); json.GetField(ref orderId, "orderId"); json.GetField(ref productId, "productId"); json.GetField(ref purchaseTime, "purchaseTime"); double price = 0; try { price = double.Parse(e.PurchasedItem.localizedPriceString, NumberStyles.Currency); } catch { var re = new System.Text.RegularExpressions.Regex(@"\D*(?<num>[\d\s\.,]+?)(?<dec>([\.,]\s*\d?\d?)?)\D*$"); var match = re.Match(e.PurchasedItem.localizedPriceString); if (match.Success) { string stripped = ""; try { var dec = System.Text.RegularExpressions.Regex.Replace(match.Groups["dec"].Value, @"\s", ""); stripped = System.Text.RegularExpressions.Regex.Replace(match.Groups["num"].Value, @"[^\d]", "") + dec; price = double.Parse(stripped, NumberStyles.Currency); //Just in case the culture info is broken and double.Parse can't parse the decimal part properly if (price % 1 == 0 && dec.Length > 1) { price /= 100; } } catch { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> Unable to parse " + stripped); } } else { Debug.LogError("Fuse Unibill Tracking: Error parsing " + e.PurchasedItem.localizedPriceString + " >> String did not match regex"); } } FuseSDK.RegisterAndroidInAppPurchase((FuseMisc.IAPState)purchaseState, purchaseToken, productId, orderId, (long)purchaseTime, sigstr, price, null); } }