public SkuDetails(JSON json) { ItemType = json.ToString("itemType"); Sku = json.ToString("sku"); Type = json.ToString("type"); Price = json.ToString("price"); Title = json.ToString("title"); Description = json.ToString("description"); Json = json.ToString("json"); CurrencyCode = json.ToString("currencyCode"); StoreCountry = json.ToString("storeCountry"); PriceValue = json.ToString("priceValue"); Sku = OpenIAB_iOS.StoreSku2Sku(Sku); }
// Used for Android public SkuDetails(string jsonString) { var json = new JSON(jsonString); ItemType = json.ToString("itemType"); Sku = json.ToString("sku"); Type = json.ToString("type"); Price = json.ToString("price"); Title = json.ToString("title"); Description = json.ToString("description"); Json = json.ToString("json"); CurrencyCode = json.ToString("currencyCode"); StoreCountry = json.ToString("storeCountry"); PriceValue = json.ToString("priceValue"); ParseFromJson(); }
public SkuDetails(string json) { var j = new JSON(json); ItemType = j.ToString("itemType"); Sku = j.ToString("sku"); Type = j.ToString("type"); Price = j.ToString("price"); Title = j.ToString("title"); Description = j.ToString("description"); Json = j.ToString("json"); }
public SkuDetails(JSON json) { ItemType = json.ToString("itemType"); Sku = json.ToString("sku"); Type = json.ToString("type"); Price = json.ToString("price"); Title = json.ToString("title"); Description = json.ToString("description"); Json = json.ToString("json"); Sku = OpenIAB_iOS.StoreSku2Sku(Sku); }
} // 1, 2, 3.. ETC // Used for Android public SkuDetails(string jsonString) { /* * Explanation of what's happening: * The jsonString looks like this: * * { * "itemType": "subs", * "sku": "premium_subscription", * "type": "subs", * "price": "£2.99", * "title": "Premium Membership (Real Gangster - City Crime Simulator)", * "description": "Become a premium member to earn awesome daily rewards and an ad-free \nexperience!", * "json": "{ \"productId\":\"premium_subscription\", \"type\":\"subs\", \"price\":\"£2.99\", \"price_amount_micros\":2990000, \"price_currency_code\":\"GBP\", \"subscriptionPeriod\":\"P1W\", \"freeTrialPeriod\":\"P3D\", \"introductoryPriceAmountMicros\":1190000, \"introductoryPricePeriod\":\"P1W\", \"introductoryPrice\":\"£1.19\", \"introductoryPriceCycles\":1, \"title\":\"Premium Membership (Real Gangster - City Crime Simulator)\", \"description\":\"Become a premium member to earn awesome daily rewards and an ad-free \\nexperience!\" * }" * } * * Note how only itemType, sku, type, price, title and description are directly available * All the other values are within the "json" key */ var json = new JSON(jsonString); ItemType = json.ToString("itemType"); Sku = json.ToString("sku"); Type = json.ToString("type"); Price = json.ToString("price"); Title = json.ToString("title"); Description = json.ToString("description"); Json = json.ToString("json"); ParseFromJson(); }
private void ParseFromJson() { if (string.IsNullOrEmpty(Json)) { return; } var json = new JSON(Json); if (string.IsNullOrEmpty(PriceValue)) { float val = json.ToFloat("price_amount_micros"); val /= 1000000; PriceValue = val.ToString(); } if (string.IsNullOrEmpty(CurrencyCode)) { CurrencyCode = json.ToString("price_currency_code"); } }
private void ParseFromJsonIOS() { if (string.IsNullOrEmpty(Json)) { return; } var json = new JSON(Json); /* *"introductoryPriceValue\":0.00, * \"introductoryPriceFormatted\":\"\u00a30.00\", * \"introductoryPriceCycles\":\"1\", * \"introductoryPricePeriod\":\"week\", * \"subscriptionCycles\":\"7\", * \"subscriptionPeriod\":\"day\" */ bool isSubCyclesSet = int.TryParse(json.ToString("subscriptionCycles"), out int subCycles); bool isIntroCyclesSet = int.TryParse(json.ToString("introductoryPriceCycles"), out int introCycles); if (isSubCyclesSet) { string subPeriod = json.ToString("subscriptionPeriod"); ConvertToLongerPeriod(subCycles, subPeriod, out subCycles, out subPeriod); SubscriptionPeriod = ConvertToISO8601(subCycles.ToString(), subPeriod); // On iOS the free trial is within the introductory period FreeTrialPeriod = ""; if (isIntroCyclesSet) { string introPeriod = json.ToString("introductoryPricePeriod"); IntroductoryPriceValue = json.ToString("introductoryPriceValue"); IntroductoryPrice = json.ToString("introductoryPriceFormatted"); ConvertToLongerPeriod(introCycles, introPeriod, out introCycles, out introPeriod); IntroductoryPricePeriod = !string.IsNullOrEmpty(introPeriod) ? ConvertToISO8601(introCycles.ToString(), introPeriod) : ""; IntroductoryPriceCycles = introCycles.ToString(); } } }
private void ParseFromJson() { if (string.IsNullOrEmpty(Json)) { return; } var json = new JSON(Json); PriceValue = (json.ToFloat("price_amount_micros") / 1000000).ToString(); CurrencyCode = json.ToString("price_currency_code"); SubscriptionPeriod = json.ToString("subscriptionPeriod"); FreeTrialPeriod = json.ToString("freeTrialPeriod"); IntroductoryPriceValue = (json.ToFloat("introductoryPriceAmountMicros") / 1000000).ToString(); IntroductoryPrice = json.ToString("introductoryPrice"); IntroductoryPricePeriod = json.ToString("introductoryPricePeriod"); IntroductoryPriceCycles = json.ToString("introductoryPriceCycles"); Sku = json.ToString("productId"); }
public Purchase(JSON json) { if (json != null) { ItemType = json.ToString("itemType"); OrderId = json.ToString("orderId"); PackageName = json.ToString("packageName"); Sku = json.ToString("sku"); PurchaseTime = json.ToLong("purchaseTime"); PurchaseState = json.ToInt("purchaseState"); DeveloperPayload = json.ToString("developerPayload"); Token = json.ToString("token"); OriginalJson = json.ToString("originalJson"); Signature = json.ToString("signature"); AppstoreName = json.ToString("appstoreName"); Receipt = json.ToString("receipt"); // Catch will be hit if the Sku is already a product id try { Sku = OpenIAB_iOS.StoreSku2Sku(Sku); } catch (System.Collections.Generic.KeyNotFoundException) {} JSON receiptJson = AppleArrayToJSON(Receipt); if (receiptJson != null) { string purchaseInfo = receiptJson.ToString("purchase-info"); if (!string.IsNullOrEmpty(purchaseInfo)) { JSON purchaseInfoJson = AppleArrayToJSON(purchaseInfo); if (purchaseInfoJson != null) { string transactionId = purchaseInfoJson.ToString("original-transaction-id"); if (!string.IsNullOrEmpty(transactionId)) { Token = transactionId; } else { Debug.LogError("Failed to get transaction id"); } } else { Debug.LogError("Failed to get purchaseInfo JSON!"); } } else { Debug.LogError("Failed to get purchase info"); } } else { Debug.LogError("Failed to get receipt JSON!"); } } else { Debug.LogError("Null json!"); } }
/** * Create purchase from json string * @param jsonString data serialized to json */ public Purchase(string jsonString) { var json = new JSON(jsonString); ItemType = json.ToString("itemType"); OrderId = json.ToString("orderId"); PackageName = json.ToString("packageName"); Sku = json.ToString("sku"); PurchaseTime = json.ToLong("purchaseTime"); PurchaseState = json.ToInt("purchaseState"); DeveloperPayload = json.ToString("developerPayload"); Token = json.ToString("token"); OriginalJson = json.ToString("originalJson"); Signature = json.ToString("signature"); AppstoreName = json.ToString("appstoreName"); Receipt = json.ToString("receipt"); #if UNITY_IOS // Catch will be hit if the Sku is already a product id try { Sku = OpenIAB_iOS.StoreSku2Sku(Sku); } catch (System.Collections.Generic.KeyNotFoundException) { } JSON receiptJson = AppleArrayToJSON(Receipt); // Parse the iOS receipt token, converting it from Apple's own stupid format to normal JSON data along the way if (receiptJson != null) { string purchaseInfo = receiptJson.ToString("purchase-info"); if (!string.IsNullOrEmpty(purchaseInfo)) { JSON purchaseInfoJson = AppleArrayToJSON(purchaseInfo); if (purchaseInfoJson != null) { string transactionId = purchaseInfoJson.ToString("original-transaction-id"); if (!string.IsNullOrEmpty(transactionId)) { Token = transactionId; } else { Debug.LogError("Failed to get transaction id"); } } else { Debug.LogError("Failed to get purchaseInfo JSON!"); } } else { Debug.LogError("Failed to get purchase info"); } } else { Debug.LogError("Failed to get receipt JSON!"); } #endif }