Search in sources :

Example 6 with IdealRequest

use of com.braintreepayments.api.models.IdealRequest 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 7 with IdealRequest

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

the class IdealUnitTest method startPayment_failure_sendsAnalyticsEvent.

@Test
public void startPayment_failure_sendsAnalyticsEvent() throws JSONException, InvalidArgumentException {
    mConfiguration = new TestConfigurationBuilder().assetsUrl("http://assets.example.com").buildConfiguration();
    mBraintreeFragment = new MockFragmentBuilder().authorization(Authorization.fromString(stringFromFixture("client_token.json"))).configuration(mConfiguration).build();
    Ideal.startPayment(mBraintreeFragment, new IdealRequest(), null);
    verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.selected"));
    verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.start-payment.invalid-configuration"));
}
Also used : IdealRequest(com.braintreepayments.api.models.IdealRequest) TestConfigurationBuilder(com.braintreepayments.testutils.TestConfigurationBuilder) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with IdealRequest

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

the class IdealUnitTest method startPayment_startsBrowserWithProperRequestCode.

@Test
public void startPayment_startsBrowserWithProperRequestCode() throws InterruptedException, InvalidArgumentException {
    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/ideal_issuing_banks.json"));
            return null;
        }
    }).when(mMockApiClient).get(eq("/issuers/ideal"), any(HttpResponseCallback.class));
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            String requestBody = (String) invocation.getArguments()[1];
            JSONObject json = new JSONObject(requestBody);
            assertEquals("some-route-id", json.getString("route_id"));
            String expectedRedirectUrl = Uri.parse("http://assets.example.com/mobile/ideal-redirect/0.0.0/index.html?redirect_url=" + mBraintreeFragment.getReturnUrlScheme() + "://").toString();
            assertEquals(expectedRedirectUrl, json.getString("redirect_url"));
            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));
    Ideal.fetchIssuingBanks(mBraintreeFragment, new BraintreeResponseListener<List<IdealBank>>() {

        @Override
        public void onResponse(List<IdealBank> idealBanks) {
            IdealBank bank = idealBanks.get(0);
            IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("1.00").currency("EUR").orderId("abc-123");
            Ideal.startPayment(mBraintreeFragment, builder, null);
            verify(mBraintreeFragment).browserSwitch(eq(BraintreeRequestCodes.IDEAL), eq("http://approval.example.com/"));
            latch.countDown();
        }
    });
    latch.await();
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) Answer(org.mockito.stubbing.Answer) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) JSONObject(org.json.JSONObject) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) JSONObject(org.json.JSONObject) List(java.util.List) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with IdealRequest

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

the class IdealTest method startPayment_returnsError_whenOrderId_isAbsent.

@Test(timeout = 10000)
public void startPayment_returnsError_whenOrderId_isAbsent() throws InterruptedException {
    IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A");
    Ideal.startPayment(mBraintreeFragment, builder, null);
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof BraintreeApiErrorResponse);
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
            fail("BraintreeApiErrorResponse expected");
        }
    });
    mCountDownLatch.await();
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) BraintreeApiErrorResponse(com.braintreepayments.api.exceptions.BraintreeApiErrorResponse) IdealRequest(com.braintreepayments.api.models.IdealRequest) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) Test(org.junit.Test)

Example 10 with IdealRequest

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

the class IdealActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    IdealBank bank = (IdealBank) mIssuingBanksListView.getAdapter().getItem(position);
    IdealRequest builder = new IdealRequest().issuerId(bank.getId()).amount("10").orderId(UUID.randomUUID().toString()).currency("EUR");
    Ideal.startPayment(mBraintreeFragment, builder, new BraintreeResponseListener<IdealResult>() {

        @Override
        public void onResponse(IdealResult idealResult) {
            String idealId = idealResult.getId();
        }
    });
}
Also used : IdealRequest(com.braintreepayments.api.models.IdealRequest) IdealBank(com.braintreepayments.api.models.IdealBank) IdealResult(com.braintreepayments.api.models.IdealResult)

Aggregations

IdealRequest (com.braintreepayments.api.models.IdealRequest)10 Test (org.junit.Test)8 IdealBank (com.braintreepayments.api.models.IdealBank)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)5 JSONObject (org.json.JSONObject)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 Answer (org.mockito.stubbing.Answer)5 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)5 IdealResult (com.braintreepayments.api.models.IdealResult)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)2 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)2 BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)2 List (java.util.List)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AlertDialog (android.app.AlertDialog)1 ProgressDialog (android.app.ProgressDialog)1 DialogInterface (android.content.DialogInterface)1 OnClickListener (android.content.DialogInterface.OnClickListener)1