use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealUnitTest method startPayment_persistsIdealResultId.
@Test
public void startPayment_persistsIdealResultId() throws InvalidArgumentException, 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);
String idealResultId = getResultIdFromPrefs();
assertEquals("ideal_payment_id", idealResultId);
}
use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsExceptionListenerOnHttpError.
@Test
public void startPayment_callsExceptionListenerOnHttpError() throws InvalidArgumentException, JSONException {
final Exception expectedException = new Exception();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2];
callback.failure(expectedException);
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).postCallback(eq(expectedException));
}
use of com.braintreepayments.api.models.IdealRequest in project braintree_android by braintree.
the class IdealUnitTest method startPayment_callsResponseListenerWithPaymentId.
@Test
public void startPayment_callsResponseListenerWithPaymentId() throws InvalidArgumentException, JSONException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
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, new BraintreeResponseListener<IdealResult>() {
@Override
public void onResponse(IdealResult idealResult) {
assertEquals("ideal_payment_id", idealResult.getId());
latch.countDown();
}
});
latch.await();
}
use of com.braintreepayments.api.models.IdealRequest 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.IdealRequest in project braintree_android by braintree.
the class IdealTest method startPayment_returnsPendingPayment.
@Test(timeout = 10000)
public void startPayment_returnsPendingPayment() throws InterruptedException {
IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A").orderId(UUID.randomUUID().toString().substring(0, 15));
Ideal.startPayment(mBraintreeFragment, builder, null);
String savedId;
do {
savedId = BraintreeSharedPreferences.getString(mBraintreeFragment.getApplicationContext(), Ideal.IDEAL_RESULT_ID);
SystemClock.sleep(500);
} while (savedId.equals(""));
Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
mBraintreeFragment.addListener(new BraintreeErrorListener() {
@Override
public void onError(Exception error) {
fail(error.getMessage());
}
});
mBraintreeFragment.addListener(new BraintreePaymentResultListener() {
@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
assertTrue(result instanceof IdealResult);
IdealResult idealResult = (IdealResult) result;
assertFalse(TextUtils.isEmpty(idealResult.getId()));
assertFalse(TextUtils.isEmpty(idealResult.getShortId()));
assertFalse(TextUtils.isEmpty(idealResult.getStatus()));
mCountDownLatch.countDown();
}
});
mCountDownLatch.await();
}
Aggregations