question

Canberk Soner avatar image
Canberk Soner asked

Unique item that can only be purchased once per user

Hi.

We need to implement unique items. To be more precise, our use case is like this:

1) User purchases an item. The item is a consumable with a timer.

2) Until the item expires, it cannot be purchased again.

3) If the timer expires and user has not met a certain condition before that, he is eligible to purchase the item again.

4) If the user meets the condition before item expires, the item is "consumed" and the user cannot ever purchase the item again.

I've seen other questions asking this, but the conclusion was that it is only possible to do this client-side by checking the inventory. That would probably work for us, but I'd like to ask if there is a way to make this secure with some workarounds.

I don't really have an idea right now. Is it possible to do with somehow with StartPurchase - PayForPurchase - ConfirmPurchase flow instead of PurchaseItem? I've seen it mentioned somewhere that while StartPurchase is designed for real money transactions, it can also treat PlayFab title as a "provider" and use virtual currency.

10 |1200

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

1 Answer

·
brendan avatar image
brendan answered

Yes, the StartPurchase flow can be used for virtual currency (VC) purchases, using the title as the payment provider, but that's not really going to help with this, since all it does is add steps to the process.

First question: is this purchase only ever made with VC? If so, there are a couple of routes you could take:

1. Do a Grant... and VC consume via Cloud Script. That would allow you to check the conditions and only allow the transaction under certain circumstances.

2. Use a Segment Override on a Store to give the player access to the purchase of the item. You could set a Tag on the player account, for example, for which you have a Segment defined. That way, the Store would only be available to the player while they're in that Segment.

2 comments
10 |1200

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

Canberk Soner avatar image Canberk Soner commented ·

Yes, It's going to be VC only.

I guess I'll go with #1, because there are a couple hundred items and using stores for this wouldn't be practical. Can't have hundreds of tags anyway.

Actually I've done something similar to #1 for our "craft system" before. Is there anything to be careful of, like error handling, performance etc. ?

0 Likes 0 ·
brendan avatar image brendan Canberk Soner commented ·

Well, we always advise being careful about handling error conditions. Since the calls are going from one machine in a datacenter to another (in the same datacenter), there should be minimal issues sourcing outside the script, though. If you use try/catch blocks, you should be able to prevent the script from exiting on an exception if it hasn't run out of CPU time. In terms of performance, minimizing the number of API calls needed in the script is key.

0 Likes 0 ·

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.