public void OnPurchaseFailed(Product product, PurchaseFailureReason p) { Debug.Log(string.Format("IAP::OnPurchaseFailed PurchaseFailureReason:{0}", p)); int purchaseType = 0; string udid = ""; #if UNITY_IOS || UNITY_IPHONE purchaseType = 1; //Apple Store EPlatformType.EPlatformType_AppStore udid = IOSUtil.iosGetOpenUDID(); #elif UNITY_ANDROID purchaseType = 2; //Google Play EPlatformType.EPlatformType_GooglePlay udid = AndroidUtil.GetOpenUDID(); #endif var transactionID = product.transactionID; var pid = product.definition.id; //Write cache FileBilling.Instance.ReadFile(); FileBilling.CReceiptInfo entry = new FileBilling.CReceiptInfo(); entry.RoleId = _roleId; entry.ProductId = pid; entry.BillingType = purchaseType; entry.IsSucceed = false; entry.TransactionId = transactionID; FileBilling.Instance.Update(purchaseType, entry); FileBilling.Instance.WriteFile(); PostVerifyData(_roleId, _roleId, purchaseType, pid, transactionID, udid, "", "", false, false); // Callback PURCHASE_INFO info = new PURCHASE_INFO(); info.iBillingType = purchaseType; info.strTransactionId = product.transactionID; _fnPurchaseCallback(false, info); }
public void BuyProductByID(int purchaseType, string orderId, string productId) { Debug.Log(string.Format("BuyProductByID: {0}", productId)); if (!IsInitialized()) { Debug.Log("BuyProductByID Failed! Not Initialized!"); PURCHASE_INFO info = new PURCHASE_INFO(); info.iBillingType = purchaseType; info.strOrderId = orderId; info.strProductId = productId; _fnPurchaseCallback(false, info); return; } Debug.Log("SDK::通用接口,直接开启订单"); Product product = _storeController.products.WithID(productId); if (product == null) { Debug.Log("product is null"); } if (product != null && product.availableToPurchase == false) { Debug.Log("product is not availableToPurchase"); } if (product != null && product.availableToPurchase) { Debug.Log(string.Format("直接开启订单: {0}", product.definition.id)); //开启支付 _storeController.InitiatePurchase(product, orderId); } }
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) { //获取并解析你需要上传的数据。解析成string类型 var wrapper = (Dictionary <string, object>)MiniJson.JsonDecode(e.purchasedProduct.receipt); if (null == wrapper) { return(PurchaseProcessingResult.Complete); } var store = (string)wrapper ["Store"]; //下面的payload 即为IOS的验证商品信息的数据。即我们需要上传的部分。 var payload = (string)wrapper ["Payload"]; // For Apple this will be the base64 encoded ASN.1 receipt var pid = e.purchasedProduct.definition.id; var transactionID = e.purchasedProduct.transactionID; int purchaseType = 0; string receipt = ""; string udid = OSUtility.GetOpenUDID(); string signature = ""; #if UNITY_IOS || UNITY_IPHONE purchaseType = 1; //Apple Store EPlatformType.EPlatformType_AppStore receipt = payload; Debug.Log(string.Format("PID = {0} Payload = {1}", pid, receipt)); #elif UNITY_ANDROID purchaseType = 2; //Google Play EPlatformType.EPlatformType_GooglePlay var gpDetails = (Dictionary <string, object>)MiniJson.JsonDecode(payload); receipt = (string)gpDetails["signature"]; // 服务器待验证 签名数据 signature = (string)gpDetails["json"]; // 服务器待验证 订单信息 #endif //Write cache FileBilling.Instance.ReadFile(); FileBilling.CReceiptInfo entry = new FileBilling.CReceiptInfo(); entry.RoleId = _roleId; entry.ProductId = pid; entry.IsSucceed = true; entry.BillingType = purchaseType; entry.Receipt = payload; entry.TransactionId = transactionID; FileBilling.Instance.Update(purchaseType, entry); FileBilling.Instance.WriteFile(); // Post receipt for verify bool bPostSucceed = PostVerifyData(_roleId, _roleId, purchaseType, pid, transactionID, udid, receipt, signature, false, true); PURCHASE_INFO info = new PURCHASE_INFO(); info.iBillingType = purchaseType; info.strTransactionId = transactionID; info.strProductId = pid; info.strReceipt = receipt; _fnPurchaseCallback(true, info); return(PurchaseProcessingResult.Complete); }