yperalta
yperalta

Reputation: 1

UWP StoreContext for a specific user

I wanna make some purchase in my Universal Windows Platform (UWP) app, but when I do it this way:

auto storeContext = StoreContext::GetDefault();
auto result = co_await storeContext.RequestPurchaseAsync(PRODUCT_STORE_ID);

the purchase is done with the microsoft account currently logged in in the device before calling the RequestPurchaseAsync method. What I want is to do the purchase with a specific microsoft account, eg [email protected], in fact what I want is having a storeContext object related to that microsoft account, in order to every method I call from the StoreContext class with that object be done for that microsoft account. So if after the purchase I do the following:

auto result = co_await storeContext.GetConsumableBalanceRemainingAsync(PRODUCT_STORE_ID);

I will get the balance remaining for the account [email protected]. Actually I don't know how to do this because if after the purchase and before the balance request I log out from the Store app, which is an app installed in every Windows 10 personal computers and is an external app, ie is not my app, then the balance request will return in my app an error because the operation is not associated to any account. If instead of just log out from the Store app I also sign in with a different microsoft account, eg [email protected], the balance request will return in my app the balance of [email protected] instead of the balance of [email protected] that is what I want. So I don't want that those external signing changes affect my app behavior.

I have seen the StoreContext class have a GetForUser method but I haven't find a way to pass something like "[email protected]" as a parameter. I have found a way to create a user by its non-roamable-id, which I have no idea of how to get that from the username. In fact I'm not sure if the GetForUser method can be used for this purpose. Besides the following code makes my app crash:

auto storeContext = StoreContext::GetDefault();
auto user = storeContext.User();
auto nonRoamableId = user.NonRoamableId(); //This line makes my app crash

So if any of you guys have any idea it will be very appreciated.

PD: the code above was using Visual Studio 2017 with C++ and the cppwinrt project from https://github.com/Microsoft/cppwinrt

Upvotes: 0

Views: 416

Answers (2)

yperalta
yperalta

Reputation: 1

thanks @nicozhu for your comments, but about this:

For your scenario I recommend that you can store the username information, consumed-balance, remaining-balance in your database or server or azure storage, in this way you or your customer can search all the information based on the username for example querying the Remaining-Balance.

I can't know when asking for these informations which microsoft account they are bound, all I can do is to ask for that info to the storeContext object which will give me the info of the current logged in user, which I also don't know who is it. I mean, if once my application is launched I ask for the remaining balance, eg a value 5 is returned, and after 10 minutes I do a purchase and request again for the remaining balance, but this time I'm returned a value of 6, it doesn't mean that the same user did the purchase, maybe a signing change was done before the purchase, so this value (6) corresponds to the new user that also had 5 as a remaining balance before the purchase, but the first user still has 5 as remaining balance. I have no control of those signing changes, but that is affecting the behavior of my application. I'm not even notified about those signing changes, so if I ask for info several times I don't know if those info correspond to the same user or different users. So about this:

this api design is reasonable.

I'm not so sure about that, but thanks anyway.

Upvotes: 0

Nico Zhu
Nico Zhu

Reputation: 32785

. If instead of just log out from the Store app I also sign in with a different microsoft account, eg [email protected], the balance request will return in my app the balance of [email protected] instead of the balance of [email protected] that is what I want.

As you known storeContext.GetConsumableBalanceRemainingAsync(PRODUCT_STORE_ID) method was used to get the balance remaining of current account. If you change to another account before receiving the response of the method. It will return error. Because the balance remaining does not belong to current account. So this api design is reasonable.

I have seen the StoreContext class have a GetForUser method but I haven't find a way to pass something like "[email protected]" as a parameter. I have found a way to create a user by its non-roamable-id, which I have no idea of how to get that from the username.

Currently, there is no api for getting specific user’s Remaining-Balance. For your scenario I recommend that you can store the username information, consumed-balance, remaining-balance in your database or server or azure storage, in this way you or your customer can search all the information based on the username for example querying the Remaining-Balance.

Upvotes: 0

Related Questions