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

GetPurchasesAsync(ItemType.InAppPurchase) Fails #633

Open
brianbentwood opened this issue Oct 2, 2024 · 0 comments
Open

GetPurchasesAsync(ItemType.InAppPurchase) Fails #633

brianbentwood opened this issue Oct 2, 2024 · 0 comments

Comments

@brianbentwood
Copy link

The call to GetPurchasesAsync fails with the following on both the simulator and my device when using TestFlight. I have not yet tried it with the published app as I want to make sure this is fixed.

Exception thrown: 'Plugin.InAppBilling.InAppBillingPurchaseException' in System.Private.CoreLib.dll
Error: Plugin.InAppBilling.InAppBillingPurchaseException: Restore Transactions Failed
   at Plugin.InAppBilling.InAppBillingImplementation.GetPurchasesAsync(ItemType itemType)
   at Waldo.PurchasePage.RestoreItemsPurchased() in /Users/boggs/Documents/Phone Apps/Waldo/Waldo/PurchasePage.xaml.cs:line 482

Version Number of Plugin: 7.1.3
Device Tested On: iPhone 12 mini
Simulator Tested On: iPhone 15
Version of VS: 17.6.1 (device) and 17.5 (simulator)
Version of Xamarin: MAUI 1.3.29
Versions of other things you are using: .Net 8.0.401

Steps to reproduce the Behavior

Simply make the following call:
purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase);

I have both consumable and non-consumable product IDs. It fails with both. But also my thought is that I only need this for non-consumable since a past purchase of a consumable does not mean anything since they could have "consumed" it already.

NOTE: the documentation shows this function taking two parameters. The second one is "idsToNotFinish". However, there is no such occurrence of this function taking two parameters in the version I am using.

Expected Behavior

I expect the "purchase" object to either be empty or to include a list of the product IDs that have been purchased so that I can iterate through them and setup my UI properly.

Actual Behavior

The call to "GetPurchasesAsync receives the following error and I never get past this call.

Exception thrown: 'Plugin.InAppBilling.InAppBillingPurchaseException' in System.Private.CoreLib.dll
Error: Plugin.InAppBilling.InAppBillingPurchaseException: Restore Transactions Failed
   at Plugin.InAppBilling.InAppBillingImplementation.GetPurchasesAsync(ItemType itemType)
   at Waldo.PurchasePage.RestoreItemsPurchased() in /Users/boggs/Documents/Phone Apps/Waldo/Waldo/PurchasePage.xaml.cs:line 482

Code snippet

	public async Task<bool> RestoreItemsPurchased()
	{
		var billing = CrossInAppBilling.Current;
		try
		{
			IEnumerable<InAppBillingPurchase> purchases;
			var connected = await billing.ConnectAsync();

			if (!connected)
			{
				return false;
			}

			purchases = await billing.GetPurchasesAsync(ItemType.InAppPurchase);
			foreach (InAppBillingPurchase p in purchases)
			{
				//Set various controls in the UI
				SetControlsAfterPurchase(dictProducts.First(z => z.Value.ProductId.Equals(p.ProductId)).Key, false);
			}

			return true;
		}    
		catch (InAppBillingPurchaseException purchaseEx)
		{
			//Billing Exception handle this based on the type
			Debug.WriteLine("Error: " + purchaseEx);
			return false;
		}
		catch (Exception ex)
		{
			//Something has gone wrong
			return false;
		}
		finally
		{    
			await billing.DisconnectAsync();
		}
	}

Screenshotst

Screenshot 2024-10-02 at 3 34 48 PM
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