question

VasyaGoblin-8337 avatar image
0 Votes"
VasyaGoblin-8337 asked Ctblova8690-2009 commented

Purchase not working for XBox and Microsoft Store

Unity3D. Xbox.
Implemented the purchase of a license for the game. In the Microsoft Store for desctop Windows it works fine (and when installed from the store and from under Visual Studio, including in the debug assembly), it does NOT work on XBox in dev and retail modes. The license (purchase) has been in the store for a week. For the experiment, I posted the assembly in open access (the day has not yet passed). I repeat: the purchase works without problems on the desktop, it does not work on the XBox. This code does not work (the check works, in both cases):

 // Get product information from the app store
 StoreProductResult productResult = await context.GetStoreProductForCurrentAppAsync();
 if (productResult == null || productResult.Product == null)
 //if (productResult.ExtendedError != null)
 {
     // User may be disconnected or there may be some other server failure
     purchaseCallback?.Invoke(XBoxIAPStatus.NotGetStoreProduct, productResult.ExtendedError);
    
     return;
 }

Весь код:

     public static async void PurchaseFullLicense(Action<XBoxIAPStatus, Exception> purchaseCallback, Action<XBoxIAPStatus> licChanged)
     {
 #if ENABLE_IL2CPP && UNITY_WSA_10_0
         licenseChanged = licChanged;
    
         if (context == null)
         {
             context = StoreContext.GetDefault();
    
             // Подписываемся на событие изменения лицензии
             context.OfflineLicensesChanged += context_OfflineLicensesChanged;
         }
    
         if (context == null)
         {
             purchaseCallback?.Invoke(XBoxIAPStatus.NoInitContext, null);
    
             return;
         }
    
         // Получить информацию о продукте в магазине приложений
         StoreProductResult productResult = await context.GetStoreProductForCurrentAppAsync();
         if (productResult == null || productResult.Product == null)
         //if (productResult.ExtendedError != null)
         {
             // Пользователь может быть отключен или может быть какой-то другой сбой сервера
             purchaseCallback?.Invoke(XBoxIAPStatus.NotGetStoreProduct, productResult.ExtendedError);
    
             return;
         }
    
         // Покупка полной лицензии ...
         StoreAppLicense license = await context.GetAppLicenseAsync();
         if (license != null && appLicense.IsActive && license.IsTrial)
         {
             // Пока демо версия
             StorePurchaseResult result = await productResult.Product.RequestPurchaseAsync();
             if (result.ExtendedError != null)
             {
                 // Ошибка: print result.ExtendedError.Message
                 purchaseCallback?.Invoke(XBoxIAPStatus.NotRequestPurchase, null);
    
                 return;
             }
    
             // Покупка прошла. Результат:
             switch (result.Status)
             {
                 case StorePurchaseStatus.AlreadyPurchased:
                     // Вы уже купили это приложение и имеете полностью лицензированную версию
                     purchaseCallback?.Invoke(XBoxIAPStatus.AlreadyPurchased, null);
                     return;
    
                 case StorePurchaseStatus.Succeeded:
                     // Лицензия будет обновлена автоматически с помощью события StoreContext.OfflineLicensesChanged
                     purchaseCallback?.Invoke(XBoxIAPStatus.Succeeded, null);
                     return;
    
                 case StorePurchaseStatus.NotPurchased:
                     // Товар не был куплен, возможно, он был отменен
                     purchaseCallback?.Invoke(XBoxIAPStatus.NotPurchased, null);
                     return;
    
                 case StorePurchaseStatus.NetworkError:
                     // Сетевая ошибка
                     purchaseCallback?.Invoke(XBoxIAPStatus.NetworkError, null);
                     return;
    
                 case StorePurchaseStatus.ServerError:
                     // Ошибка сервера
                     purchaseCallback?.Invoke(XBoxIAPStatus.ServerError, null);
                     return;
    
                 default:
                     // Не определённая ошибка
                     purchaseCallback?.Invoke(XBoxIAPStatus.UnDefined, null);
                     return;
             }
         }
         else
             // Вы уже купили это приложение и имеете полностью лицензированную версию
             purchaseCallback?.Invoke(XBoxIAPStatus.LicenseFull, null);
 #else
         purchaseCallback?.Invoke(XBoxIAPStatus.NotXBoxPlatform, null);
 #endif
 #pragma warning restore 1998
     }


partner-center-general
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Could you please tell me what do you mean by not work? Does it give an error? Have you checked the StorePurchaseResult object? Does it have a return value? If it has, what the status?

0 Votes 0 ·

May be fixed now but if you have any further issues contact Microsoft with your query

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered

XBox is not currently supported here on QnA. They're actively answering question in dedicated forums here.
https://answers.microsoft.com/en-us/xbox/forum
https://social.msdn.microsoft.com/Forums/en-US/home?forum=xboxlivedev

--please don't forget to Accept as answer if the reply is helpful--




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VasyaGoblin-8337 avatar image
0 Votes"
VasyaGoblin-8337 answered RoyLi-MSFT commented

Hi!

I am making additional explanations.
The code is identical for purchasing the full license for the desktop and Xbox application. But for a desktop computer, it works (both when loading an application from the store and when debugging in Visual Studio) and on Xbox the system window is not displayed in both dev and pro console modes.
The task of the code is to display a system window for purchasing a full license.

