use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_defaultPostParamsIncludeCorrectValues.
@Test
public void requestOneTimePayment_defaultPostParamsIncludeCorrectValues() throws JSONException {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"));
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 actual = new JSONObject(dataCaptor.getValue());
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("amount", "1").put("experience_profile", new JSONObject().put("address_override", false).put("brand_name", "displayName").put("no_shipping", true)).put("intent", "authorize").put("offer_paypal_credit", false);
JSONAssert.assertEquals(expected, actual, true);
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_startsBrowser.
@Test
public void requestOneTimePayment_startsBrowser() {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1.00"));
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
verify(fragment).browserSwitch(eq(BraintreeRequestCodes.PAYPAL), captor.capture());
Intent intent = captor.getValue();
assertEquals(Intent.ACTION_VIEW, intent.getAction());
assertEquals("checkout.paypal.com", intent.getData().getHost());
assertEquals("/one-touch-login-sandbox/index.html", intent.getData().getPath());
assertEquals("create_payment_resource", intent.getData().getQueryParameter("action"));
assertEquals("63cc461306c35080ce674a3372bffe1580b4130c7fd33d33968aa76bb93cdd06|created_at=2015-10-13T18:49:48.371382792+0000&merchant_id=dcpspy2brwdjr3qn&public_key=9wwrzqk3vr3t4nc8", intent.getData().getQueryParameter("authorization_fingerprint"));
assertEquals("USD", intent.getData().getQueryParameter("currency_iso_code"));
assertEquals("false", intent.getData().getQueryParameter("experience_profile[address_override]"));
assertEquals("false", intent.getData().getQueryParameter("experience_profile[no_shipping]"));
assertEquals("dcpspy2brwdjr3qn", intent.getData().getQueryParameter("merchant_id"));
assertEquals("com.braintreepayments.api.test.braintree://onetouch/v1/success", intent.getData().getQueryParameter("return_url"));
assertEquals("com.braintreepayments.api.test.braintree://onetouch/v1/cancel", intent.getData().getQueryParameter("cancel_url"));
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_postParamsIncludeNoShippingAndAddressAndAddressOverride.
@Test
public void requestOneTimePayment_postParamsIncludeNoShippingAndAddressAndAddressOverride() 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(false).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(true, 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 requestBillingAgreement_whenSuccessful_sendsAnalyticsEvents.
@Test
public void requestBillingAgreement_whenSuccessful_sendsAnalyticsEvents() {
final BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_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&ba_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.requestBillingAgreement(fragment, new PayPalRequest());
verify(fragment).sendAnalyticsEvent("paypal.billing-agreement.selected");
verify(fragment).sendAnalyticsEvent("paypal-billing-agreement.webswitch.started");
verify(fragment).sendAnalyticsEvent("paypal-billing-agreement.webswitch.succeeded");
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_customHandlerCancelCallbackIsInvoked.
@Test
public void requestOneTimePayment_customHandlerCancelCallbackIsInvoked() throws InterruptedException {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {
@Override
public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
paypalApprovalCallback.onCancel();
}
});
verify(fragment).postCancelCallback(BraintreeRequestCodes.PAYPAL);
}
Aggregations