use of com.braintreepayments.api.models.IdealResult in project braintree_android by braintree.
the class IdealUnitTest method onActivityResult_returnsResultToFragment.
@Test
public void onActivityResult_returnsResultToFragment() throws InvalidArgumentException, JSONException, InterruptedException {
putResultIdInPrefs("ideal_payment_id");
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/completed_ideal_bank_payment.json"));
latch.countDown();
return null;
}
}).when(mMockApiClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
latch.await();
ArgumentCaptor<IdealResult> captor = ArgumentCaptor.forClass(IdealResult.class);
verify(mBraintreeFragment).postCallback(captor.capture());
IdealResult capturedResult = captor.getValue();
assertEquals("ideal_payment_id", capturedResult.getId());
assertEquals("short_id", capturedResult.getShortId());
assertEquals("COMPLETE", capturedResult.getStatus());
}
use of com.braintreepayments.api.models.IdealResult 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.IdealResult 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();
}
use of com.braintreepayments.api.models.IdealResult 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.IdealResult 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();
}
Aggregations