question

jrDev avatar image
jrDev asked

PurchaseItem Not Working?

Hello,

I am trying to use PurchaseItem API but it keeps returning error ServiceUnavailable in Unity and when I try to test from the API website, it gives error ItemNotFound. I tried calling my item with its ID and its Display Name but still same errors. Am I doing something wrong?

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

The base design of the service is that a catalog is a version - hence the naming. So, you would normally put all the items, including virtual currency purchases, in a single catalog version, and then update the version when you update the title (if necessary). The Stores are meant to be the way to have subsets of items from your catalog, separated out for different purposes. You can still use the service the way you describe - with different groups of items in different catalog versions - but there are some limitations. Specifically, receipt validation does not take a catalog version - it always uses the primary catalog version.

Now, PurchaseItem, as you pointed out, takes a CatalogVersion. I'll file a bug for the fact that passing "" as the version causes an issue - as far as I know, you're the first to encounter that issue, but we'll get it fixed shortly. However, when using that call, the CatalogVersion you pass in, as long as it actually matches a configured catalog in your game, will always determine which catalog is used for the operation. If that's not what you're seeing, could you provide the specifics of the call you're making and the title ID you're using?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jrDev avatar image
jrDev answered

Hey,

I figured it out by doing some more reading through the forums and the solution was to set the Primary Catalog. That brings up a question, how do I access a currency catalog separate from my item catalog if they have to be Primary?

Also my other error seems to have been because I was putting a blank CatalogVersion into the spot. The API should ignore if a request attribute is blank as to not cause confusion when an error like this pops up.

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jrDev avatar image
jrDev answered

Hey,

I was actually incorrect about the CatalogVersion causing the ServiceUnavailable error. After I went back to research, it was the StoreID causing the error. So I guess when the StoreID is blank ("") then it will throw this error. I ran into this bug because I was creating a system to set these values from inspector. After uncommenting and testing one by one, I found the error. The CatalogVersion and CharacterID sections don't have a problem with being blank but the StoreID does. Let me know you can fix.

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

So the issue is specifically when you do have a StoreId in the call, but it's an empty string? Thanks - I'll get a bug filed on that.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jrDev avatar image
jrDev answered

Wow, that was quick. And yes!

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Hmm - actually, can you provide the specifics of your test (Title ID and the full body of the call to PurchaseItem)? In my own testing, I'm getting a 500 error, rather than ServiceUnavailable.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jrDev avatar image
jrDev answered

 

TitleID = 1FBB

PurchaseItemRequest request = new PurchaseItemRequest(){
ItemId = "RR",
VirtualCurrency = "DP",
Price = 1,
CatalogVersion = "",
StoreId = ""
CharacterId = ""
};

PlayFabClientAPI.PurchaseItem(request, (result) => {

items = result.Items.ToArray();

Debug.Log("Purchasing Item was successful!");

},(errorCall) => {

Debug.Log("There was an error Purchasing Item! The error is: '" + errorCall.Error + "'!");

error = errorCall.Error.ToString();

});

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

I see. It looks like there are two distinct issues here, then. The first is what I'm seeing - that calling PurchaseItem with a StoreId of "" is causing a 500 error. What you're running into is an issue with how the request object is formed - specifically, you've got a missing comma after the StoreId, which must be what's causing the ServiceUnavailable you're running into. I've already filed a bug on the StoreId in PurchaseItem - I'll also file one for the tools team on the request issue. Thanks!

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jrDev avatar image
jrDev answered

Oh, that was just a mistake by be accidentally removing the comma while editing the code for your use.

That part actually reads:

StoreID = storeID, //This is the variable used to set from inspector.

Thanks,

jrDev

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

brendan avatar image
brendan answered

Well, that's interesting, then. Can you try making the call from Postman, to see what response you get?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.