예제 #1
0
    public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    {
        // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
        // this reason with the user to guide their troubleshooting actions.
        Debug.Log(
            $"OnPurchaseFailed: FAIL. Product: '{product.definition.storeSpecificId}', PurchaseFailureReason: {failureReason}");

        // When purchase fail due to duplicate transaction, and the item is not shown in client side,
        // do restore purchase to fetch the product.
        // This situation may happen when the user lose internet connection after paying to play store.
        if (failureReason == PurchaseFailureReason.DuplicateTransaction)
        {
            _playStoreExtensions.RestoreTransactions(null);
        }
    }
예제 #2
0
        //*******************************************************************
        // RESTORE
        //*******************************************************************
        /// <summary>
        /// Restore purchases
        /// (GooglePlay is automatic after Init)
        /// </summary>
        public async UniTask RestorePurchasesAsync(Action <PurchaseResponse> onDone = null)
        {
            if (!IsInit)
            {
                Debug.LogWarning("Cannot restore purchases. IAPManager not successfully initialized!");
                onDone(PurchaseResponse.NoInit);
                return;
            }

            bool isProcessing = true;

            googlePlay.RestoreTransactions(result => {
                DebugLog($"googlePlay.RestoreTransactions result = {result}");

                // still waiting for result.
                if (onDone != null)
                {
                    if (result)
                    {
                        onDone(PurchaseResponse.Ok);
                    }
                    else
                    {
                        DebugLog("Restore process rejected.");
                        onDone(PurchaseResponse.Unknown);
                    }
                }

                isProcessing = false;
            });

            await UniTask.WaitWhile(() => isProcessing);
        }