qonversion / unity-sdk

Unity SDK for cross-platform in-app purchase and subscription infrastructure, revenue analytics, engagement automation, and integrations
53 stars 5 forks source link

PurchaseCallback is returning empty entitlements dictionary #243

Closed WiseKodama closed 4 months ago

WiseKodama commented 4 months ago
   #region StartBuying()
    public void StartBuying( PurchasePack<IapPack> purchasePack, Action<string, PurchaseFinishStatus, string> purchaseFinishCallback )
    {
        var purchaseModel = purchasePack.StoreProduct.ToPurchaseModel();
        Qonversion.GetSharedInstance().Purchase( purchaseModel, ( entitlements, error, isCancelled ) =>
        {
            var purchaseFinishStatus = isCancelled ? PurchaseFinishStatus.Cancelled 
                : error == null ? PurchaseFinishStatus.Success 
                : error.Code == QErrorCode.PurchasePending ? PurchaseFinishStatus.Pending 
                : PurchaseFinishStatus.Failed;

            Log.Info( $"PurchaseManager - purchase of pack({purchasePack.IapPack.Id}) finished. Status({purchaseFinishStatus}) WasCancelled({isCancelled}) Error({error})" );
            if( entitlements is { Count: > 0 } )
            {
                foreach( var entitlement in entitlements )
                {
                    Log.Info( $"PCEntitlements -> Id: {entitlement.Key} Transactions:{string.Join(";", entitlement.Value.Transactions.Select(x=>x.TransactionId))}" );
                }
            }

            var transactionId = entitlements == null || entitlements.Count <= 0 ? string.Empty : entitlements.FirstOrDefault(x=>x.Value.ProductId == purchaseModel.ProductId).Value?.Transactions[0].TransactionId;
            Log.Info( $"PurchaseComplete for {purchaseModel.ProductId} with transactionId: {transactionId}" );

            Log.Assert( purchaseFinishStatus != PurchaseFinishStatus.Success || !string.IsNullOrEmpty( transactionId ), "Cannot have successful purchase with no transactionId" );
            purchaseFinishCallback?.Invoke( purchasePack.StoreProduct.StoreId, purchaseFinishStatus, transactionId );
            if( purchaseFinishStatus == PurchaseFinishStatus.Success ) rewardPurchase?.Invoke( purchasePack, transactionId );
        } );
    }
    #endregion StartBuying()

This is our purchasing code, that worked fine two months ago, last confirmed case was 22nd of May.

Testing with Test Card on Android: Successful purchase is returning empty entitlements dictionary... Pending purchases do not get success callback

We get normal confirmation emails from GooglePlay for these test purchases with valid transaction IDs, but the entitlements are empty...

This is happening with release 7.4.0 && 8.0.0, Unity version 2022.3.22f1

SpertsyanKM commented 4 months ago

Hello, @WiseKodama. Let me dive deeper into your case. I'll need a couple of minutes.

SpertsyanKM commented 4 months ago

Could you please share a transaction ID for the purchase, resulted in empty entitlements?

WiseKodama commented 4 months ago

GPA.3318-5784-5577-87382 GPA.3329-6694-1094-24612 GPA.3321-3935-5162-29305

SpertsyanKM commented 4 months ago

Are these consumable or non-consumable in-app purchases?

WiseKodama commented 4 months ago

Those are all consumable in-app purchases. I cannot mark them as such in the Qonversion dashboard, but this was working fine before.

SpertsyanKM commented 4 months ago

Ok, I think I know, what the problem is. We had an issue on our side with handling Android consumable/non-consumable in-app purchases from the last two major versions of our SDKs (for Unity it's 7.0.0+). The bug has been relevant from the 9th of July till yesterday when we released the fix.

Could you please try once again to reproduce it and let me know, if it works now?

WiseKodama commented 4 months ago

Will test right away! Would this also have been the case for the android native sdk?

SpertsyanKM commented 4 months ago

Yes, but only for the mentioned period. If there are any problems with purchases before July 9th or after yesterday, there might be another reason.

WiseKodama commented 4 months ago

Working now! Perfect! Well done!

WiseKodama commented 4 months ago

I will close the issue now, if that's ok with you. I will also test our native android app that has native-android-sdk and report here.

SpertsyanKM commented 4 months ago

Happy to hear that! Once again, accept my apologies for the late reply, please.

I'm closing this issue as solved. Feel free to reopen it or create new ones if you have any further questions.

SpertsyanKM commented 4 months ago

I will also test our native android app that has native-android-sdk and report https://github.com/qonversion/android-sdk/issues/567.

Yes, please. Thank you!