MAUI: Plugin.InAppBilling.InAppBillingPurchaseException: Invalid products found when querying product list

Sreejith Sreenivasan 851 Reputation points
2024-06-17T15:01:03.86+00:00

I am getting below exception when when I try to pay for a subscription for app store.

Plugin.InAppBilling.InAppBillingPurchaseException: Invalid products found when querying product list at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync(String productId, ItemType itemType, String applicationUserName) at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync(String productId, ItemType itemType, String obfuscatedAccountId, String obfuscatedProfileId, String subOfferToken)

I have created 3 subscriptions on the app store and all are in Ready to Submit state.

My Code:

UserDialogs.Instance.ShowLoading("");
if (IsBusy)
    return;

IsBusy = true;
try
{
    // check internet first with Essentials
    if (Connectivity.NetworkAccess != NetworkAccess.Internet)
        return;

    // connect to the app store api
    var connected = await CrossInAppBilling.Current.ConnectAsync();
    if (!connected)
        return;

    UserDialogs.Instance.HideHud();
    //try to make purchase, this will return a purchase, empty, or throw an exception
    var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.Subscription);

    if (purchase == null)
    {
        //nothing was purchased
        return;
    }

    if (purchase.State == PurchaseState.Purchased)
    {
        Debug.WriteLine("Purchase successfull");
        Debug.WriteLine("Purchase token:>>" + purchase.PurchaseToken);
        Debug.WriteLine("Purchase id:>>" + purchase.Id);
        
    }
    else
    {
        throw new InAppBillingPurchaseException(PurchaseError.GeneralError);
    }
}
catch (InAppBillingPurchaseException purchaseEx)
{
    // Handle all the different error codes that can occure and do a pop up
    Debug.WriteLine("purchaseEx:>>" + purchaseEx);
}
catch (Exception ex)
{
    // Handle a generic exception as something really went wrong
    Debug.WriteLine("exception:>>" + ex);
}
finally
{
    await CrossInAppBilling.Current.DisconnectAsync();
    IsBusy = false;
}

Am I miss any other set up for the proper working of this? Is there any permission do we need on the info.plist? I tested it on simulator, is it work on simulator or do we need to test it on a real device?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,223 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 29,306 Reputation points Microsoft Vendor
    2024-06-18T03:40:38.63+00:00

    Hello,

    Is there any permission do we need on the info.plist?

    No. Please make sure there is an Entitlements.plist file, see add an Entitlements.plist file. (You can also refer to this doc to create the provision profile) In-App Purchase will be automatically enabled in the Capabilities (app service).

    I tested it on simulator, is it work on simulator or do we need to test it on a real device?

    You must test In-App Purchase feature on your physical devices. Regard testing on a physical device, a provisioning profile is necessary, please select the App ID that you’ve set up for In-App Purchasing when you create the provisioning profile manually.

    (During the testing process, your app will prompt you to sign in the Apple ID)

    For more details, please see In-App Purchase Basics and Configuration in Xamarin.iOS - Xamarin | Microsoft Learn (This doc is about Xamarin, it applies to MAUI. The iTunes connect in the doc means Appstore connect)

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments