use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class TokenizationClient method tokenize.
/**
* Create a {@link PaymentMethodNonce} in the Braintree Gateway.
* <p/>
* On completion, returns the {@link PaymentMethodNonce} to {@link PaymentMethodNonceCallback}.
* <p/>
* If creation fails validation, {@link com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)}
* will be called with the resulting {@link ErrorWithResponse}.
* <p/>
* If an error not due to validation (server error, network issue, etc.) occurs, {@link
* com.braintreepayments.api.interfaces.BraintreeErrorListener#onError(Exception)} (Throwable)}
* will be called with the {@link Exception} that occurred.
*
* @param paymentMethodBuilder {@link PaymentMethodBuilder} for the {@link PaymentMethodNonce}
* to be created.
*/
static void tokenize(final BraintreeFragment fragment, final PaymentMethodBuilder paymentMethodBuilder, final PaymentMethodNonceCallback callback) {
paymentMethodBuilder.setSessionId(fragment.getSessionId());
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
if (paymentMethodBuilder instanceof CardBuilder && configuration.getGraphQL().isFeatureEnabled(GraphQLConfiguration.TOKENIZE_CREDIT_CARDS_FEATURE)) {
tokenizeGraphQL(fragment, (CardBuilder) paymentMethodBuilder, callback);
} else {
tokenizeRest(fragment, paymentMethodBuilder, callback);
}
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class AmericanExpress method getRewardsBalance.
/**
* Gets the rewards balance associated with a Braintree nonce. Only for American Express cards.
*
* @param fragment the {@link BraintreeFragment} This fragment will also be responsible
* for handling callbacks to it's listeners
* @param nonce A nonce representing a card that will be used to look up the rewards balance
* @param currencyIsoCode The currencyIsoCode to use. Example: 'USD'
*/
public static void getRewardsBalance(final BraintreeFragment fragment, final String nonce, final String currencyIsoCode) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
String getRewardsBalanceUrl = Uri.parse(AMEX_REWARDS_BALANCE_PATH).buildUpon().appendQueryParameter("paymentMethodNonce", nonce).appendQueryParameter("currencyIsoCode", currencyIsoCode).build().toString();
fragment.sendAnalyticsEvent("amex.rewards-balance.start");
fragment.getHttpClient().get(getRewardsBalanceUrl, new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fragment.sendAnalyticsEvent("amex.rewards-balance.success");
try {
fragment.postAmericanExpressCallback(AmericanExpressRewardsBalance.fromJson(responseBody));
} catch (JSONException e) {
fragment.sendAnalyticsEvent("amex.rewards-balance.parse.failed");
fragment.postCallback(e);
}
}
@Override
public void failure(Exception exception) {
fragment.postCallback(exception);
fragment.sendAnalyticsEvent("amex.rewards-balance.error");
}
});
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class AndroidPay method requestAndroidPay.
/**
* @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>
*
* Launch an Android Pay masked wallet request. This method will show the payment instrument
* chooser to the user.
*
* @param fragment The current {@link BraintreeFragment}.
* @param cart The cart representation with price, currency code, and optionally items.
* @param shippingAddressRequired {@code true} if this request requires a shipping address, {@code false} otherwise.
* @param phoneNumberRequired {@code true} if this request requires a phone number, {@code false} otherwise.
* @param allowedCountries ISO 3166-2 country codes that shipping is allowed to.
*/
@Deprecated
public static void requestAndroidPay(final BraintreeFragment fragment, @NonNull final Cart cart, final boolean shippingAddressRequired, final boolean phoneNumberRequired, final ArrayList<CountrySpecification> allowedCountries) {
fragment.sendAnalyticsEvent("android-pay.selected");
if (!validateManifest(fragment.getApplicationContext())) {
fragment.postCallback(new BraintreeException("AndroidPayActivity was not found in the Android manifest, " + "or did not have a theme of R.style.bt_transparent_activity"));
fragment.sendAnalyticsEvent("android-pay.failed");
return;
}
if (cart == null) {
fragment.postCallback(new BraintreeException("Cannot pass null cart to performMaskedWalletRequest"));
fragment.sendAnalyticsEvent("android-pay.failed");
return;
}
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.sendAnalyticsEvent("android-pay.started");
Intent intent = new Intent(fragment.getApplicationContext(), AndroidPayActivity.class).putExtra(EXTRA_ENVIRONMENT, GooglePayment.getEnvironment(configuration.getAndroidPay())).putExtra(EXTRA_MERCHANT_NAME, configuration.getAndroidPay().getDisplayName()).putExtra(EXTRA_CART, cart).putExtra(EXTRA_TOKENIZATION_PARAMETERS, GooglePayment.getTokenizationParameters(fragment)).putIntegerArrayListExtra(EXTRA_ALLOWED_CARD_NETWORKS, GooglePayment.getAllowedCardNetworks(fragment)).putExtra(EXTRA_SHIPPING_ADDRESS_REQUIRED, shippingAddressRequired).putExtra(EXTRA_PHONE_NUMBER_REQUIRED, phoneNumberRequired).putParcelableArrayListExtra(EXTRA_ALLOWED_COUNTRIES, allowedCountries).putExtra(EXTRA_REQUEST_TYPE, AUTHORIZE);
fragment.startActivityForResult(intent, BraintreeRequestCodes.ANDROID_PAY);
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class BraintreeFragment method fetchConfiguration.
@VisibleForTesting
protected void fetchConfiguration() {
if (getConfiguration() != null || ConfigurationManager.isFetchingConfiguration() || mAuthorization == null || mHttpClient == null) {
return;
}
if (mConfigurationRequestAttempts >= 3) {
postCallback(new ConfigurationException("Configuration retry limit has been exceeded. Create a new " + "BraintreeFragment and try again."));
return;
}
mConfigurationRequestAttempts++;
ConfigurationManager.getConfiguration(this, new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
setConfiguration(configuration);
postConfigurationCallback();
flushCallbacks();
}
}, new BraintreeResponseListener<Exception>() {
@Override
public void onResponse(final Exception e) {
final ConfigurationException exception = new ConfigurationException("Request for configuration has failed: " + e.getMessage() + ". " + "Future requests will retry up to 3 times", e);
postCallback(exception);
postOrQueueCallback(new QueuedCallback() {
@Override
public boolean shouldRun() {
return mConfigurationErrorListener != null;
}
@Override
public void run() {
mConfigurationErrorListener.onResponse(exception);
}
});
flushCallbacks();
}
});
}
use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.
the class BraintreeFragmentUnitTest method waitForConfiguration_postsCallbackWhenFragmentIsAttached.
@Test
public void waitForConfiguration_postsCallbackWhenFragmentIsAttached() throws JSONException, InvalidArgumentException {
final Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/configuration.json"));
mockConfigurationManager(configuration);
final BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration returnedConfiguration) {
assertTrue(fragment.isAdded());
mCalled.set(true);
}
});
assertTrue(mCalled.get());
}
Aggregations