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

Android Pending Payments Confusion - IPurchasesUpdatedListener Implementation #384

Closed
jamsoft opened this issue May 11, 2021 · 7 comments · Fixed by #385
Closed

Android Pending Payments Confusion - IPurchasesUpdatedListener Implementation #384

jamsoft opened this issue May 11, 2021 · 7 comments · Fixed by #385

Comments

@jamsoft
Copy link

jamsoft commented May 11, 2021

I'm just looking at how to deal with Pending payments on Android. After reading the plugin docs and the google docs it states that in order to receive updates we should implement PurchasesUpdatedListener - in XF by implementing IPurchasesUpdatedListener.

This all sounds fine and reasonable in principal but I'm a still a little confused.

The InAppBillingPlugin also sets it's own listener internally

BillingClientBuilder.SetListener(OnPurchasesUpdated);
during the call to ConnectAsync();

This leads me to think that if I also register a listener in my MainActivity won't this result in getting multiple updates during a normal purchasing process? Both the Plugin and `MainActiivty listener would be registered at that point.

It looks like this Plugin listener would be disconnected in the call to DisconnectAsync();, which is called in my code immediately after any billing processes.

At that point it seems to make sense to have the MainActiivty listener to then process any updates changing a Pending into Cancelled or Purchased outside of the Connect() Disconnect() flow.

Are there any examples of handling this?

@jamesmontemagno
Copy link
Owner

So, as of right now there is no callback that you can subscribe to in the library when a purchase is updated. ... Maye I will add that in.

https://developer.android.com/google/play/billing/integrate#pending says: When your app receives a new purchase, either through your PurchasesUpdatedListener or as a result of calling queryPurchases(), use the getPurchaseState() method to determine whether the purchase state is PURCHASED or PENDING

So, my recommendation is to just GetPUrchasesAsync on startup of the app. In my apps I just have a restore purchases button that they can go and press.

@jamesmontemagno
Copy link
Owner

So i did -> #385

What i did here is made IsConnected visible which should be helpful for Android.

You can connect on startup and register for

Plugin.InAppBilling.InAppBillingImplementation.OnAndroidPurchasesUpdated = (billingResult, purchases) =>
{
     // decide what you are going to do here with purchases
};

Does that make sense?

@jamsoft
Copy link
Author

jamsoft commented Jun 16, 2021

This does make a stack of sense. Thanks James, much more convenient, obvious and explicit.

@jamesmontemagno
Copy link
Owner

Cools, i will try to push a thing out in the next few days

@jamsoft
Copy link
Author

jamsoft commented Jun 18, 2021

Would be good to have an example usage I think.

Since the general advice in the documentation follows connect -> do your thing -> disconnect, it would be good to document how this should be treated in a similar or different manner.

It would suggest from the approach above that you connect during app initialisation and would need to then remain connected in order to receive the events.

Unless I'm actually reading this wrong myself at the moment.

jamesmontemagno added a commit that referenced this issue Jul 13, 2021
Add callback on Android for on purchases updated
@smalgin
Copy link

smalgin commented Mar 5, 2022

Sorry to pick on the closed issue, but I have the weirdest thing happening:

Xamarin app, latest version of billing plugin.

In my MainActivity I added the recommended code snippet to add purchase update listener.
Now I am getting this compile error:
MainActivity.cs(128,64,128,89): error CS0117: 'InAppBillingImplementation' does not contain a definition for 'OnAndroidPurchasesUpdated'

Any ideas? The web is silent...

@jamesmontemagno
Copy link
Owner

Should be there... https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling/InAppBilling.android.cs#L29

Make sure that you are compiling your Android app against Android 10 +

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

Successfully merging a pull request may close this issue.

3 participants