jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Play In-Apps are always refunded after 3 days in Xamarin.Android/.NET 8

FANMixco opened this issue · comments

If you are creating an issue for a BUG please fill out this information. If you are asking a question or requesting a feature you can delete the sections below.

Failure to fill out this information will result in this issue being closed. If you post a full stack trace in a bug it will be closed, please post it to http://gist.github.com and then post the link here.

Bug Information

Version Number of Plugin: 7.1.0
Device Tested On: Oppo A91
Simulator Tested On: Android 14/Pixel 4
Version of VS: 2022
Version of Xamarin: .NET 8
Versions of other things you are using: .NET 8

Steps to reproduce the Behavior

I have built an app originally with Xamarin.Android. I recently migrated it to .NET 8, but I noticed that a couple of days after the users had paid, I lost the sales since they were auto-refunded. I read in some forums that I had to acknowledge the payment, so, I added some code that I guess it should do that:

const string PRODUCT_ID = "my.product.com";
const string PRODUCT_ID_MORE_THAN_ONE= "my.other.product.com";
readonly Context context = Application.Context;

public async Task<bool> ShowDonate(bool isMoreThanOneAllowed = false)
{
	try
	{
		var connected = await CrossInAppBilling.Current.ConnectAsync();

		//Couldn't connect to billing, could be offline, alert user
		if (!connected)
		{
			Toast.MakeText(context, "No internet available", ToastLength.Short).Show();
			return false;
		}

		var productId = isMoreThanOneAllowed ? PRODUCT_ID_MORE_THAN_ONE : PRODUCT_ID;
		var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase);
		if (purchase == null)
		{
			//Not purchased, alert the user
			Toast.MakeText(context, "Didn't work", ToastLength.Short).Show();
			return false;
		}
		else
		{
			// Purchase was successful
			if ((bool)!purchase.IsAcknowledged)
			{
				if (isMoreThanOneAllowed)
				{
					// For consumables, we need to consume the purchase
					var consumeResult = await CrossInAppBilling.Current.ConsumePurchaseAsync(productId, purchase.PurchaseToken);
					if (consumeResult)
					{
						// Consuming was successful
						Toast.MakeText(context, "Thank you", ToastLength.Short).Show();
						return true;
					}
					else
					{
						Toast.MakeText(context, "Didn't work", ToastLength.Short).Show();
						return false;
					}
				}
				else
				{
					// For non-consumables, we finalize (acknowledge) the purchase
					var acknowledgeResult = await CrossInAppBilling.Current.FinalizePurchaseAsync(purchase.PurchaseToken);
					if (acknowledgeResult.First().Success)
					{
						Toast.MakeText(context, "Thank you", ToastLength.Short).Show();
						return true;
					}
					else
					{
						Toast.MakeText(context, "Didn't work", ToastLength.Short).Show();
						return false;
					}
				}
			}
			else
			{
				// Purchase was already acknowledged
			        Toast.MakeText(context, "Thank you", ToastLength.Short).Show();
				return true;
			}
		}
	}
	catch
	{
		// Handle exception
		Toast.MakeText(context, "Didn't work", ToastLength.Short).Show();
		return false;
	}
	finally
	{
		await CrossInAppBilling.Current.DisconnectAsync();
	}
}

However, it seems it's not working. I'm not sure what I'm doing wrong. Any idea what else am I missing in my code?

Expected Behavior

To don't refund the in app in the Play Store.

Actual Behavior

In-Apps are refunded in the Play Store

Code snippet

Already provided.

Screenshots

N/A

You are passing in the wrong data for it to finalize, you need to pass in the TransactionId: https://jamesmontemagno.github.io/InAppBillingPlugin/PurchaseNonConsumable.html

It is pretty straight forward code that is getting called: https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/InAppBilling.android.cs#L426