@Override @SuppressWarnings("unchecked") public void checkAvailability(@NonNull final Context context, @NonNull PaymentMethod paymentMethod, @NonNull final PaymentMethodAvailabilityCallback callback) { Log.d(TAG, "checkAvailability"); GoogleApiAvailability googleAPI = GoogleApiAvailability.getInstance(); int result = googleAPI.isGooglePlayServicesAvailable(context); if (result != ConnectionResult.SUCCESS) { callback.onFail(new GoogleApiClientNotInitializedException("Google API not available")); } final GoogleApiClient googleApiClient = getGoogleApiClient(context); if (googleApiClient != null) { googleApiClient.connect(); Wallet.Payments.isReadyToPay(googleApiClient).setResultCallback( new ResultCallback<BooleanResult>() { @Override public void onResult(@NonNull BooleanResult booleanResult) { if (booleanResult.getStatus().isSuccess()) { callback.onSuccess(booleanResult.getValue()); } else { Log.e(TAG, "isReadyToPay:" + booleanResult.getStatus()); String errorMessage = booleanResult.getStatus().getStatusCode() + booleanResult.getStatus().getStatusMessage(); callback.onFail(new Throwable(errorMessage)); } } }); } else { callback.onFail(new GoogleApiClientNotInitializedException( "Google API client is null or not connected")); } }
private void readyToPayRequest(){ IsReadyToPayRequest req = IsReadyToPayRequest.newBuilder() .addAllowedCardNetwork(WalletConstants.CardNetwork.MASTERCARD) .addAllowedCardNetwork(WalletConstants.CardNetwork.VISA) .addAllowedCardNetwork(WalletConstants.CardNetwork.AMEX) .addAllowedCardNetwork(WalletConstants.CardNetwork.DISCOVER) .build(); Wallet.Payments.isReadyToPay(mGoogleApiClient, req) .setResultCallback(new ResultCallback<BooleanResult>() { @Override public void onResult(@NonNull BooleanResult booleanResult) { if (booleanResult.getStatus().isSuccess()) { if (booleanResult.getValue()) { //Log.i(TAG, "Android Pay is ready"); Toast.makeText(getBaseContext(), "Android Pay is ready", Toast.LENGTH_LONG).show(); showAndroidPayButton(); return; } } //Log.i(TAG, "Android Pay not ready"); Toast.makeText(getBaseContext(), "Android Pay not ready", Toast.LENGTH_LONG).show(); hideAndroidPayButton(); } }); }
private void validateAndroidPay() { showProgressDialog(); Wallet.Payments.isReadyToPay(mGoogleApiClient).setResultCallback( new ResultCallback<BooleanResult>() { @Override public void onResult(@NonNull BooleanResult booleanResult) { hideProgressDialog(); if (booleanResult.getStatus().isSuccess()) { if (booleanResult.getValue()) { // Show Android Pay buttons and hide regular checkout button Log.d(tag, "isReadyToPay:true"); createAndAddWalletFragment(); findViewById(R.id.button_regular_checkout).setVisibility(View.GONE); } else { // Hide Android Pay buttons, show a message that Android Pay // cannot be used yet, and display a traditional checkout button Log.d(tag, "isReadyToPay:false:" + booleanResult.getStatus()); findViewById(R.id.checkout_fragment_container).setVisibility(View.GONE); findViewById(R.id.android_pay_message).setVisibility(View.VISIBLE); findViewById(R.id.button_regular_checkout).setVisibility(View.VISIBLE); } } else { // Error making isReadyToPay call Log.e(tag, "isReadyToPay:" + booleanResult.getStatus()); } } } ); }
/** * @deprecated Android Pay is deprecated, use {@link GooglePayment} instead. For more information see the * <a href="https://developers.braintreepayments.com/guides/pay-with-google/overview">documentation</a> * * Before starting the Android Pay flow, use * {@link #isReadyToPay(BraintreeFragment, BraintreeResponseListener)} to check whether the * user has the Android Pay app installed and is ready to pay. When the listener is called with * {@code true}, show the Android Pay button. When it is called with {@code false}, display other * checkout options along with text notifying the user to set up the Android Pay app. * * @param fragment {@link BraintreeFragment} * @param listener Instance of {@link BraintreeResponseListener<Boolean>} to receive the * isReadyToPay response. */ @Deprecated public static void isReadyToPay(final BraintreeFragment fragment, final BraintreeResponseListener<Boolean> listener) { fragment.waitForConfiguration(new ConfigurationListener() { @Override public void onConfigurationFetched(Configuration configuration) { if (!configuration.getAndroidPay().isEnabled(fragment.getApplicationContext())) { listener.onResponse(false); return; } fragment.getGoogleApiClient(new BraintreeResponseListener<GoogleApiClient>() { @Override public void onResponse(GoogleApiClient googleApiClient) { Wallet.Payments.isReadyToPay(googleApiClient).setResultCallback( new ResultCallback<BooleanResult>() { @Override public void onResult(@NonNull BooleanResult booleanResult) { listener.onResponse(booleanResult.getStatus().isSuccess() && booleanResult.getValue()); } }); } }); } }); }
void init() { simplify = ((SimplifyApplication) getApplication()).getSimplify(); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(Wallet.API, new Wallet.WalletOptions.Builder() .setEnvironment(Constants.WALLET_ENVIRONMENT) .setTheme(WalletConstants.THEME_LIGHT) .build()) .build(); TextView amountView = (TextView) findViewById(R.id.amount); amountView.setText(Constants.AMOUNT); mPayButton = (Button) findViewById(R.id.btnPay); mPayButton.setEnabled(false); mPayButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { requestCardToken(); } }); mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); mCardEditor = (CardEditor) findViewById(R.id.card_editor); mCardEditor.addOnStateChangedListener(new CardEditor.OnStateChangedListener() { @Override public void onStateChange(CardEditor cardEditor) { mPayButton.setEnabled(cardEditor.isValid()); } }); IsReadyToPayRequest req = IsReadyToPayRequest.newBuilder() .addAllowedCardNetwork(WalletConstants.CardNetwork.MASTERCARD) .addAllowedCardNetwork(WalletConstants.CardNetwork.VISA) .addAllowedCardNetwork(WalletConstants.CardNetwork.AMEX) .addAllowedCardNetwork(WalletConstants.CardNetwork.DISCOVER) .build(); Wallet.Payments.isReadyToPay(mGoogleApiClient, req) .setResultCallback(new ResultCallback<BooleanResult>() { @Override public void onResult(@NonNull BooleanResult booleanResult) { if (booleanResult.getStatus().isSuccess()) { if (booleanResult.getValue()) { Log.i(TAG, "Android Pay is ready"); showAndroidPayButton(); return; } } Log.i(TAG, "Android Pay not ready"); hideAndroidPayButton(); } }); }
private void initAndroidPay(Context context) { if (Build.VERSION.SDK_INT < 19) { return; } googleApiClient = new GoogleApiClient.Builder(context) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(Bundle bundle) { } @Override public void onConnectionSuspended(int i) { } }) .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(ConnectionResult connectionResult) { } }) .addApi(Wallet.API, new Wallet.WalletOptions.Builder() .setEnvironment(paymentForm.invoice.test ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION) .setTheme(WalletConstants.THEME_LIGHT) .build()) .build(); Wallet.Payments.isReadyToPay(googleApiClient).setResultCallback( new ResultCallback<BooleanResult>() { @Override public void onResult(BooleanResult booleanResult) { if (booleanResult.getStatus().isSuccess()) { if (booleanResult.getValue()) { showAndroidPay(); } } else { } } } ); googleApiClient.connect(); }