I am implementing the subscription restore process on iOS.
I found that the restore called ProcessPurchase multiple times(Number of subscription purchases in the past?).
Since I want to verify the receipt on the server, ProcessPurchase uses PurchaseProcessingResult.Pending.
I implemented the process to perform ConfirmPendingPurchase when the receipt verification on the server is completed.
At this time, I thought about performing ConfirmPendingPurchase using PurchaseEventArgs.purchaseProduct when ProcessPurchase was called.
However, it seems that the value of product is rewritten every time ProcessPurchase is called, and ConfirmPendingPurchase cannot be executed with the appropriate product, so the process remains Pending.
For this reason, it seems that ProcessPurchase is called multiple times again when the app is restarted.
How should ConfirmPendingPurchase be performed if PurchaseProcessingResult.Pending is used when ProcessPurchase is called multiple times?
The pseudo code is processed as follows
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
{
Product product = args.purchasedProduct;
Debug.Log("[log]ProcessPurchase : " + product.transactionID);
StartCoroutine(ConfirmPendingPurchaseAfterDelay(product));
return PurchaseProcessingResult.Pending;
}
private IEnumerator ConfirmPendingPurchaseAfterDelay(Product p)
{
Debug.Log("[log]Delaying confirmation of " + p.transactionID + " for 5 seconds.");
var end = Time.time + 5f;
while (Time.time < end) {
yield return null;
}
Debug.Log("[log]Confirming purchase of " + p.transactionID);
_storeController.ConfirmPendingPurchase(p);
}
Cannot you just return Complete from ProcessPurchase instead of ConfirmPendingPurchase? What do you mean “rewritten”? Yes, each ProcessPurchase has a different productID associated with it in the arguments. I would not recommend to run any co-routines from ProcessPurchase. it’s a callback from the store APIs.
I cannot return Complete since I want to check the receipt on my server.
Co-routine is necessary I need a little seconds while I wait a return from my server.
Multiple call of “ProcessPurchase” will be occured when I use “IAppleExtensions.RestoreTransactions”.
while I verify the receipt on my server.
I think, each “PurchaseEventArgs.purchasedProduct” have same memory address.
So, if I assign “PurchaseEventArgs.purchasedProduct” to my local variable, all “product” have same value when I call “ConfirmPendingPurchase”.
All “product” only has same value as last “ProcessPurchase”'s “PurchaseEventArgs.purchasedProduct”.
Therefore, I think to copy those value to new “Product” object.
But I cannot instantiate “Product” object since it’s not public.(Setter is private too.)How do I correct if there are multiple call of ProcessPurchase?
Each ProcessPurchase will have a unique ProductID. You will need to handle accordingly in your code, I would not have specific recommendations. I persist a temporary product in the Sample IAP project Sample IAP Project
Did you see the sample code and log output I wrote at the beginning of the thread?
As you can see from the log, Product.transactionID has been rewritten in “ConfirumPendingPurchaseAfterDelay”.
(Looking at the logs, “ConfirmPendingPurchase” uses product with the same transactionID.)
For this reason, “ConfirmPendingPurchase” has failed.
The sample code “ConfirumPendingPurchaseAfterDelay” is just a minor tweak to IAPDemo.cs included in the Unity IAP 3.0.1 demo.
Isn’t this code intended for receipt verification on the server?
Has Unity IAP been tested for subscription purchases and “IAppleExtensions.RestoreTransactions”?
Yes, did you see how I save the product in the IAP Sample Project? Test without a co-routine, or perhaps make an array/list if you claim they keep changing.