question

hipposoft3 avatar image
hipposoft3 asked

How to handle IAP validation with pending called ProcessPurchase again.

IAPExample.cs

In ProcessPurchase() in the example script above link,

 public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
         {
             // NOTE: this code does not account for purchases that were pending and are
             // delivered on application start.

// .... }

And I understand that if the game have been reinstalled, ProcessPurchase() would be called right after the start of the game(google said).

But, at the start of the game. The user maybe not logined to Playfab, so can't call validation API of Playfab. So, there is a part of the example code like this:

         if (!IsInitialized || playfab.isLogined()) // not logined to playfab
         {
             return PurchaseProcessingResult.Complete;
         }

It looks like bypassing the validation.

So the problem is,

Is it possible to makes the case that the specific item purchased successfully at google store but not get investigated via Playfab validation so the item doens't show up at the player's inventory of the Playfab?

I think that must be a problem. Or is it just not the case? How can I make the Google purchase and the Playfab validation are matched exactly? Please let me know. Thanks!

apis
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

·
Xiao Zha avatar image
Xiao Zha answered

As the doc: Unity - Manual: Processing Purchases (unity3d.com) says, if you return PurchaseProcessingResult.Pending to ensure that the consumable purchase is not lost, then you need to call the IStoreController's ConfirmPendingPurchase function to complete the purchase process, otherwise the ProcessPurchase method will be called the next time the application starts.

As the comment says: “this code does not account for purchases that were pending and delivered on application start”, so, the edge case you mentioned need other operations to solve the problem, and the code you add is incorrect, it will stop the logged in player to validate the receipt. In your case, you need to recall the ProcessPurchase method manually to validate the receipt. You can add login check in the ProcessPurchase method, if the player is not logged in, you can store the receipt for the ProcessPurchase method to call after login.

3 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.

hipposoft3 avatar image hipposoft3 commented ·

Hi, Xiao. That's my mistake. if( !playfab.isLogined()) is right.

Is it safe for the security to store the receipt to the PlayerPrefs, and use that so I can call Playfab PlayFabClientAPI.ValidateGooglePlayPurchase() manually?

It seems like 'ReceiptJson' and 'Signature' as request would be used for that API. So I can save both string data to PlayerPrefs for the validation.

0 Likes 0 ·
hipposoft3 avatar image hipposoft3 commented ·

And Should I return "PurchaseProcessingResult.Pending" in the ProcessPurchase() method to make sure to proceed the Playfab validation API?

0 Likes 0 ·
Xiao Zha avatar image Xiao Zha hipposoft3 commented ·

Since the code is client code and the receipt is expose to the client, so, it is safe to store the receipt wherever you want. And as the Unity doc says, if you want to keep transactions open on the underlying store until confirmed as processed to ensuring consumable purchases are not lost, you need to return PurchaseProcessingResult.Pending and call ConfirmPendingPurchase only when you have successfully persisted the purchase.

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.