Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could you please explicitly specify that this plugin doesn't work with UWP -Subscriptions #524

Closed
devmathews opened this issue Feb 7, 2023 · 0 comments

Comments

@devmathews
Copy link

devmathews commented Feb 7, 2023

using YourOrg.Research;
using System.Diagnostics;
using Plugin.InAppBilling;

namespace YourAwesomeAppApp
{
internal class SubscriptionManager
{
private const string ProductId = "your_app_pro_monthly";

    public static async Task<bool> PurchaseSubscriptionAsync()
    {
        var billing = CrossInAppBilling.Current;
        try
        {
            var connected = await billing.ConnectAsync();
            if (!connected)
            {
                //we are offline or can't connect, don't try to purchase
                return false;
            }

            //check purchases
            var purchase = await billing.PurchaseAsync(ProductId, ItemType.Subscription);

            //possibility that a null came through.
            if (purchase == null)
            {
                //did not purchase
            }
            else if (purchase.State == PurchaseState.Purchased)
            {
                //purchased!
                if (DeviceInfo.Current.Platform == DevicePlatform.Android)
                {
                    //only needed on android unless you turn off auto finalize
                    var ack = await billing.FinalizePurchaseAsync(purchase.TransactionIdentifier);
                }

                CryptoCurrencyEngine.Instance.Settings.IsPremium = true;
                return true;
            }
        }
        catch (InAppBillingPurchaseException purchaseEx)
        {
            //Billing Exception handle this based on the type
            Debug.WriteLine("Error: " + purchaseEx);
        }
        catch (Exception ex)
        {
            //Something else has gone wrong, log it
            Debug.WriteLine("Issue connecting: " + ex);
        }
        finally
        {
            await billing.DisconnectAsync();
        }

        return false;
    }

    public static async Task<bool> CheckSubscriptionAsync()
    {
        var billing = CrossInAppBilling.Current;

        try
        {
            var connected = await billing.ConnectAsync();

            if (!connected)
            {
                //Couldn't connect
                return false;
            }

            //check purchases
            var purchases = await billing.GetPurchasesAsync(ItemType.Subscription);

            //check for null just incase
            if (purchases?.Any(p => p.ProductId == ProductId) ?? false)
            {
                //Purchase restored
                CryptoCurrencyEngine.Instance.Settings.IsPremium = true;
                return true;
            }
            else
            {
                //no purchases found
                return false;
            }
        }
        catch (InAppBillingPurchaseException purchaseEx)
        {
            //Billing Exception handle this based on the type
            Debug.WriteLine("Error: " + purchaseEx);
        }
        catch (Exception ex)
        {
            //.Logger.Error(ex);
            //Something has gone wrong
        }
        finally
        {
            await billing.DisconnectAsync();
        }

        return false;
    }
}

}

After days of research, it turns out this plugin fails win UWP Subscription. Rendering Null for var purchase = await billing.PurchaseAsync(ProductId, ItemType.Subscription); currently existing subscription at Microsoft store.

  1. Works on Android Store. - Subscription IDs created
  2. Fails for Microsoft store - Despite Subscription Product ID/Store ID submitted -as it returns null.

Used the above code and failed miserably when the users tried to subscribe to a "Monthly" subscription based add-on on Microsoft store. As it always returns null.

UWP Unsupported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant