Search in sources :

Example 31 with PayPalRequest

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

the class PayPalUnitTest method requestBillingAgreement_defaultPostParamsIncludeCorrectValues.

@Test
public void requestBillingAgreement_defaultPostParamsIncludeCorrectValues() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestBillingAgreement(fragment, new PayPalRequest());
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(fragment.getHttpClient()).post(contains("/paypal_hermes/setup_billing_agreement"), dataCaptor.capture(), any(HttpResponseCallback.class));
    JSONObject expected = new JSONObject().put("client_key", "authorization").put("return_url", "com.braintreepayments.api.braintree://onetouch/v1/success").put("cancel_url", "com.braintreepayments.api.braintree://onetouch/v1/cancel").put("experience_profile", new JSONObject().put("address_override", false).put("brand_name", "displayName").put("no_shipping", true)).put("offer_paypal_credit", false);
    JSONObject actual = new JSONObject(dataCaptor.getValue());
    JSONAssert.assertEquals(expected, actual, true);
}
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 32 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_intent_canBeSetToOrder.

@Test
public void requestOneTimePayment_intent_canBeSetToOrder() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_ORDER));
    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.INTENT_ORDER, json.get("intent"));
}
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 33 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_userAction_canBeSetToCommit.

@Test
public void requestOneTimePayment_userAction_canBeSetToCommit() throws JSONException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json")).build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").userAction(PayPalRequest.USER_ACTION_COMMIT));
    ArgumentCaptor<Intent> dataCaptor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), dataCaptor.capture());
    Uri uri = dataCaptor.getValue().getData();
    assertEquals("commit", 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)

Example 34 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_persistsPayPalRequest.

@Test
public void requestOneTimePayment_persistsPayPalRequest() {
    BraintreeFragment braintreeFragment = mMockFragmentBuilder.build();
    SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
    PayPal.requestOneTimePayment(braintreeFragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_SALE));
    assertNotNull(prefs.getString("com.braintreepayments.api.PayPal.PAYPAL_REQUEST_KEY", null));
}
Also used : SharedPreferences(android.content.SharedPreferences) BraintreeSharedPreferences(com.braintreepayments.api.internal.BraintreeSharedPreferences) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with PayPalRequest

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

the class PayPalUnitTest method requestOneTimePayment_postsExceptionWhenNoAmountIsSet.

@Test
public void requestOneTimePayment_postsExceptionWhenNoAmountIsSet() {
    BraintreeFragment fragment = mMockFragmentBuilder.build();
    PayPal.requestOneTimePayment(fragment, new PayPalRequest());
    ArgumentCaptor<Exception> captor = ArgumentCaptor.forClass(Exception.class);
    verify(fragment).postCallback(captor.capture());
    assertTrue(captor.getValue() instanceof BraintreeException);
    assertEquals("An amount must be specified for the Single Payment flow.", captor.getValue().getMessage());
}
Also used : BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) 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