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);
}
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"));
}
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"));
}
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));
}
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());
}
Aggregations