Search in sources :

Example 11 with ConfigurationListener

use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.

the class CardTest method setupBraintreeFragment.

private BraintreeFragment setupBraintreeFragment(String authorization) throws Exception {
    final BraintreeFragment fragment = BraintreeFragment.newInstance(mActivityTestRule.getActivity(), authorization);
    final CountDownLatch latch = new CountDownLatch(1);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (mRequestProtocol.equals(REST)) {
                try {
                    JSONObject configJson = new JSONObject(configuration.toJson());
                    configJson.remove("graphQL");
                    fragment.setConfiguration(Configuration.fromJson(configJson.toString()));
                } catch (JSONException ignored) {
                }
                assertFalse(fragment.getConfiguration().getGraphQL().isEnabled());
            } else if (mRequestProtocol.equals(GRAPHQL)) {
                assertTrue(configuration.getGraphQL().isEnabled());
            }
            latch.countDown();
        }
    });
    latch.await();
    return fragment;
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with ConfigurationListener

use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.

the class GooglePaymentTest method getAllowedCardNetworks_returnsSupportedNetworks.

@Test(timeout = 5000)
public void getAllowedCardNetworks_returnsSupportedNetworks() throws InterruptedException {
    String configuration = mBaseConfiguration.androidPay(mBaseConfiguration.androidPay().supportedNetworks(new String[] { "visa", "mastercard", "amex", "discover" })).build();
    final BraintreeFragment fragment = getFragmentWithConfiguration(mActivityTestRule.getActivity(), configuration);
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Collection<Integer> allowedCardNetworks = GooglePayment.getAllowedCardNetworks(fragment);
            assertEquals(4, allowedCardNetworks.size());
            assertTrue(allowedCardNetworks.contains(CardNetwork.VISA));
            assertTrue(allowedCardNetworks.contains(CardNetwork.MASTERCARD));
            assertTrue(allowedCardNetworks.contains(CardNetwork.AMEX));
            assertTrue(allowedCardNetworks.contains(CardNetwork.DISCOVER));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Collection(java.util.Collection) Test(org.junit.Test)

Example 13 with ConfigurationListener

use of com.braintreepayments.api.interfaces.ConfigurationListener in project braintree_android by braintree.

the class GooglePaymentTest method getTokenizationParameters_includesATokenizationKeyWhenPresent.

@Test(timeout = 5000)
public void getTokenizationParameters_includesATokenizationKeyWhenPresent() throws Exception {
    final BraintreeFragment fragment = getFragment(mActivityTestRule.getActivity(), TOKENIZATION_KEY, mBaseConfiguration.withAnalytics().build());
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            Bundle tokenizationParameters = GooglePayment.getTokenizationParameters(fragment).getParameters();
            assertEquals(TOKENIZATION_KEY, tokenizationParameters.getString("braintree:clientKey"));
            mLatch.countDown();
        }
    });
    mLatch.await();
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreeFragmentTestUtils.getFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration) BraintreeFragmentTestUtils.getMockFragmentWithConfiguration(com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Bundle(android.os.Bundle) Test(org.junit.Test)

Example 14 with ConfigurationListener

use of com.braintreepayments.api.interfaces.ConfigurationListener 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 15 with ConfigurationListener

use of com.braintreepayments.api.interfaces.ConfigurationListener 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);
                }
            });
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) Configuration(com.braintreepayments.api.models.Configuration) JSONObject(org.json.JSONObject) 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) IdealResult(com.braintreepayments.api.models.IdealResult)

Aggregations

ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)37 Configuration (com.braintreepayments.api.models.Configuration)36 Test (org.junit.Test)21 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)15 JSONException (org.json.JSONException)12 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 ConfigurationException (com.braintreepayments.api.exceptions.ConfigurationException)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)4 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)4 BraintreeHttpClient (com.braintreepayments.api.internal.BraintreeHttpClient)4 JSONObject (org.json.JSONObject)4 Bundle (android.os.Bundle)3 Intent (android.content.Intent)2 BraintreeResponseListener (com.braintreepayments.api.interfaces.BraintreeResponseListener)2 UnionPayConfiguration (com.braintreepayments.api.models.UnionPayConfiguration)2 Uri (android.net.Uri)1