Search in sources :

Example 6 with IdealBank

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"));
        }
    });
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) List(java.util.List) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with IdealBank

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"));
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IdealBank

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);
                }
            });
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) IdealBank(com.braintreepayments.api.models.IdealBank) JSONException(org.json.JSONException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) ConfigurationException(com.braintreepayments.api.exceptions.ConfigurationException) JSONException(org.json.JSONException)

Example 9 with IdealBank

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ProgressDialog(android.app.ProgressDialog) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) OnClickListener(android.content.DialogInterface.OnClickListener) List(java.util.List) IdealResult(com.braintreepayments.api.models.IdealResult)

Example 10 with IdealBank

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());
}
Also used : TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) Configuration(com.braintreepayments.api.models.Configuration) IdealBank(com.braintreepayments.api.models.IdealBank) List(java.util.List) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) JSONException(org.json.JSONException) IOException(java.io.IOException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

IdealBank (com.braintreepayments.api.models.IdealBank)14 Test (org.junit.Test)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)9 List (java.util.List)8 JSONObject (org.json.JSONObject)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 Answer (org.mockito.stubbing.Answer)8 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)8 IdealRequest (com.braintreepayments.api.models.IdealRequest)7 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)5 JSONException (org.json.JSONException)5 IOException (java.io.IOException)4 Configuration (com.braintreepayments.api.models.Configuration)3 IdealResult (com.braintreepayments.api.models.IdealResult)3 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1