use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_success_sendsAnalyticsEvent.
@Test
public void fetchIssuingBanks_success_sendsAnalyticsEvent() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
callback.success(stringFromFixture("payment_methods/ideal_issuing_banks.json"));
return null;
}
}).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.load.succeeded"));
}
});
}
use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.
the class IdealUnitTest method startPayment_success_sendsAnalyticsEvent.
@Test
public void startPayment_success_sendsAnalyticsEvent() throws JSONException {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.success(stringFromFixture("payment_methods/pending_ideal_bank_payment.json"));
return null;
}
}).when(mMockApiClient).post(eq("/ideal-payments"), any(String.class), any(HttpResponseCallback.class));
List<IdealBank> banks = IdealBank.fromJson(mConfiguration, stringFromFixture("payment_methods/ideal_issuing_banks.json"));
IdealRequest builder = new IdealRequest().issuerId(banks.get(0).getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, null);
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.selected"));
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.webswitch.initiate.succeeded"));
}
use of com.braintreepayments.api.models.IdealBank 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.IdealBank in project braintree_android by braintree.
the class IdealActivity method launchIdeal.
public void launchIdeal(View v) {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setTitle("Fetching issuing banks");
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(final List<IdealBank> idealBanks) {
dialog.dismiss();
new AlertDialog.Builder(IdealActivity.this).setTitle("Issuing Banks").setAdapter(new BankListAdapter(IdealActivity.this, idealBanks), new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
IdealBank bank = idealBanks.get(i);
IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("10").orderId(UUID.randomUUID().toString().substring(0, 15)).currency("EUR");
Ideal.startPayment(mBraintreeFragment, builder, new BraintreeResponseListener<IdealResult>() {
@Override
public void onResponse(IdealResult idealResult) {
String idealId = idealResult.getId();
}
});
}
}).create().show();
}
});
dialog.show();
}
use of com.braintreepayments.api.models.IdealBank in project braintree_android by braintree.
the class IdealUnitTest method fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled.
@Test
public void fetchIssuingBanks_postsConfigurationExceptionWhenIdealNotEnabled() throws InvalidArgumentException {
Configuration configuration = new TestConfigurationBuilder().braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
BraintreeFragment fragment = getMockFragment(stringFromFixture("client_token.json"), configuration);
Ideal.fetchIssuingBanks(fragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
fail("Success listener called");
}
});
ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
verify(fragment).postCallback(captor.capture());
Exception e = captor.getValue();
assertEquals("iDEAL is not enabled for this merchant.", e.getMessage());
}
Aggregations