Implement pending purchase handling for Unity IAP and update README#112
Implement pending purchase handling for Unity IAP and update README#112sotash wants to merge 4 commits into
Conversation
Update README.md
Add UnlockInGameContent and ConfirmPurchase calls on OnPurchasePending to properly acknowledge purchases
Update README.md
There was a problem hiding this comment.
Code Review
This pull request updates the project to Unity 6.3 LTS and Unity IAP 5.3.0, alongside documentation improvements and updated troubleshooting steps in the README. A critical security and logic issue was identified in PurchaseController.cs, where in-game content is unlocked and purchases are confirmed during the 'Pending' state instead of the 'Confirmed' state, potentially allowing access to items before payment is finalized. Additionally, a null check for obj.CartOrdered is recommended to prevent a potential NullReferenceException.
| foreach (var product in obj.CartOrdered.Items()) | ||
| { | ||
| GameDataController.UnlockInGameContent(product.Product.definition.id); | ||
| } | ||
| _storeController.ConfirmPurchase(obj); |
There was a problem hiding this comment.
Unlocking content and confirming the purchase within the OnPurchasePending handler is a security and logic risk. A "Pending" state in IAP (such as Google Play's Pending Transactions or Apple's Ask to Buy) indicates that the transaction has been initiated but not yet completed. Granting access to content at this stage allows users to receive items before payment is finalized. This logic should be moved to the OnPurchaseConfirmed handler. Additionally, the code should check if obj.CartOrdered is null before iterating over its items to avoid a potential NullReferenceException.
There was a problem hiding this comment.
This implementation is based on Unity's documentation. Also, implementation in this sample is just an example.
Added a null check.
Add a null check to PurchaseController.cs
|
Tg |
Summary
This PR ensures proper purchase processing when using Unity IAP by implementing pending purchase handling. It also refactors and updates the README documentation for better troubleshooting guidance.
Changes
OnPurchasePendingto callGameDataController.UnlockInGameContentandStoreController.ConfirmPurchaseto handle pending transactions correctly.Verifications