use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_postParamsIncludeAddressAndAddressOverride.
@Test
public void requestOneTimePayment_postParamsIncludeAddressAndAddressOverride() throws JSONException {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PostalAddress address = new PostalAddress().streetAddress("123 Fake St.").extendedAddress("Apt. v.0").locality("Oakland").region("CA").postalCode("12345").countryCodeAlpha2("US");
PayPalRequest request = new PayPalRequest("3.43").shippingAddressRequired(true).shippingAddressOverride(address);
PayPal.requestOneTimePayment(fragment, request);
ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
verify(fragment.getHttpClient()).post(pathCaptor.capture(), dataCaptor.capture(), any(HttpResponseCallback.class));
assertTrue(pathCaptor.getValue().contains("/paypal_hermes/create_payment_resource"));
JSONObject json = new JSONObject(dataCaptor.getValue());
assertEquals("3.43", json.get("amount"));
assertEquals("123 Fake St.", json.get("line1"));
assertEquals("Apt. v.0", json.get("line2"));
assertEquals("Oakland", json.get("city"));
assertEquals("CA", json.get("state"));
assertEquals("12345", json.get("postal_code"));
assertEquals("US", json.get("country_code"));
assertEquals(false, json.getJSONObject("experience_profile").get("no_shipping"));
assertEquals(true, json.getJSONObject("experience_profile").get("address_override"));
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_whenSuccessful_sendsAnalyticsEvents.
@Test
public void requestOneTimePayment_whenSuccessful_sendsAnalyticsEvents() {
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/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN"));
PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
return null;
}
}).when(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), any(Intent.class));
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"));
verify(fragment).sendAnalyticsEvent("paypal.one-time-payment.selected");
verify(fragment).sendAnalyticsEvent("paypal-single-payment.webswitch.started");
verify(fragment).sendAnalyticsEvent("paypal-single-payment.webswitch.succeeded");
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_doesNotCallCancelListenerWhenSuccessful.
@Test
public void requestOneTimePayment_doesNotCallCancelListenerWhenSuccessful() {
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/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN"));
PayPal.onActivityResult(fragment, Activity.RESULT_OK, intent);
return null;
}
}).when(fragment).startActivity(any(Intent.class));
mockStatic(TokenizationClient.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"));
verify(fragment, never()).postCancelCallback(anyInt());
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_postParamsIncludeNoShipping.
@Test
public void requestOneTimePayment_postParamsIncludeNoShipping() throws JSONException {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").shippingAddressRequired(false));
ArgumentCaptor<String> pathCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
verify(fragment.getHttpClient()).post(pathCaptor.capture(), dataCaptor.capture(), any(HttpResponseCallback.class));
assertTrue(pathCaptor.getValue().contains("/paypal_hermes/create_payment_resource"));
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"));
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_intent_canBeSetToSale.
@Test
public void requestOneTimePayment_intent_canBeSetToSale() throws JSONException {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_SALE));
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_SALE, json.get("intent"));
}
Aggregations