Search in sources :

Example 6 with IdealResult

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

the class IdealActivity method onBraintreePaymentResult.

@Override
public void onBraintreePaymentResult(BraintreePaymentResult result) {
    super.onBraintreePaymentResult(result);
    IdealResult idealResult = (IdealResult) result;
    if (!mIsPolling && !("COMPLETE".equals(idealResult.getStatus()))) {
        try {
            Ideal.pollForCompletion(mBraintreeFragment, idealResult.getId(), 1, 1000);
            mIsPolling = true;
        } catch (InvalidArgumentException e) {
            onError(e);
        }
    } else {
        Intent intent = new Intent().putExtra(MainActivity.EXTRA_PAYMENT_RESULT, result);
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}
Also used : InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) Intent(android.content.Intent) IdealResult(com.braintreepayments.api.models.IdealResult)

Example 7 with IdealResult

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

the class MainActivity method displayBraintreeResult.

private void displayBraintreeResult(BraintreePaymentResult result) {
    if (result instanceof IdealResult) {
        IdealResult idealResult = (IdealResult) result;
        mNonceString.setText("iDEAL payment id: \n" + idealResult.getId());
        mNonceString.setVisibility(VISIBLE);
        mNonceDetails.setText("iDEAL payment status: \n" + idealResult.getStatus());
        mNonceDetails.setVisibility(VISIBLE);
        mCreateTransactionButton.setEnabled(false);
    }
}
Also used : IdealResult(com.braintreepayments.api.models.IdealResult)

Example 8 with IdealResult

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

the class IdealUnitTest method pollForCompletion_pollsUntilMaxRetryCountExceeded.

@Test(timeout = 5000)
public void pollForCompletion_pollsUntilMaxRetryCountExceeded() throws InterruptedException, JSONException, InvalidArgumentException {
    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(2);
    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.pollForCompletion(fragment, idealResult.getId(), 1, 1000);
    // Two retries = three calls to latch.countDown
    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 9 with IdealResult

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

the class IdealUnitTest method onActivityResult_callsExceptionListenerOnNonCompletedOrPendingStatus.

@Test
public void onActivityResult_callsExceptionListenerOnNonCompletedOrPendingStatus() throws InvalidArgumentException, JSONException {
    putResultIdInPrefs("ideal_payment_id");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[1];
            callback.success(stringFromFixture("payment_methods/failed_ideal_bank_payment.json"));
            return null;
        }
    }).when(mMockApiClient).get(eq("/ideal-payments/ideal_payment_id/status"), any(HttpResponseCallback.class));
    Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
    ArgumentCaptor<IdealResult> captor = ArgumentCaptor.forClass(IdealResult.class);
    verify(mBraintreeFragment).postCallback(captor.capture());
    IdealResult actualBankResult = captor.getValue();
    assertEquals("ideal_payment_id", actualBankResult.getId());
    assertEquals("short_id", actualBankResult.getShortId());
    assertEquals("FAILED", actualBankResult.getStatus());
}
Also used : Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) IdealResult(com.braintreepayments.api.models.IdealResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with IdealResult

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

Aggregations

IdealResult (com.braintreepayments.api.models.IdealResult)11 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)6 JSONObject (org.json.JSONObject)6 Test (org.junit.Test)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 IdealRequest (com.braintreepayments.api.models.IdealRequest)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 Configuration (com.braintreepayments.api.models.Configuration)3 IdealBank (com.braintreepayments.api.models.IdealBank)3 BraintreeApiHttpClient (com.braintreepayments.api.internal.BraintreeApiHttpClient)2 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)2 TestBraintreeApiConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestBraintreeApiConfigurationBuilder)2 TestIdealConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder.TestIdealConfigurationBuilder)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1