public void BuyProduct(ProductInfo productInfo) { if (iapAvailable != true) { OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE); return; } PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq { PriceType = productInfo.PriceType, ProductId = productInfo.ProductId, // ToDo : developer payload??? DeveloperPayload = "test" }; ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq); task.AddOnSuccessListener((result) => { if (result != null) { Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString()); Debug.Log("[HMSPlugin]: Bought " + purchaseIntentReq.ProductId); Status status = result.Status; status.StartResolutionForResult((androidIntent) => { PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent); Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode); Debug.Log("HMErrorMssg: " + purchaseResultInfo.ErrMsg); Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData); Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature); switch (purchaseResultInfo.ReturnCode) { case OrderStatusCode.ORDER_STATE_SUCCESS: OnBuyProductSuccess.Invoke(purchaseResultInfo); break; default: OnBuyProductFailure.Invoke(purchaseResultInfo.ReturnCode); break; } }, (exception) => { Debug.Log("[HMSPlugin]:startIntent ERROR"); }); } }).AddOnFailureListener((exception) => { Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message); }); }
void PurchaseInitentCreated(PurchaseIntentResult intentResult, ProductDefinition product) { if (intentResult == null) { storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.Unknown, "IntentIsNull")); return; } var status = intentResult.Status; status.StartResolutionForResult((androidIntent) => { PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent); switch (purchaseResultInfo.ReturnCode) { case OrderStatusCode.ORDER_STATE_SUCCESS: var data = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData); this.purchasedData[product.storeSpecificId] = data; this.productsByID.TryGetValue(product.storeSpecificId, out var productInfo); var receipt = EncodeReceipt(purchaseResultInfo.InAppPurchaseData, purchaseResultInfo.InAppDataSignature, ProductToJson(productInfo)); storeEvents.OnPurchaseSucceeded(product.storeSpecificId, receipt, data.OrderID); break; case OrderStatusCode.ORDER_PRODUCT_OWNED: storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.DuplicateTransaction, purchaseResultInfo.ErrMsg)); break; case OrderStatusCode.ORDER_STATE_CANCEL: storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.UserCancelled, purchaseResultInfo.ErrMsg)); break; default: storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.storeSpecificId, PurchaseFailureReason.Unknown, purchaseResultInfo.ErrMsg)); break; } }, (exception) => { storeEvents.OnPurchaseFailed(new PurchaseFailureDescription(product.id, PurchaseFailureReason.Unknown, exception.Message)); }); }
public void BuyProduct(string productID) { PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq(); ProductInfo productInfo = productInfoList.Find(product => product.ProductId == productID); purchaseIntentReq.PriceType = productInfo.PriceType; purchaseIntentReq.ProductId = productID; // ToDo : developer payload??? purchaseIntentReq.DeveloperPayload = "test"; ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq); InAppPurchaseData inAppPurchaseDataBean; task.AddOnSuccessListener((result) => { if (result != null) { Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString()); Debug.Log("[HMSPlugin]: Bought " + productID); Status status = result.Status; status.StartResolutionForResult((androidIntent) => { PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent); Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode); Debug.Log("HMErrorMssg: " + purchaseResultInfo.ErrMsg); Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData); Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature); switch (purchaseResultInfo.ReturnCode) { case OrderStatusCode.ORDER_STATE_CANCEL: // User cancel payment. Debug.Log("[HMS]: User cancel payment"); break; case OrderStatusCode.ORDER_STATE_FAILED: Debug.Log("[HMS]: order paymentf failed"); break; case OrderStatusCode.ORDER_PRODUCT_OWNED: Debug.Log("[HMS]: Product owned"); inAppPurchaseDataBean = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData); ConsumePurchase(inAppPurchaseDataBean.PurchaseToken); // to check if there exists undelivered products. break; case OrderStatusCode.ORDER_STATE_SUCCESS: // pay success. Debug.Log("[HMSPlugin]: PURCHASE SUCCESS"); String inAppPurchaseData = purchaseResultInfo.InAppPurchaseData; String inAppPurchaseDataSignature = purchaseResultInfo.InAppDataSignature; Debug.Log("HMS" + inAppPurchaseData); Debug.Log("HMS:" + inAppPurchaseDataSignature); //ToDO: use the public key of your app to verify the signature. // If ok, you can deliver your products. // If the user purchased a consumable product, call the consumeOwnedPurchase API to consume it after successfully delivering the product. // Consume purchase inAppPurchaseDataBean = new InAppPurchaseData(purchaseResultInfo.InAppPurchaseData); ConsumePurchase(inAppPurchaseDataBean.PurchaseToken); break; default: break; } }, (exception) => { Debug.Log("[HMSPlugin]:startIntent ERROR"); } ); } }).AddOnFailureListener((exception) => { Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message); }); }
public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true, string payload = "") { if (iapAvailable != true) { OnObtainProductInfoFailure?.Invoke(IAP_NOT_AVAILABLE); return; } PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq { PriceType = productInfo.PriceType, ProductId = productInfo.ProductId, DeveloperPayload = payload }; ITask <PurchaseIntentResult> task = iapClient.CreatePurchaseIntent(purchaseIntentReq); task.AddOnSuccessListener((result) => { if (result != null) { Debug.Log("[HMSIAPManager]:" + result.ErrMsg + result.ReturnCode.ToString()); Debug.Log("[HMSIAPManager]: Buying " + purchaseIntentReq.ProductId); Status status = result.Status; status.StartResolutionForResult((androidIntent) => { PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent); if (purchaseResultInfo.ReturnCode == OrderStatusCode.ORDER_STATE_SUCCESS) { Debug.Log("[HMSIAPManager] HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData); Debug.Log("[HMSIAPManager] HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature); OnBuyProductSuccess.Invoke(purchaseResultInfo); if (consumeAfter) { ConsumePurchase(purchaseResultInfo); } } else { switch (purchaseResultInfo.ReturnCode) { case OrderStatusCode.ORDER_STATE_CANCEL: Debug.LogError("[HMSIAPManager] User cancel payment"); break; case OrderStatusCode.ORDER_STATE_FAILED: Debug.LogError("[HMSIAPManager] order payment failed"); break; case OrderStatusCode.ORDER_PRODUCT_OWNED: Debug.LogError("[HMSIAPManager] Product owned"); break; default: Debug.LogError("[HMSIAPManager] BuyProduct failed. ReturnCode: " + purchaseResultInfo.ReturnCode + ", ErrorMsg: " + purchaseResultInfo.ErrMsg); break; } OnBuyProductFailure?.Invoke(purchaseResultInfo.ReturnCode); } }, (exception) => { Debug.LogError("[HMSIAPManager] startIntent ERROR"); }); } }).AddOnFailureListener((exception) => { Debug.LogError("[HMSIAPManager]: BuyProduct failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); }); }