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

Consume and Purchase returns null after redeem #100

Closed
Yohandah opened this issue Dec 19, 2017 · 11 comments
Closed

Consume and Purchase returns null after redeem #100

Yohandah opened this issue Dec 19, 2017 · 11 comments

Comments

@Yohandah
Copy link

Yohandah commented Dec 19, 2017

Version Number of Plugin: Last
Device Tested On: Samsung Galaxy S8 Oreo
Simulator Tested On:
Version of VS: Last
Version of Xamarin: Last
Versions of other things you are using:

Steps to reproduce the Behavior

Create a product and create a promotion code, redeem the code in the app, purchase returns null and consume also for this productId

Expected Behavior

It should not return null

Actual Behavior

It returns null

Code snippet

try
{
                var connected = await CrossInAppBilling.Current.ConnectAsync();

                if (!connected)
                {
                    //Couldn't connect to billing, could be offline, alert user
                    return;
                }

                var purchases = await CrossInAppBilling.Current.GetPurchasesAsync(ItemType.InAppPurchase);
                Console.WriteLine(purchases);
//trying to consume it because just above I can see that I have the item and it's not consumed
                var consumedItem = await CrossInAppBilling.Current.ConsumePurchaseAsync(productId, ItemType.InAppPurchase, "mypayload");

                var purchase = await CrossInAppBilling.Current.PurchaseAsync(productId, ItemType.InAppPurchase, "mypayload");
                if (purchase == null)
                {
                    Toast.MakeText(this,"not purchased", ToastLength.Long).Show();
                }
                else
                {
                    //Purchased, save this information
                    var id = purchase.Id;
                    var token = purchase.PurchaseToken;
                    var state = purchase.State;
                    //var consumedItem = await CrossInAppBilling.Current.ConsumePurchaseAsync(productId, Plugin.InAppBilling.Abstractions.ItemType.InAppPurchase, "mypayload");

                    if (consumedItem != null)
                    {
                        Toast.MakeText(this, "Item Consumed", ToastLength.Short).Show();
                    }
                    else
                    {
                        Toast.MakeText(this, "Item NOT CONSUMED", ToastLength.Short).Show();
                    }
                }
            }
            catch (System.Exception ex)
            {
                //Something bad has occurred, alert user
                Console.WriteLine(ex);
            }
            finally
            {
                //Disconnect, it is okay if we never connected
                await CrossInAppBilling.Current.DisconnectAsync();
            }

Screenshotst

@SkillerSKL
Copy link

same issue here :s

@jamesmontemagno
Copy link
Owner

jamesmontemagno commented Dec 20, 2017

hmmmm, i am not sure how that works with a promo code works.

What is the ConsumptionState of the original purchase?

@jamesmontemagno
Copy link
Owner

You should also really use:
ConsumePurchaseAsync(string productId, string purchaseToken)

It is the only reliable method here.. and you HAVE THE TOKEN! Use it! Else I just try to find the first one in the list.

I could probably check the state for not consumed as an optimization.

@Yohandah
Copy link
Author

Yohandah commented Dec 20, 2017

@jamesmontemagno The ConsumptionState of the original purchase was NotYetConsumed, but using ConsumePurchaseAsync(string productId, string purchaseToken) is working !

On the other hand, PurchaseAsync(productId, ItemType.InAppPurchase, "payload") returns null when using a promo code .. :s using a credit card is ok

@EmilAlipiev
Copy link

EmilAlipiev commented Apr 24, 2018

@meepou so ConsumePurchaseAsync worka for both promocode and other payment methods? can we safely call it instead of PurchaseAsync? actually PurchaseAsync also works but return object is just null but when I check with GetPurchasesAsync, i can see that it is in the list.

@EmilAlipiev
Copy link

This makes no sense. I just went through the code and ConsumePurchaseAsync just just checkes if you have purchase and uses the token from the found purchase token. even in another case, I need promotion code to be working for non-consumable products. ConsumePurcahseAsync only works for consumables I believe. how can we resolve this please?

@jamesmontemagno
Copy link
Owner

normal purchaseasync should work just fine I think. Else would need to debug through

@EmilAlipiev
Copy link

It is unfortunately not working. i mean that purchase is working but result from purchaseasync is always null. it could be some serialization problem in the application. I recognized that although i am passing payload for that action, when using redeem code, response has no payload but same purchase with credit card has payload. I wanted to debug attaching source code on my .net standard 2.0.2 project but i am getting error for current activity plugin is not recognized somehow. i will try with a fresh project. please let me know if you can test it faster :)

image

@jamesmontemagno
Copy link
Owner

are you passing it a "" payload? i just fixed a bug that was returning null here. Update to the latest beta if that is the case or pass it a payload, which is best practice.

@jamesmontemagno
Copy link
Owner

hmmm the Id is null?

@jamesmontemagno
Copy link
Owner

Please comment: #143

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

4 participants