"ProcessPurchase" function calling declined deferred purchase from Google Play Store

Issue:
When testing in-game purchases I noticed that Google Play added new test cases:

  • Slow test card, approves after a few minutes
  • Test card always approves
  • Test card always declines
  • Slow test card, declines after a few minutes

After the purchase is deferred (options 1 and 4) if I close the game and reopen Unity treats the purchase as always approved. Looking at the Google Play receipt, we can see that the purchaseState comes with a value of 4, but in their documentation, there is no such value.
Unity Version:
2019.4.21f1
Unity Purchasing:
2.2.2 & 3.0.1
Platform:
Android
Google Play Receipt
csharp** **{ "Store":"GooglePlay", "TransactionID":"ipnikneneaekgkcggpnoljbi.AO-J1OzoiGA4ysOKYx4acWopYS7rQpam0C-cPCucjpfYtznMnq25Dse-3YLnlZQ9DbA6xk9lKE3_0wnXmie5HGkD8-hflF-p4v3jpqBrl0UFuYTrQGvJfrs", "Payload":{ "json":{ "orderId":"GPA.3377-1455-2559-74643", "packageName":"com.company.game", "productId":"consumable_product_01", "purchaseTime":1615320446688, "purchaseState":4, "purchaseToken":"ipnikneneaekgkcggpnoljbi.AO-J1OzoiGA4ysOKYx4acWopYS7rQpam0C-cPCucjpfYtznMnq25Dse-3YLnlZQ9DbA6xk9lKE3_0wnXmie5HGkD8-hflF-p4v3jpqBrl0UFuYTrQGvJfrs", "acknowledged":false }, "signature":"N0cnw97IKBbO1xYEwgkUu/24MjW0Zr3q9staj0MCSf7nSF6P3seXsdOAxAihB93BWGQcXcRKrboS7qyF/EnFIum/Wg8Adgdq8ccgw0fu1hjQ8q3E152glSjk298/OINfPnIxIvLcngopbCzcRIRfe5JieSgsqhNhOE/qUeS1Djq9e2ndCZEP1DwlFf3mwoEZOJBaXBML4VP4vaDxKmqOwzsMdu061dQBE+Mt7nl1/Ce2iDHClQp+qAqeWv01Pg6+PXTeekoisXPao468aahPC5ecMEAc7h76/O4RRzKJD2v5hizJNSr2Da+yseFxyX5QMvlB5PyxvRIy1pUQPvFKaw==", "skuDetails":{ "productId":"consumable_product_01", "type":"inapp", "price":"R$3.39", "price_amount_micros":3390000, "price_currency_code":"BRL", "title":"Title Here", "description":"Description Here", "skuDetailsToken":"AEuhp4Kr0U7jrNhybxCjbmT8WNXlekMRw3cSTpxQStYabd-GDe5J-arzLR5hoa7UBSaO" } } }** **

1 Like

It’s our understanding that purchaseState of 4 is mapped to 2 (Pending) by the Google API. You should not award the product in this case, but continue to return Pending from ProcessPurchase for these transactions.

In that case, shouldn’t CrossPlatformValidator handle it? else, the IPurchaseReceipt does not have a “Pending” state. See the enum below:

public enum GooglePurchaseState
{
  Purchased,
  Cancelled,
  Refunded,
}

Good point. Instead of requiring you to parse the receipt, the validator could return pending. That would be handy, I’ll bring it up with the dev team

We save purchases in the cloud, so we will always have the purchase as pending. The question is how can we identify the deferred purchase to handle it. About “Instead of parsing the receipt, the validator should return pending” it’s a good idea, I’ll be waiting for your return. Thanks a lot!

1 Like

You need to eventually consume the purchase by calling ConfirmPendingPurchase or returning Complete from ProcessPurchase. This is the typical flow whether you save to the cloud or not. A user would not be able to purchase a consumable product a second time, for example. So for now, you’ll need to parse the receipt.