use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class GooglePaymentTest method getTokenizationParameters_includesATokenizationKeyWhenPresent.
@Test(timeout = 5000)
public void getTokenizationParameters_includesATokenizationKeyWhenPresent() throws Exception {
final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, mBaseConfiguration.withAnalytics().build());
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
assertEquals(TOKENIZATION_KEY, tokenizationParameters.getString("braintree:clientKey"));
mLatch.countDown();
}
});
mLatch.await();
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class GooglePaymentTest method getTokenizationParameters_returnsCorrectParametersInCallback.
@Test(timeout = 5000)
public void getTokenizationParameters_returnsCorrectParametersInCallback() throws Exception {
String config = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
final Configuration configuration = Configuration.fromJson(config);
BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, config);
GooglePayment.getTokenizationParameters(fragment, new TokenizationParametersListener() {
@Override
public void onResult(PaymentMethodTokenizationParameters parameters, Collection<Integer> allowedCardNetworks) {
assertEquals("braintree", parameters.getParameters().getString("gateway"));
assertEquals(configuration.getMerchantId(), parameters.getParameters().getString("braintree:merchantId"));
assertEquals(configuration.getAndroidPay().getGoogleAuthorizationFingerprint(), parameters.getParameters().getString("braintree:authorizationFingerprint"));
assertEquals("v1", parameters.getParameters().getString("braintree:apiVersion"));
assertEquals(BuildConfig.VERSION_NAME, parameters.getParameters().getString("braintree:sdkVersion"));
try {
JSONObject metadata = new JSONObject(parameters.getParameters().getString("braintree:metadata"));
assertNotNull(metadata);
assertEquals(BuildConfig.VERSION_NAME, metadata.getString("version"));
assertNotNull(metadata.getString("sessionId"));
assertEquals("custom", metadata.getString("integration"));
assertEquals("android", metadata.get("platform"));
} catch (JSONException e) {
fail("Failed to unpack json from tokenization parameters: " + e.getMessage());
}
assertEquals(4, allowedCardNetworks.size());
assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
mLatch.countDown();
}
});
mLatch.await();
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class Ideal method fetchIssuingBanks.
/**
* Makes a call to fetch the list of potential issuing banks with which a customer can pay.
*
* @param fragment {@link BraintreeFragment}
* @param listener {@link BraintreeResponseListener} the callback to which a list of issuing banks will be provided.
*/
public static void fetchIssuingBanks(final BraintreeFragment fragment, final BraintreeResponseListener<List<IdealBank>> listener) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(final Configuration configuration) {
Exception configException = checkIdealEnabled(configuration);
if (configException != null) {
fragment.postCallback(configException);
return;
}
fragment.getBraintreeApiHttpClient().get("/issuers/ideal", new HttpResponseCallback() {
@Override
public void success(String responseBody) {
fragment.sendAnalyticsEvent("ideal.load.succeeded");
try {
List<IdealBank> banks = IdealBank.fromJson(configuration, responseBody);
if (listener != null) {
listener.onResponse(banks);
}
} catch (JSONException jsonException) {
failure(jsonException);
}
}
@Override
public void failure(Exception exception) {
fragment.sendAnalyticsEvent("ideal.load.failed");
fragment.postCallback(exception);
}
});
}
});
}
use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.
the class Ideal method startPayment.
/**
* Initiates the payment flow by opening a browser where the customer can authenticate with their bank.
*
* @param fragment {@link BraintreeFragment}
* @param builder {@link IdealRequest} with the payment details.
* @param listener {@link BraintreeResponseListener} the callback to which the {@link IdealResult} will be sent
* with a status of `PENDING` before the flow starts. This result contains the iDEAL payment ID.
*/
public static void startPayment(final BraintreeFragment fragment, final IdealRequest builder, final BraintreeResponseListener<IdealResult> listener) {
fragment.waitForConfiguration(new ConfigurationListener() {
@Override
public void onConfigurationFetched(Configuration configuration) {
fragment.sendAnalyticsEvent("ideal.start-payment.selected");
Exception configException = checkIdealEnabled(configuration);
if (configException != null) {
fragment.postCallback(configException);
fragment.sendAnalyticsEvent("ideal.start-payment.invalid-configuration");
return;
}
String redirectUrl = URI.create(configuration.getIdealConfiguration().getAssetsUrl() + ASSET_SERVER_REDIRECT_PATH + fragment.getReturnUrlScheme() + "://").toString();
fragment.getBraintreeApiHttpClient().post("/ideal-payments", builder.build(redirectUrl, configuration.getIdealConfiguration().getRouteId()), new HttpResponseCallback() {
@Override
public void success(String responseBody) {
try {
IdealResult idealResult = IdealResult.fromJson(responseBody);
BraintreeSharedPreferences.putString(fragment.getApplicationContext(), IDEAL_RESULT_ID, idealResult.getId());
if (listener != null) {
listener.onResponse(idealResult);
}
JSONObject responseJson = new JSONObject(responseBody);
String approvalUrl = responseJson.getJSONObject("data").getString("approval_url");
fragment.browserSwitch(BraintreeRequestCodes.IDEAL, approvalUrl);
fragment.sendAnalyticsEvent("ideal.webswitch.initiate.succeeded");
} catch (JSONException jsonException) {
failure(jsonException);
}
}
@Override
public void failure(Exception exception) {
fragment.sendAnalyticsEvent("ideal.webswitch.initiate.failed");
fragment.postCallback(exception);
}
});
}
});
}
use of com.braintreepayments.api.models.Configuration 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);
}
}
});
}
Aggregations