When the user closes the app during the IAP of a Consumable the payment may be registered and processed, but the application isn’t receiving the callback.
On iOS our app receives the transaction when opened again, by the ProcessPurchase
method getting called. On Android, this is not the case.
We are using In App Purchasing version 3.2.3
Here are the most important code snippets of our implementation:
void Start() {
if (m_StoreController == null)
InitializePurchasing();
}
public void InitializePurchasing() {
if (IsInitialized()) {
return;
}
var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
foreach(PurchaseType purchaseType in Enum.GetValues(typeof(PurchaseType))) {
builder.AddProduct(GetProductStringByType(purchaseType), ProductType.Consumable);
}
UnityPurchasing.Initialize(this, builder);
}
void BuyProductID(string productId) {
if (IsInitialized()) {
Product product = m_StoreController.products.WithID(productId);
if (product != null && product.availableToPurchase) {
m_StoreController.InitiatePurchase(product);
}
}
}
public void OnInitialized(IStoreController controller, IExtensionProvider extensions) {
m_StoreController = controller;
m_StoreExtensionProvider = extensions;
foreach (var product in m_StoreController.products.all) {
m_StoreController.ConfirmPendingPurchase(product);
}
}
public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) {
foreach (PurchaseType purchaseType in Enum.GetValues(typeof(PurchaseType))) {
if (String.Equals(args.purchasedProduct.definition.id,
GetProductStringByType(purchaseType), StringComparison.Ordinal)) {
DataManager.Coins += CoinCalculator.GetCoinsByType(purchaseType);
break;
}
}
return PurchaseProcessingResult.Complete;
}
I ommited all code snippets, responsible for error handling, as well as OnPurchaseFailed, OnInitializeFailed and all attributes that lie in the class elsewhere. All methods are packed into a single class, which follows the singleton pattern. An instance of the class exists in the first scene and is set to be DontDestroyOnLoad (aka persists during all scenes).
Now, what method is missing to receive unhandlded transactions on android?
Thanks in advance!
PS: I think the documentation on IAPs isn’t as instructive as it could be. Cases as the one described here aren’t covered comprehensively or not at all. Since developers wanna have their implementation of such a delicate feature as robust as possible, some more in depth tutorials may help here.