question

Raf avatar image
Raf asked

How to validate an IAP and update Player Data using Azure Functions ? (iOS)

Hi there,

I came across this thread where CloudScript is used to validate the purchase but I couldn't find any documentation on how to do it using Azure Function.

After following the steps on the thread and the client receives the purchase receipt from Apple, how can I validate the purchase on the server and run the function in which updates the user's Player Data?

Thanks!

sdksCloudScriptapple
10 |1200

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

Rick Chen avatar image
Rick Chen answered

The process should be similar to the Cloud Script. You can also use rules to trigger the Azure function on player_receipt_validation event. And there is the corresponding context model in Azure function triggered by the event, where you can get the event payload. Please refer to: PlayFab CloudScript using Azure Functions Context Models - PlayFab | Microsoft Docs.

1 comment
10 |1200

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

Raf avatar image Raf commented ·

Thanks for your answer!

A: You can also use rules to trigger the Azure function on player_receipt_validation event

Sorry but I'm not sure what that means. Is there an example on how that can be achieved? How does one add a rule?

And in terms of the context, is there a template as well where shows how to get the event payload?

0 Likes 0 ·
Raf avatar image
Raf answered

More specifically, do I need to run ValidateIOSReceiptAsync from the server? I see it's a client call and it's not recommended since client calls are capped but I only need to run when IAPs are made.

Is there any other way to retrieve purchases from the App Store? How does one run any custom behaviour after IAPs?

Any help would be greatly appreciated.

10 |1200

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

Raf avatar image
Raf answered

Well, I think I finally found a workaround that worked for me.

The way I was able to execute custom functions and update user's Player Data upon IAP validation on the server was using the Server.UnlockContainerItem call. After many red herrings and many lost hours, I found this thread from 2015 (scroll to the bottom to see the proper answer).

I basically added "dummy" IAPs on the Container tab inside the game's Catalog and made them consumable (By 1 count). Once a purchase is made and validated from the client, the item gets added to the user's inventory automatically and sits there until claimed.

Then once you run Server.UnlockContainerItem on the server I was able to use the custom logic desired and reward the player as intended. Once the function is called the item was automatically consumed.

@Rick Chen Do you think that is a viable approach? 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.

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.