Search code examples
androidin-app-billingplay-billing-library

onPurchasesUpdated not called for pending purchase success


I have updated my application to use v2.1.0 (from an earlier 2.0.1 release) of the android play billing library and I am no longer receiving purchase updates on completion of a pending purchase.

I construct my billing client setting the listener to the current class, that implements PurchasesUpdatedListener:

billingClient = BillingClient.newBuilder( getActivity() )
        .setListener( this )
        .enablePendingPurchases()
        .build();

I then launch a purchase and use the "slow test card approves after a few minutes"

BillingFlowParams.Builder purchaseParamsBuilder = BillingFlowParams.newBuilder()
        .setSkuDetails( product );

billingClient.launchBillingFlow( getActivity(), purchaseParamsBuilder.build() );

My listener gets called after this indicating the purchase is pending:

@Override
public void onPurchasesUpdated( BillingResult billingResult, List<Purchase> purchases )
{
    int responseCode = billingResult.getResponseCode();
    if (responseCode == BillingClient.BillingResponseCode.OK)
    {
        // I get to here with a Purchase.PurchaseState.PENDING 
    }
}

However this listener does NOT get called when the purchase completes. I leave the application open and I see the notification from the play store saying the purchase was successful in the notification bar.

If I query the purchases manually after this notification I can get the updated purchase however this doesn't seem like a valid approach for handling the purchase.

Does anyone know what I am doing wrong or has this process changed?


Solution

  • This was an issue in the Play Store app (v17.9.17). The code here is correct and there is no error in the usage of the Play Billing library in the above, i.e. onPurchasesUpdated should be called when the pending transaction completes (either successfully or cancelled).

    Google has isolated the issue and it will be fixed in the next update.

    Reference for the bug report can be found here:

    https://issuetracker.google.com/issues/146480197