Search in sources :

Example 11 with PayPalRequest

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

the class PayPalUnitTest method checkout_cancelUrlTriggersCancelListener.

@Test
public void checkout_cancelUrlTriggersCancelListener() {
    final BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Intent intent = new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/cancel"));
            PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
            return null;
        }
    }).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"));
    verify(fragment).postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
Also used : PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) JSONObject(org.json.JSONObject) Intent(android.content.Intent) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_landingPageType_canBeSetToLogin.

@Test
public void requestOneTimePayment_landingPageType_canBeSetToLogin() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").landingPageType(PayPalRequest.LANDING_PAGE_TYPE_LOGIN));
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(contains("/paypal_hermes/create_payment_resource"), dataCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject json = new JSONObject(dataCaptor.getValue());
    assertEquals("1", json.get("amount"));
    assertEquals(true, json.getJSONObject("experience_profile").get("no_shipping"));
    assertEquals(false, json.getJSONObject("experience_profile").get("address_override"));
    assertEquals(PayPalRequest.LANDING_PAGE_TYPE_LOGIN, json.getJSONObject("experience_profile").get("landing_page_type"));
}
Also used : JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_displayName_canBeSet.

@Test
public void requestOneTimePayment_displayName_canBeSet() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").displayName("Test Name"));
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(contains("/paypal_hermes/create_payment_resource"), dataCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject json = new JSONObject(dataCaptor.getValue());
    assertEquals("Test Name", json.getJSONObject("experience_profile").get("brand_name"));
}
Also used : JSONObject(org.json.JSONObject) Matchers.anyString(org.mockito.Matchers.anyString) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_customHandlerIsCalledCorrectly.

@Test(timeout = 1000)
public void requestOneTimePayment_customHandlerIsCalledCorrectly() throws InterruptedException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
    final CountDownLatch latch = new CountDownLatch(1);
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {

        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            latch.countDown();
        }
    });
    latch.await();
}
Also used : PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) CountDownLatch(java.util.concurrent.CountDownLatch) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_userAction_setsUserActionToBlankStringonDefault.

@Test
public void requestOneTimePayment_userAction_setsUserActionToBlankStringonDefault() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json")).build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").userAction(PayPalRequest.USER_ACTION_DEFAULT));
    ArgumentCaptor<Intent> dataCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), dataCaptor.capture());
    Uri uri = dataCaptor.getValue().getData();
    assertEquals("", uri.getQueryParameter("useraction"));
}
Also used : Intent(android.content.Intent) Uri(android.net.Uri) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PayPalRequest (com.braintreepayments.api.models.PayPalRequest)39 Test (org.junit.Test)36 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)36 JSONObject (org.json.JSONObject)21 Intent (android.content.Intent)18 HttpResponseCallback (com.braintreepayments.api.interfaces.HttpResponseCallback)13 Matchers.anyString (org.mockito.Matchers.anyString)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Answer (org.mockito.stubbing.Answer)12 PowerMockito.doAnswer (org.powermock.api.mockito.PowerMockito.doAnswer)12 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)11 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)11 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)10 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)6 Request (com.paypal.android.sdk.onetouch.core.Request)6 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)5 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)5 SharedPreferences (android.content.SharedPreferences)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)4 BraintreeSharedPreferences (com.braintreepayments.api.internal.BraintreeSharedPreferences)4