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 Exception #66

Closed
MarcorOnline opened this issue Aug 1, 2017 · 6 comments
Closed

GetPurchasesAsync Exception #66

MarcorOnline opened this issue Aug 1, 2017 · 6 comments

Comments

@MarcorOnline
Copy link

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: 1.2.2 (nuget)
Device Tested On: iPhone 6S Plus
iOS Version: iOS 8

Hello.
I'm using this library to purchase Auto-Renewable Subscriptions on Xamarin Forms.
The purchase process works, but after 1 month (subscription expiration) I'm having an issue to check if already exists (restore).
When I try to get the purchased items, using GetPurchasesAsync, an exception occurs:

https://gist.github.com/MarcorOnline/319897c5256614272aed9c62acc47376

Code snippet

var storePurchased = await billing.GetPurchasesAsync(ItemType.Subscription);

Thanks for your support

@MarcorOnline
Copy link
Author

MarcorOnline commented Aug 1, 2017

I'm looking the source code of this plugin and, maybe, there is a bug in "ToIABPurchase" method:

var p = transaction.OriginalTransaction;
if (p == null)
  p = transaction;

if (p == null)
  return null;

Should be replaced with:

var p = transaction?.OriginalTransaction ?? transaction;
if (p == null)
  return null;

I don't know if the crash is related with this, but can be an improvement.

Thanks

@MarcorOnline
Copy link
Author

MarcorOnline commented Aug 1, 2017

@jamesmontemagno I discovered that the real problem is that is necessary to call

CrossInAppBilling.Dispose()

to reset the

CrossInAppBilling.Current

instance.
It's not enoug to simply call dispose (for example with using) on the "CrossInAppBilling.Current" instance.

Working with Subscriptions I've found another problem in the "ToIABPurchase" method. Preferring the "OriginalTransaction" it's not possible to detect the last renewing DateTime.

Why you don't use directly the "transaction" object?

Best regards,
Marco

@jamesmontemagno
Copy link
Owner

jamesmontemagno commented Aug 1, 2017

Oh i see now, looks like a documentation issue. Let me fix this up.

@MarcorOnline
Copy link
Author

@jamesmontemagno CrossInAppBIlling.Current.Dispose(); is not sufficient.
If you look the code, the "Current" entity is not resetted and if you try to use it again you obtain an exception because the "observer" (in iOS implementation) is nulla after CrossInAppBIlling.Current.Dispose();

If you call "CrossInAppBilling.Dispose()" the CrossInAppBIlling.Current.Dispose(); is included, but also a new Lazy for "Current" is created.

To reproduce the problem:

  • Get CrossInAppBIlling.Current
  • Call "GetPurchasesAsync"
  • Call dispose
  • Get CrossInAppBIlling.Current again
  • Call "PurchaseAsync" -> Exception!

Best regards,
Marco

@jamesmontemagno
Copy link
Owner

I have updated the documentation.

jamesmontemagno added a commit that referenced this issue Aug 1, 2017
@last-Programmer
Copy link

@MarcorOnline Can you able to make it working restore purchases for subscription? If so could you please post the code on how to do it?. I am in the same situation.
Thanks

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

3 participants