use of com.braintreepayments.api.models.IdealRequest 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.IdealRequest in project braintree_android by braintree.
the class IdealUnitTest method startPayment_failure_sendsAnalyticsEvent.
@Test
public void startPayment_failure_sendsAnalyticsEvent() throws JSONException, InvalidArgumentException {
mConfiguration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").buildConfiguration();
mBraintreeFragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(mConfiguration).build();
Ideal.startPayment(mBraintreeFragment, new IdealRequest(), null);
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.selected"));
verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.invalid-configuration"));
}
use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealUnitTest method startPayment_startsBrowserWithProperRequestCode.
@Test
public void startPayment_startsBrowserWithProperRequestCode() throws InterruptedException, InvalidArgumentException {
final CountDownLatch latch = new CountDownLatch(1);
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));
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
String requestBody = (String) invocation.getArguments()[1];
JSONObject json = new JSONObject(requestBody);
assertEquals("some-route-id", json.getString("route_id"));
String expectedRedirectUrl = Uri.parse("http://assets.example.com/mobile/ideal-redirect/0.0.0/index.html?redirect_url=" + mBraintreeFragment.getReturnUrlScheme() + "://").toString();
assertEquals(expectedRedirectUrl, json.getString("redirect_url"));
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));
Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {
@Override
public void onResponse(List<IdealBank> idealBanks) {
IdealBank bank = idealBanks.get(0);
IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("1.00").currency("EUR").orderId("abc-123");
Ideal.startPayment(mBraintreeFragment, builder, null);
verify(mBraintreeFragment).browserSwitch(eq(BraintreeRequestCodes.IDEAL), eq("http://approval.example.com/"));
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealTest method startPayment_returnsError_whenOrderId_isAbsent.
@Test(timeout = 10000)
public void startPayment_returnsError_whenOrderId_isAbsent() throws InterruptedException {
IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A");
Ideal.startPayment(mBraintreeFragment, builder, null);
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
assertTrue(error instanceof BraintreeApiErrorResponse);
mCountDownLatch.countDown();
}
});
mBraintreeFragment.addListener(new BraintreePaymentResultListener() {
@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
fail("BraintreeApiErrorResponse expected");
}
});
mCountDownLatch.await();
}
use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealActivity method onItemClick.
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
IdealBank bank = (IdealBank) mIssuingBanksListView.getAdapter().getItem(position);
IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("10").orderId(UUID.randomUUID().toString()).currency("EUR");
Ideal.startPayment(mBraintreeFragment, builder, new BraintreeResponseListener<IdealResult>() {
@Override
public void onResponse(IdealResult idealResult) {
String idealId = idealResult.getId();
}
});
}
Aggregations