Search in sources :

Example 51 with Configuration

use of com.braintreepayments.api.models.Configuration 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)

Example 52 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class IdealUnitTest method onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback.

@Test(timeout = 10000)
public void onActivityResult_checksPaymentStatusOnceBeforeInvokingCallback() throws InvalidArgumentException, JSONException, InterruptedException {
    Configuration configuration = new TestConfigurationBuilder().ideal(new TestIdealConfigurationBuilder().routeId("some-route-id")).braintreeApi(new TestBraintreeApiConfigurationBuilder().accessToken("access-token").url("http://api.braintree.com")).buildConfiguration();
    final BraintreeFragment fragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(configuration).build();
    BraintreeApiHttpClient apiHttpClient = mock(BraintreeApiHttpClient.class);
    when(fragment.getBraintreeApiHttpClient()).thenReturn(apiHttpClient);
    final String resultFixture = stringFromFixture("payment_methods/pending_ideal_bank_payment.json");
    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(resultFixture);
            latch.countDown();
            return null;
        }
    }).when(apiHttpClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
    IdealResult idealResult = IdealResult.fromJson(resultFixture);
    putResultIdInPrefs(idealResult.getId());
    Ideal.onActivityResult(fragment, Activity.RESULT_OK);
    latch.await();
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeApiHttpClient(com.braintreepayments.api.internal.BraintreeApiHttpClient) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) TestBraintreeApiConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder) TestIdealConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 53 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class PayPalRequestUnitTest method getBillingAgreementRequest_buildsWithLiveStageUrl.

@Test
public void getBillingAgreementRequest_buildsWithLiveStageUrl() throws JSONException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_live_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build();
    Request request = PayPal.getBillingAgreementRequest(fragment, null);
    assertEquals(EnvironmentManager.LIVE, request.getEnvironment());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Test(org.junit.Test)

Example 54 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class PayPalRequestUnitTest method getAuthorizationRequest_containsCorrectValues.

@Test
public void getAuthorizationRequest_containsCorrectValues() throws JSONException, InvalidArgumentException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.authorization(Authorization.fromString(TOKENIZATION_KEY)).configuration(configuration).build();
    AuthorizationRequest request = PayPal.getAuthorizationRequest(fragment);
    assertEquals(EnvironmentManager.MOCK, request.getEnvironment());
    assertEquals("com.braintreepayments.api.braintree://onetouch/v1/cancel", request.getCancelUrl());
    assertEquals("com.braintreepayments.api.braintree://onetouch/v1/success", request.getSuccessUrl());
    assertEquals("paypal_client_id", request.getClientId());
    assertEquals(configuration.getPayPal().getPrivacyUrl(), request.getPrivacyUrl());
    assertEquals(configuration.getPayPal().getUserAgreementUrl(), request.getUserAgreementUrl());
    String[] scopes = request.getScopeString().split(" ");
    Arrays.sort(scopes);
    assertEquals(2, scopes.length);
    assertEquals("email", scopes[0]);
    assertEquals("https://uri.paypal.com/services/payments/futurepayments", scopes[1]);
}
Also used : AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Configuration(com.braintreepayments.api.models.Configuration) Test(org.junit.Test)

Example 55 with Configuration

use of com.braintreepayments.api.models.Configuration in project braintree_android by braintree.

the class PayPalRequestUnitTest method getAuthorizationRequest_buildsWithOfflineStageUrl.

@Test
public void getAuthorizationRequest_buildsWithOfflineStageUrl() throws JSONException, InvalidArgumentException {
    Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json"));
    BraintreeFragment fragment = mMockFragmentBuilder.authorization(Authorization.fromString(TOKENIZATION_KEY)).configuration(configuration).build();
    Request request = PayPal.getAuthorizationRequest(fragment);
    assertEquals(EnvironmentManager.MOCK, request.getEnvironment());
}
Also used : Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) Test(org.junit.Test)

Aggregations

Configuration (com.braintreepayments.api.models.Configuration)84 Test (org.junit.Test)66 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)35 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)19 JSONException (org.json.JSONException)19 Authorization (com.braintreepayments.api.models.Authorization)14 Intent (android.content.Intent)13 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)12 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)11 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)11 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)11 JSONObject (org.json.JSONObject)11 UnexpectedException (com.braintreepayments.api.exceptions.UnexpectedException)10 SharedPreferencesHelper.writeMockConfiguration (com.braintreepayments.testutils.SharedPreferencesHelper.writeMockConfiguration)10 Request (com.paypal.android.sdk.onetouch.core.Request)10 Bundle (android.os.Bundle)9 BraintreeFragmentTestUtils.getMockFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getMockFragmentWithConfiguration)6 BraintreeFragmentTestUtils.getFragmentWithConfiguration (com.braintreepayments.api.BraintreeFragmentTestUtils.getFragmentWithConfiguration)5