When a deferred purchase is made, the order number on the google receipt is null. I can confirm that this was not the case in version 4.9. After the purchase is confirmed, the order number takes value.
Unity version: 2021.3.40f1
IAP package: 4.12.2
Platform: Android
Here is the code I use to get receipt:
googlePlayConfiguration = builder.Configure<IGooglePlayConfiguration>();
googlePlayConfiguration.SetDeferredPurchaseListener(OnDeferredPurchase);
private void OnDeferredPurchase(Product product)
{
var orderId = GetOrderId(product);
...
}
string GetOrderId(Product product)
{
try
{
var validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.identifier);
var result = validator.Validate(product.receipt);
foreach (IPurchaseReceipt productReceipt in result)
{
var googleReceipt = productReceipt as GooglePlayReceipt;
if (googleReceipt != null)
{
orderId = googleReceipt.orderID;
Debug.Log(googleReceipt.orderID); // Log: empty
}
}
}
catch (IAPSecurityException ex) { Debug.LogException(ex); }
return orderId;
}