jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
651 stars 152 forks source link

CrossInAppBilling.Current.AcknowledgePurchaseAsync has error #527

Closed mohammadrezahamedi closed 1 year ago

mohammadrezahamedi commented 1 year ago

Hello this code await CrossInAppBilling.Current.AcknowledgePurchaseAsync(purchase.PurchaseToken); has this error 'IInAppBilling' does not contain a definition for 'AcknowledgePurchaseAsync', and no accessible extension method 'AcknowledgePurchaseAsync' accepting a first argument of type 'IInAppBilling' could be found I even tested this code
billingResult = await billingClient.AcknowledgePurchaseAsync(acknowledgePurchaseParams).ConfigureAwait(false); and this code: var consumePurchase = await CrossInAppBilling.Current.ConsumePurchaseAsync(purchase.PurchaseToken, ItemType.Subscription.ToString());

All of the returns false or null, and the purchase cancel after 3 minutes

How to fix that?

Version Number of Plugin: 6.7.0 Device Tested On: Android Version of VS: 2022

mohammadrezahamedi commented 1 year ago

Oh I think that was the solution :) var ack = await CrossInAppBilling.Current.FinalizePurchaseAsync(purchase.TransactionIdentifier).ConfigureAwait(false); Console.WriteLine(ack);

mohammadrezahamedi commented 1 year ago

I used this code to acknowledge the purchases, but all purchases are in the "Chargeable" status. Why?

jamesmontemagno commented 1 year ago

Correct in 6.X this API changed to FinalizePurchase.

Chargeable will be there if you are in test mode I am pretty sure. https://stackoverflow.com/questions/28014059/android-in-app-purchase-order-status-chargeable

mohammadrezahamedi commented 1 year ago

Hi james Thanks for your reply. But this is not about the developer test. I published the app as a production version, and I get the "Chargeable" status for every purchase the user makes.

Please take a look at my code and see there is any problem with it code this code calls every time that the app runs :

`
public async Task RestorePurchases(string productIdSub) { if (_isBusy) return; _isBusy = true;

        try
        {
            var connected = await CrossInAppBilling.Current.ConnectAsync();
            if (!connected)
                return;
            var purchases = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.Subscription);

            if (purchases != null)
            {
                var isSubscribed = purchases.Any(p => p.ProductId == productIdSub && p.State == Plugin.InAppBilling.PurchaseState.Purchased);
                var purchase = purchases.OrderByDescending(i => i.TransactionDateUtc).FirstOrDefault();

                if (isSubscribed)
                {
                    var ack2 = await CrossInAppBilling.Current.FinalizePurchaseAsync(purchase.TransactionIdentifier);//before checking if subscriber or not
                    if (purchase != null)
                    {
                        main.RunOnUiThread(() =>
                        {
                            PurchasedUI(purchase.Id, purchase.State.ToString());
                        });
                    }
                }
            }

        }
        catch (InAppBillingPurchaseException purchaseEx)
        {

            var purchaseError = purchaseEx.PurchaseError;

        }
        catch (Exception ex)
        {
            // Handle other exceptions here
        }
        finally
        {
            _isBusy = false;
            await CrossInAppBilling.Current.DisconnectAsync();

        }

    }

`