com.android.billingclient.api.BillingFlowParams Java Examples

The following examples show how to use com.android.billingclient.api.BillingFlowParams. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
public void startPurchaseFlow(final SkuDetails skuDetails) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                    .setSkuDetails(skuDetails)
                    .build();
            int responseCode = mBillingClient.launchBillingFlow(mActivity, billingFlowParams).getResponseCode();
            //PPApplication.logE(TAG, "startPurchaseFlow responseCode="+responseCode);
            getFragment().displayAnErrorIfNeeded(responseCode);
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #2
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
public void launchBilling(String skuId) {
    if (billingServiceConnected) {

        if (!mSkuDetailsMap.isEmpty()) {

            Log.i(LOG_TAG, "Launch billing");

            new PrefManager(activity).setBoolPref("helper_no_show_pending_purchase", false);

            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                    .setSkuDetails(mSkuDetailsMap.get(skuId))
                    .build();
            mBillingClient.launchBillingFlow(activity, billingFlowParams);
        } else {
            Log.w(LOG_TAG, "Launch billing but details map is empty");
        }

    } else {
        Log.w(LOG_TAG, "Launch billing but billing client is disconnected");
        mBillingClient.startConnection(this);
    }
}
 
Example #3
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void onPurchase(Intent intent) {
    if (Helper.isPlayStoreInstall()) {
        BillingFlowParams.Builder flowParams = BillingFlowParams.newBuilder();
        if (skuDetails.containsKey(getSkuPro())) {
            Log.i("IAB purchase SKU=" + skuDetails.get(getSkuPro()));
            flowParams.setSkuDetails(skuDetails.get(getSkuPro()));
        }

        BillingResult result = billingClient.launchBillingFlow(this, flowParams.build());
        if (result.getResponseCode() != BillingClient.BillingResponseCode.OK)
            reportError(result, "IAB launch billing flow");
    } else
        try {
            Uri uri = Uri.parse(BuildConfig.PRO_FEATURES_URI + "?challenge=" + getChallenge(this));
            Helper.view(this, uri, true);
        } catch (NoSuchAlgorithmException ex) {
            Log.unexpectedError(getSupportFragmentManager(), ex);
        }
}
 
Example #4
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 6 votes vote down vote up
private void purchase(final String identifier, final Boolean consume, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            int responseCode = billingClient.launchBillingFlow(
                    activity,
                    BillingFlowParams.newBuilder()
                                     .setSku(identifier)
                                     .setType(SkuType.INAPP)
                                     .build());

            if (responseCode == BillingResponse.OK) {
                PurchaseRequest request = new PurchaseRequest(identifier, consume, result);
                pendingPurchaseRequests.add(request);
            } else {
                result.error("ERROR", "Failed to launch billing flow to purchase an item with error " + responseCode, null);
            }
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #5
Source File: DefaultBillingManager.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void launchBillingFlow(Activity activity, BillingProduct product) {
    if (getStatus().getValue() != BillingManagerStatus.OK) {
        if (activity instanceof FragmentActivity) {
            FragmentActivity fragmentActivity = (FragmentActivity) activity;
            SimpleAlertDialogFragment.newInstance(activity, R.string.error, R.string.donate_billing_not_available).show(fragmentActivity.getSupportFragmentManager(), null);
        }
        return;
    }

    BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
            .setSkuDetails(((SkuDetailsBillingProduct) product).getSkuDetails())
            .build();

    mBillingClient.launchBillingFlow(activity, billingFlowParams);
}
 
Example #6
Source File: MainActivity.java    From FCM-for-Mojo with GNU General Public License v3.0 6 votes vote down vote up
private void showDonateGooglePlay() {
    mBillingClient = BillingClient.newBuilder(this).setListener(this).build();

    mBillingClient.startConnection(new BillingClientStateListener() {
        @Override
        public void onBillingSetupFinished(@BillingResponse int billingResponseCode) {
            if (billingResponseCode == BillingResponse.OK) {
                // The billing client is ready. You can query purchases here.
                BillingFlowParams flowParams = BillingFlowParams.newBuilder()
                        .setSku("donate_2")
                        .setType(SkuType.INAPP)
                        .build();
                mBillingClient.launchBillingFlow(MainActivity.this, flowParams);
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            // Try to restart the connection on the next request to
            // Google Play by calling the startConnection() method.
        }
    });
}
 
Example #7
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
public void startPurchaseFlow(final String skuId, final String billingType) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                    .setType(billingType)
                    .setSku(skuId)
                    .build();
            mBillingClient.launchBillingFlow(mActivity, billingFlowParams);
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #8
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
public void doPurchase(final String skuId) {
    Runnable purchaseFlowRequest = () -> {
        BillingFlowParams purchaseParams = BillingFlowParams.newBuilder()
                .setSkuDetails(mSkuDetails.get(skuId))
                .build();
        mBillingClient.launchBillingFlow(Game.instance(), purchaseParams);
    };

    executeServiceRequest(purchaseFlowRequest);
}
 
Example #9
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public void launchBillingFlow(@NonNull final Activity activity, @NonNull String sku, @SkuType String itemType) {
    throwIfUnavailable();
    logSafely("Launching billing flow for " + sku + " with type " + itemType);

    getSkuDetails(
            itemType,
            Collections.singletonList(sku),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    try {
                        if (responseCode == BillingResponse.OK && skuDetailsList.size() > 0) {
                            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                    .setSkuDetails(skuDetailsList.get(0))
                                    .build();

                            // This will call the {@link PurchasesUpdatedListener} specified in {@link #initialize}
                            billing.launchBillingFlow(activity, billingFlowParams);
                        } else {
                            vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                        }
                    } catch (Exception e) {
                        vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                    }
                }
            }
    );
}
 
