private void launchPurchaseFlow ( Activity activity , Product product , ItemType itemType , String oldProductId ) { executeServiceRequest ( new Runnable ( ) { @ Override public void run ( ) { if ( itemType . equals ( ItemType . SUBSCRIPTION ) && ! isSubscriptionsSupported ( ) ) { LOGGER . debug ( "Failed in-app purchase flow for product id " + product . getId ( ) + ", item type: " + itemType + ". Subscriptions not supported." ) ; if ( listener != null ) { listener . onPurchaseFailed ( InAppBillingErrorCode . SUBSCRIPTIONS_NOT_AVAILABLE . newErrorCodeException ( ) ) ; } } else { LOGGER . debug ( "Launching in-app purchase flow for product id " + product . getId ( ) + ", item type: " + itemType ) ; String productIdToBuy = InAppBillingAppModule . get ( ) . getInAppBillingContext ( ) . isStaticResponsesEnabled ( ) ? product . getProductType ( ) . getTestProductId ( ) : product . getId ( ) ; BillingFlowParams purchaseParams = BillingFlowParams . newBuilder ( ) . setSku ( productIdToBuy ) . setType ( itemType . getType ( ) ) . setOldSku ( oldProductId ) . build ( ) ; int responseCode = billingClient . launchBillingFlow ( activity , purchaseParams ) ; InAppBillingErrorCode inAppBillingErrorCode = InAppBillingErrorCode . findByErrorResponseCode ( responseCode ) ; if ( inAppBillingErrorCode != null ) { if ( listener != null ) { AbstractApplication . get ( ) . getExceptionHandler ( ) . logHandledException ( inAppBillingErrorCode . newErrorCodeException ( ) ) ; listener . onPurchaseFailed ( inAppBillingErrorCode . newErrorCodeException ( ) ) ; } } } } } ) ; }
Initiate the UI flow for an in - app purchase . Call this method to initiate an in - app purchase which will involve bringing up the Google Play screen . The calling activity will be paused while the user interacts with Google Play This method MUST be called from the UI thread of the Activity .