The purchase flow depends on whether the store item is configured for game currency purchase (no sku) or in-app purchase (has sku). See Virtual Store purchases for details on how SKU configuration affects purchases.
This example shows how to handle both purchase types based on the store item’s configuration:
publicasyncTaskBuyStoreItem(EconomyListStoreItemstoreItem){if(string.IsNullOrEmpty(storeItem.Cost.Sku)){// Soft currency purchase - server deducts currency and grants rewardIEconomyPurchaseAckresult=await_economySystem.PurchaseStoreItemAsync(storeItem.Id);// Show reward animation UI.ShowRewardAnimationUI(result.Reward);// Your custom function.}else{// Hard currency purchase - requires platform IAP flowtry{varresult=await_unityPurchasingSystem.BuyProductByIdAsync(storeItem.Id);AnalyticsSendReceipt(result.receipt);// Your custom function.// Show reward animation UI.ShowRewardAnimationUI(storeItem.Reward);// Your custom function.}catch(PurchaseFailureExceptione){switch(e.Reason){caseUnityEngine.Purchasing.PurchaseFailureReason.UserCancelled:// Popup some UI.break;caseUnityEngine.Purchasing.PurchaseFailureReason.PaymentDeclined:// Popup some UI.break;caseUnityEngine.Purchasing.PurchaseFailureReason.ExistingPurchasePending:// Popup some UI.break;caseUnityEngine.Purchasing.PurchaseFailureReason.PurchasingUnavailable:caseUnityEngine.Purchasing.PurchaseFailureReason.ProductUnavailable:caseUnityEngine.Purchasing.PurchaseFailureReason.SignatureInvalid:caseUnityEngine.Purchasing.PurchaseFailureReason.DuplicateTransaction:caseUnityEngine.Purchasing.PurchaseFailureReason.Unknown:break;}}}}
Soft currency purchases will fail if the store item has a sku but you haven’t configured IAP validation on your server. Remove the sku from items that should only be purchasable with soft currency.