In the xbox mode, I can see the returned exception when GetStoreProductForCurrentAppAsync is called, but it is extremely uninformative (the description boils down to the fact that this is a system exception). Of course, something similar to displaying in the prod console mode can also be organized, but for this you need to put the application in the store and ..., in general, this is an extreme way of debugging. Later I will post a screenshot of the returned exception (Exception.ToString ()), now there is no console nearby.
The application was in private access (only for testers). I got the assumption that Xbox does not see the product in the store, because the application was released to the public only yesterday and it has not yet passed 24 hours to set up the product in the store. in the hope that this is the only reason why the purchase does not work.
Another suggested reason is to initialize StoreContext.GetDefault () with parameters, and named with the current user.

The code that receives the result of an attempt to purchase a license:

     private void Purchase()
     {
         Loger(">>>>>>>>>> #0 InAppPurchaseManagerXBox.Purchases()");
    
         CPurchaseXBox.PurchaseFullLicense((CPurchaseXBox.XBoxIAPStatus result, Exception e) =>
         {
             if (e != null)
             {
                 Loger($">>>>>>>>>> #1 InAppPurchaseManagerXBox.Purchases() Exception message: \"{e.ToString()}\"");
    
                 return;
             }
    
             Loger($">>>>>>>>>> #2 InAppPurchaseManagerXBox.Purchases() result = {result}");
    
             if (result == CPurchaseXBox.XBoxIAPStatus.AlreadyPurchased || result == CPurchaseXBox.XBoxIAPStatus.LicenseFull)
             {
                 TryUnlockGame(true, "1");
    
                 OnPurchaseHandler?.Invoke(this, new PurchaseEventArgs(true, "Is Product Purchased"));
             }
    
         }, LicensesChanged);          
     }

Also, later I will attach a more detailed output of the exception.

· 5
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you get detailed information about the exception or the result, please share it here.

0 Votes 0 ·

The order of calling commands when trying to buy a license and getting an error (so as not to delve into it for a long time):

32889-screenshot-2.png


0 Votes 0 ·
screenshot-2.png (291.3 KiB)

Output from the XBox console, in dev mode, to Visual Studio during a purchase attempt:

32890-screenshot-1.png


0 Votes 0 ·
screenshot-1.png (129.9 KiB)

Can the store dispatch settings affect how this piece of code works? Or connecting to Xbox Live?

0 Votes 0 ·

Looks like you directly check the exception message. Could you please put a breakpoint inside the PurchaseFullLicense method? Then you could run the code line by line when you debug and to see which line of code throws the exception. And if there is no exception, what's the value of StorePurchaseStatus and StorePurchaseResult

0 Votes 0 ·
VasyaGoblin-8337 avatar image
0 Votes"
VasyaGoblin-8337 answered RoyLi-MSFT commented

Hi.
Thanks for your attention to my problem.

The code is written in Unity3d, after which it is assembled into the Visual Studio project. Therefore, unfortunately, there is no way to set a breakpoint. I use logging.
The GetStoreProductForCurrentAppAsync () function returns a StoreProductResult, which contains an exception that has already been handled by the system and I don't need to catch it. You just need to check its presence and if it is, then process the fact of its presence. Standard schema according to documentation and numerous examples.
As a result, if I install an application from a store on a stationary computer, then everything works, and if I also install an application on an XBox, it does not work because GetStoreProductForCurrentAppAsync cannot get products in the XBox environment and the PurchaseFullLicense function is terminated for verification:

 StoreProductResult productResult = await context.GetStoreProductForCurrentAppAsync();
          if (productResult == null || productResult.Product == null)
          //if (productResult.ExtendedError != null) //  is equivalent to interrupting the check


· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Expression: everything works means that the game receives products and displays a system window with a choice of payment options. Unfortunately, this does not happen on Xbox, although buying in XBox OS also works fine. I can't buy a license for a product in the Xbox environment inside our game (when the game is running).

0 Votes 0 ·

Do you mean the GetStoreProductForCurrentAppAsync method throws the exception? Could you please try to output StorePurchaseStatus and StorePurchaseResult like what you did for the exception? So that we could confirm if the GetStoreProductForCurrentAppAsync did work or not.

0 Votes 0 ·

Expression: everything works means that the game receives products and displays a system window with a choice of payment options. Unfortunately, this does not happen on Xbox, although buying in XBox OS also works fine. I can't buy a license for a product in the Xbox environment inside our game (when the game is running).

0 Votes 0 ·

I know what you mean. I want to check the value StorePurchaseStatus and StorePurchaseResult because they might contains the error message.

0 Votes 0 ·

I think I managed to understand what the problem was. For Xbox, a full game license (not a trial) is initially returned, so the license request threw an internal exception and returned it as an error.
Now I have another question: why do I have a license for the full version of the application in Xbox, although I did not buy it (in the desktop version everything is fine and the license for the demo version)?

0 Votes 0 ·

Hey.
When requesting from xbox to store (and in other functions), the following error is returned(HRESULT 0x803F6107):
34133-screenshot-1.png



On a desktop computer, there is no such error and everything works fine.
I assume that this is either not a correct store setup or a Microsoft error. Does anyone have any ideas?

0 Votes 0 ·
screenshot-1.png (45.3 KiB)

The error code means Something unexpected happened while processing the current operation. You could check the code here: Error codes for Store operations.

I'd suggest you open a free support ticket here: Contact Us. Choose to Contact us, select Dashboard for Topic, and select App submissions and management for issue type.


0 Votes 0 ·