OnPurchaseFailed(Product, PurchaseFailureReason) is not called when using bad network

Unity Version: 2019.4.27f1
IAP package version: 3.0.2, 3.2.1
OS: Android

We need VPN to connect to the store here.

  1. Connect to VPN.
  2. Open my Unity game.
  3. Go to shop.
  4. Disconnect VPN or disable wifi.
  5. Purchase any product.
  6. Can’t receive any callback from IStoreListener, run into a bug.

Log:

2021/05/31 18:33:37.945 16426 23335 Warn BillingClient getSkuDetails() failed. Response code: 2
2021/05/31 18:33:37.962 16426 23157 Error Unity Failed to purchase unknown product productId:Coin2 reason:ProductUnavailable message:SKU does not exist in the store.
2021/05/31 18:33:37.962 16426 23157 Error Unity #0 0x6d08b1bf88 (libunity.so) ? 0x0
2021/05/31 18:33:37.962 16426 23157 Error Unity #1 0x6d089d08b4 (libunity.so) ? 0x0
2021/05/31 18:33:37.962 16426 23157 Error Unity #2 0x6d086b0330 (libunity.so) ? 0x0
2021/05/31 18:33:37.962 16426 23157 Error Unity #3 0x6d086b0260 (libunity.so) ? 0x0

If Skip the step 4, everything is fine. I can make a purchase, or cancel.

public void OnPurchaseFailed(PurchaseFailureDescription description)
{
if (description != null)
{
var product = products.WithStoreSpecificID(description.productId);
if (null == product)
{
m_Logger.LogFormat(LogType.Error, "Failed to purchase unknown product {0}", "productId:" + description.productId + " reason:" + description.reason + " message:" + description.message);
return;
}

m_Logger.LogFormat(LogType.Warning, "onPurchaseFailedEvent({0})", "productId:" + product.definition.id + " message:" + description.message);
m_Listener.OnPurchaseFailed(product, description.reason);
}
}

Code is from PurchasingManager.cs. Is it a bug? why not call the OnPurchaseFailed?

From log, the Sku is wrong. from the log is “Coin2”, it should be my sku "
g7_cpbr012104001.coins500.499
"
So the OnPurchaseFailed(PurchaseFailureDescription description) cannot find the product?
Like fix it with

var product = products.WithStoreSpecificID(description.productId)??products.WithID(description.productId);
```?

Please post only one topic per forum thread, you’ve mentioned two. VPN is not related to productIDs. If you have no network connection, it would be expected that you do not receive any callbacks. Separately, test without using store specific IDs.

It’s same thing, I trace the code, and find out the productID of PurchaseFailureDescription

public void OnPurchaseFailed(PurchaseFailureDescription description)
``` is changed, it should be store specific ID, but it is the ID I put in the "IAP Catalog"

It only happen after IAP is initialized, then I turn off the network.
The above code is from IAP package "PurchasingManager".

If I change code in “OnPurchaseFailed” of “PurchasingManager” to

var product = products.WithStoreSpecificID(description.productId)??products.WithID(description.productId);

It solve my bug. But after I restart Unity, the code is reset.

Sorry I don’t follow, what do you mean by reset. Please compare to the Sample IAP Project v2 https://discussions.unity.com/t/700293/3

Please check your code, it’s you use the wrong product Id.

void OnQuerySkuDetailsResponse(List<AndroidJavaObject> skus, ProductDefinition productToBuy, Product oldProduct, int desiredProrationMode)
{
if (skus?.Count > 0)
{
AndroidJavaObject sku = skus[0];
VerifyAndWarnIfMoreThanOneSku(skus, sku);
AndroidJavaObject billingResult = m_BillingClient.LaunchBillingFlow(sku, oldProduct?.definition?.storeSpecificId, oldProduct?.transactionID, desiredProrationMode);
HandleBillingFlowResult(new GoogleBillingResult(billingResult), sku);
}
else
{
m_GooglePurchaseCallback.OnPurchaseFailed(
new PurchaseFailureDescription(
productToBuy.id,
PurchaseFailureReason.ProductUnavailable,
"SKU does not exist in the store."
)
);
}
}

Code is from “Library/PackageCache/com.unity.purchasing@3.2.1/Runtime/Stores/Android/GooglePlay/AAR/GooglePurchaseService.cs” line 30.

It should use the productToBuy.storeSpecificId, not the productToBuy.id

Later, you use the id here

public void OnPurchaseFailed(PurchaseFailureDescription description)
{
if (description != null)
{
var product = products.WithStoreSpecificID(description.productId);
if (null == product)
{
m_Logger.LogFormat(LogType.Error, "Failed to purchase unknown product {0}", "productId:" + description.productId + " reason:" + description.reason + " message:" + description.message);
return;
}

m_Logger.LogFormat(LogType.Warning, "onPurchaseFailedEvent({0})", "productId:" + product.definition.id + " message:" + description.message);
m_Listener.OnPurchaseFailed(product, description.reason);
}
}

Code is from “Library/PackageCache/com.unity.purchasing@3.2.1/Runtime/Purchasing/PurchasingManager.cs”

I’ve tested and it’s working for me. So everything works for you when you don’t use the store specific ID? Please answer all my questions before skipping to new ones. What do you mean by “reset”?

I don’t use the store specific ID.
I need to change the code “Library/PackageCache/com.unity.purchasing@3.2.1/Runtime/Stores/Android/GooglePlay/AAR/GooglePurchaseService.cs” to solve this bug.
If I restart Unity, all the code under “Library/PackageCache/com.unity.purchasing@3.2.1” revert. That what I mean “reset”.

Understood, I will pass this along to engineering.

Hi densy07, I have looked at your issue.

Are you using codeless? If not, can you share your IAP initialization method?
When no store-specific id is specified for a product, IAP will use its product id as the product’s store-specific id.

Have a good day!

Hi,
My IAP initialization method is same as codeless.
If “IAP will use its product id as the product’s store-specific id”, OnPurchaseFailed of “Library/PackageCache/com.unity.purchasing@3.2.1/Runtime/Purchasing/PurchasingManager.cs” should change with ```
products.WithStoreSpecificID(description.productId)??products.WithID(description.productId);

Please share your initialization code. We need to see how you are adding your products.

I use the “Window/Unity IAP/IAP Catalog” in Unity to add my products.
I have upload my code.

7205722–865480–Hantu_CodelessIAPStoreListener.cs (5.6 KB)
7205722–865483–Hantu_IAPConfigurationHelper.cs (1.29 KB)

You are mixing Codeless and Scripting, unfortunately a common mistake. You are duplicating the IAP callbacks. Please compare to the Sample IAP Project v2 https://discussions.unity.com/t/700293/3

1 Like

I suspect that you are adding empty store-specific ids.
Try changing line 37 in Hantu_IAPConfigurationHelper.cs

from
builder.AddProduct(product.id, product.type, ids);
to
builder.AddProduct(product.id, product.type);

If this solves your issue, a more permanent solution would be to specify your store-specific ids to be the same as your product id in your catalog for all your stores.

And as Jeff said, if this doesn’t work, try adding your products manually instead of using the codeless catalog.

I have disabled the default one.

/// <summary>
/// Enables automatic initialization when using Codeless IAP.
/// </summary>
public bool enableCodelessAutoInitialization = false;

Can I ask a question?
Why GooglePurchaseService.cs pass a Non store-specific id to PurchasingManager.cs, who only handle store-specific id?
I turn off my network after Unity IAP initialized(maybe a bad network), so Unity IAP cant query any sku.