void EventRevenue(PurchaseData data) { amplitude.logRevenue(data.iap.name, 1, data.iap.revenueUSD, data.receipt, data.signature); }
public virtual void Verify(PurchaseData data, Action <bool> callback) { }
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) { var iap = IAP.FromSKU(args.purchasedProduct.definition.id); if (iap == null) { Log("IAP - Purchase Failed. Unrecognized product: " + args.purchasedProduct.definition.id); iapManager.PurchaseFailed(); return(PurchaseProcessingResult.Complete); } Log($"IAP - Purchase Success: {args.purchasedProduct.definition.id}, Purchase Receipt: {args.purchasedProduct.receipt}"); // {"Store":"GooglePlay","TransactionID":"GPA.1365-0610-5320-80591","Payload":"{\"json\":\"{\\\"orderId\\\":\\\"GPA.1365-0610-5320-80591\\\",\\\"packageName\\\":\\\"com.sundaygames.rhymes\\\",\\\"productId\\\":\\\"com.sundaygames.rhymes.coins2\\\",\\\"purchaseTime\\\":1457679428830,\\\"purchaseState\\\":0,\\\"purchaseToken\\\":\\\"plfjeknfmgggeeoeplhcpccb.AO-J1Oyr-sBdnVXmUwD9JWdvYMXYsjQVVUbJ11HCIf5R6f6E0smmAVj4Lq_LoR79it8MBIc3j7FTN5i97f56UoViJ95k-R6ddJ-OjAxjoYybOsXzBoGGXuHbRBglLf1bJURFTNhYvBME8IbH0YS5Iags61ojxu1oIw\\\"}\",\"signature\":\"1GWVO1alYCTdu0Xxv+bNBNWtXiXX2XVyR+P6ItxWVPI0w7+a2c68AzpGpAVTRg6yXRTPdXX1NPt8pUlQW0vxhNEc2yRX\\/agEGx1CorFMBtNj1xJxiYyoZC85BD6+RU\\/2QnfbJXyPy\\/GzXARsdbFJMwGWmVw7ZzRMLFSEghIAjVCVHcammxgugpkzZcwEaipX6rb9G6ZsETvlBa3EosX+WukzGxiL0w1V4H0mb\\/VTcNqtejdD6akqrsbR\\/UvHcjETJQm1MKqv0K2UEog22HX4CxGCD1saFzxU0fhUTTjxYturLp8z312Qu3FmwTff+6QlPv9QwgPLRsiXC+0UmS9KvA==\"}"} var purchaseData = new PurchaseData(iap, transaction: args.purchasedProduct.transactionID); var payload = (Json.Deserialize(args.purchasedProduct.receipt) as Dictionary <string, object>)["Payload"] as string; if (platform == Platform.AppStore || platform == Platform.tvOS) { purchaseData.receipt = payload; } else if (platform == Platform.GooglePlay) { purchaseData.receipt = (Json.Deserialize(payload) as Dictionary <string, object>)["json"] as string; purchaseData.signature = (Json.Deserialize(payload) as Dictionary <string, object>)["signature"] as string; } else if (platform == Platform.WindowsPhone) { // Payload is an XML string as specified by Microsoft https://msdn.microsoft.com/en-US/library/windows/apps/windows.applicationmodel.store.currentapp.getappreceiptasync.aspx } if (build.serverPurchaseVerification) { server.VerifyPurchase(purchaseData, result => { if (result == true) { iapManager.PurchaseSucceed(purchaseData); } else if (result == false) { iapManager.PurchaseFailed(); } else { if (build.localPurchaseVerification) { LocalPurchaseVerification.Validate(args.purchasedProduct.receipt, purchaseData, success => { if (success) { iapManager.PurchaseSucceed(purchaseData); } else { iapManager.PurchaseFailed(); } }); } else { iapManager.PurchaseFailed(); } } }); return(PurchaseProcessingResult.Complete); } if (build.localPurchaseVerification) { LocalPurchaseVerification.Validate(args.purchasedProduct.receipt, purchaseData, success => { if (success) { iapManager.PurchaseSucceed(purchaseData); } else { iapManager.PurchaseFailed(); } }); return(PurchaseProcessingResult.Complete); } iapManager.PurchaseSucceed(purchaseData); return(PurchaseProcessingResult.Complete); }
public void VerifyPurchase(PurchaseData data, Action <bool?> callback) { var url = links.server; var request = new Dictionary <string, object>() { { "productId", data.iap.sku }, { "orderId", data.transaction }, { "deviceId", user.deviceId }, { "userId", user.id }, }; if (platform == Platform.AppStore || platform == Platform.tvOS) { url += links.verifyPurchaseApple; request.Add("base64EncodedReceipt", data.receipt); request.Add("debug", isDebug); } else if (platform == Platform.GooglePlay) { url += links.verifyPurchaseGoogle; request.Add("packageName", build.ID); request.Add("purchaseToken", (Json.Deserialize(data.receipt) as Dictionary <string, object>)["purchaseToken"]); request.Add("developerPayload", data.receipt); } RequestDict("Verify Purchase", url, request, download => { if (download.isSuccess && download.responseDict != null) { if (download.responseDict.ContainsKey("valid") && (bool)download.responseDict["valid"]) { callback?.Invoke(true); if (!string.IsNullOrEmpty(data.transaction)) { PlayerPrefs.SetString("Purchase " + data.transaction, "Success"); } } else { if (download.responseDict.ContainsKey("message")) { LogError("Server - Verify Purchase - Store Error: " + download.responseDict["message"]); } callback?.Invoke(false); if (!string.IsNullOrEmpty(data.transaction)) { PlayerPrefs.SetString("Purchase " + data.transaction, "Failed"); } } } else if (download.isCorrupted) { LogError("Server - Verify Purchase - Corrupted"); callback?.Invoke(false); } else { LogError("Server - Verify Purchase - Unknown Error"); callback?.Invoke(null); } }); }