I'm trying to implement automatic transaction recovery for interrupted transactions.
Everything works fine in the *happy flow* where I send *InitiatePurchase* and shortly after I receive a *ProcessPurchase* call.
However, restarting the app never triggers *ProcessPurchase* again. I'm returning *PurchaseProcessingResult.Pending* as the [documentation][1] clearly states: *The application is still processing the purchase and ProcessPurchase will be called again the next time the Application starts, unless the ConfirmPendingPurchase function of IStoreController is called.*
It is never called however. Neither in the Editor, nor on device(s). Am I missing something?
Here is some test code I setup for this:
public class IAPTest : MonoBehaviour, IStoreListener
{
public bool useFakeStore;
private IStoreController _storeController;
private void Start()
{
Debug.Log($"Initializing IAP Service");
if (useFakeStore)
StandardPurchasingModule.Instance().useFakeStoreUIMode = FakeStoreUIMode.DeveloperUser;
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
builder.AddProduct("some_product_id", UnityEngine.Purchasing.ProductType.Consumable);
UnityServices.InitializeAsync();
UnityPurchasing.Initialize(this, builder);
}
public void OnInitializeFailed(InitializationFailureReason error)
{
Debug.Log($"OnInitializeFailed {error}.");
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
Debug.Log($"OnInitialized.");
_storeController = controller;
}
public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
{
Debug.Log($"OnPurchaseFailed {failureReason} (click for more info):" +
$"\n{JsonConvert.SerializeObject(product)}");
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs purchaseEvent)
{
var product = purchaseEvent.purchasedProduct;
Debug.Log($"ProcessPurchase (click for more info):" +
$"\n{JsonConvert.SerializeObject(product)}");
return PurchaseProcessingResult.Pending;
}
[ContextMenu("Buy")]
public void Buy()
{
var sku = _storeController.products.all[0].definition.id;
_storeController.InitiatePurchase(sku);
}
}
[1]: https://docs.unity3d.com/Manual/UnityIAPProcessingPurchases.html
↧