Example #10
Source File: MainActivity.java    From scroball with MIT License 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  switch (item.getItemId()) {
    case R.id.settings_item:
      Intent intent = new Intent(getBaseContext(), SettingsActivity.class);
      startActivityForResult(intent, 1);
      return true;
    case R.id.remove_ads_item:
      BillingFlowParams.Builder builder =
          new BillingFlowParams.Builder()
              .setSku(REMOVE_ADS_SKU)
              .setType(BillingClient.SkuType.INAPP);
      int responseCode = billingClient.launchBillingFlow(this, builder.build());
      if (responseCode != BillingResponse.OK) {
        purchaseFailed();
      }
      return true;
    case R.id.privacy_policy_item:
      Intent browserIntent =
          new Intent(
              Intent.ACTION_VIEW,
              Uri.parse("https://scroball.peterjosling.com/privacy_policy.html"));
      startActivity(browserIntent);
      return true;
    case R.id.logout_item:
      logout();
      return true;
    default:
      return super.onOptionsItemSelected(item);
  }
}
 
Example #11
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
public void loadSKUs(){
    List<String> skuList = new ArrayList<>();
    skuList.add("upgrade");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult billingResult,
                                                 List<SkuDetails> skuDetailsList) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            if (skuDetails.getSku().equals("upgrade")){
                                findViewById(R.id.upgrade_button).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        BillingFlowParams billingFlowParams = BillingFlowParams
                                                .newBuilder()
                                                .setSkuDetails(skuDetails)
                                                .build();
                                        billingClient.launchBillingFlow(PictureInPictureUpgradeActivity.this, billingFlowParams);
                                    }
                                });
                            }

                        }
                    }
                }
            });
}
 
Example #12
Source File: BillingManager.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
public void launchPurchaseFlow() {
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {
            final BillingFlowParams params = BillingFlowParams.newBuilder()
                    .setSku("remove_ads")
                    .setType(BillingClient.SkuType.INAPP)
                    .build();
            billingClient.launchBillingFlow(activity, params);
        }
    };
    executeServiceRequest(runnable);
}
 
Example #13
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void startPurchaseFlow(String skuId, String billingType) {
    BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
            .setType(billingType)
            .setSku(skuId)
            .build();
    mBillingClient.launchBillingFlow(mActivity, billingFlowParams);
}
 
Example #14
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void buyProduct(@NonNull Activity activity, @NonNull SkuDetails product) {
    BillingFlowParams flowParams = BillingFlowParams.newBuilder()
            .setSkuDetails(product)
            .build();

    BillingResult result = billingClient.launchBillingFlow(activity, flowParams);
    if (result.getResponseCode() != BillingResponseCode.OK)
        handleBillingErrors(result.getResponseCode());
}
 
Example #15
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void subscribe(final String identifier, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            int subscriptionSupportResponse = billingClient.isFeatureSupported(FeatureType.SUBSCRIPTIONS);
            if (BillingResponse.OK != subscriptionSupportResponse) {
                result.error("NOT SUPPORTED", "Subscriptions are not supported.", null);
                return;
            }

            int responseCode = billingClient.launchBillingFlow(
                    activity,
                    BillingFlowParams.newBuilder()
                                     .setSku(identifier)
                                     .setType(SkuType.SUBS)
                                     .build());

            if (responseCode == BillingResponse.OK) {
                PurchaseRequest request = new PurchaseRequest(identifier, result);
                pendingPurchaseRequests.add(request);
            } else {
                result.error("ERROR", "Failed to subscribe with error " + responseCode, null);
            }
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #16
Source File: PlayBillingWrapper.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public boolean launchPaymentFlow(SkuDetails sku) {
    BillingFlowParams params = BillingFlowParams
            .newBuilder()
            .setSkuDetails(sku)
            .build();

    BillingResult result = mClient.launchBillingFlow(mActivity, params);

    return result.getResponseCode() == BillingClient.BillingResponseCode.OK;
}
 
Example #17
Source File: BillingManager.java    From SchoolQuest with GNU General Public License v3.0 4 votes vote down vote up
public void startPurchaseFlow(SkuDetails details) {
    BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder().
            setSkuDetails(details).build();
    mBillingClient.launchBillingFlow(mActivity, billingFlowParams);
}
 
Example #18
Source File: IAPHelper.java    From rootvalidator with GNU General Public License v3.0 4 votes vote down vote up
private BillingFlowParams buildSKUDonateUpgrade() {
    return BillingFlowParams.newBuilder()
            .setSku(SKU_UPGRADE_DONATE)
            .setType(BillingClient.SkuType.INAPP)
            .build();
}
 
Example #19
Source File: GoogleBillingHelper.java    From Augendiagnose with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Launch the purchase flow for a product.
 *
 * @param activity   The triggering activity.
 * @param skuDetails The details of the product to be purchased.
 * @param listener   a listener called after the purchase has been completed.
 */
private void doLaunchPurchaseFlow(final Activity activity, final SkuDetails skuDetails, final OnPurchaseSuccessListener listener) {
	mOnPurchaseSuccessListener = listener;

	Log.d(TAG, "Starting purchase flow for " + skuDetails.getSku());
	mBillingClient.launchBillingFlow(activity, BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build());
}