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 }