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