use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalActivity method getPayPalRequest.
private PayPalRequest getPayPalRequest(@Nullable String amount) {
PayPalRequest request = new PayPalRequest(amount);
request.displayName(Settings.getPayPalDisplayName(this));
String landingPageType = Settings.getPayPalLandingPageType(this);
if (getString(R.string.paypal_landing_page_type_billing).equals(landingPageType)) {
request.landingPageType(PayPalRequest.LANDING_PAGE_TYPE_BILLING);
} else if (getString(R.string.paypal_landing_page_type_login).equals(landingPageType)) {
request.landingPageType(PayPalRequest.LANDING_PAGE_TYPE_LOGIN);
}
String intentType = Settings.getPayPalIntentType(this);
if (intentType.equals(getString(R.string.paypal_intent_authorize))) {
request.intent(PayPalRequest.INTENT_AUTHORIZE);
} else if (intentType.equals(getString(R.string.paypal_intent_order))) {
request.intent(PayPalRequest.INTENT_ORDER);
} else if (intentType.equals(getString(R.string.paypal_intent_sale))) {
request.intent(PayPalRequest.INTENT_SALE);
}
if (Settings.isPayPalUseractionCommitEnabled(this)) {
request.userAction(PayPalRequest.USER_ACTION_COMMIT);
}
if (Settings.isPayPalCreditOffered(this)) {
request.offerCredit(true);
}
return request;
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_isSuccessful.
@Test
public void requestOneTimePayment_isSuccessful() {
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).postCallback(any(PayPalAccountNonce.class));
SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
assertNull(prefs.getString("com.braintreepayments.api.PayPal.REQUEST_KEY", null));
assertNull(prefs.getString("com.braintreepayments.api.PayPal.REQUEST_TYPE_KEY", null));
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_landingPageType_canBeSetToBilling.
@Test
public void requestOneTimePayment_landingPageType_canBeSetToBilling() throws JSONException {
BraintreeFragment fragment = mMockFragmentBuilder.build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").landingPageType(PayPalRequest.LANDING_PAGE_TYPE_BILLING));
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_BILLING, 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_containsPaymentIntent.
@Test
public void requestOneTimePayment_containsPaymentIntent() throws JSONException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
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 {
PayPalAccountBuilder payPalAccountBuilder = (PayPalAccountBuilder) invocation.getArguments()[1];
JSONObject payload = new JSONObject(payPalAccountBuilder.build());
assertEquals(PayPalRequest.INTENT_SALE, payload.getJSONObject("paypalAccount").getString("intent"));
((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
latch.countDown();
return null;
}
}).when(TokenizationClient.class);
TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").intent(PayPalRequest.INTENT_SALE));
SharedPreferences prefs = BraintreeSharedPreferences.getSharedPreferences(RuntimeEnvironment.application);
assertNull(prefs.getString("com.braintreepayments.api.PayPal.PAYPAL_REQUEST_KEY", null));
latch.await();
}
use of com.braintreepayments.api.models.PayPalRequest in project braintree_android by braintree.
the class PayPalUnitTest method requestOneTimePayment_startsBrowserWithPayPalCredit.
@Test
public void requestOneTimePayment_startsBrowserWithPayPalCredit() {
BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
PayPal.requestOneTimePayment(fragment, new PayPalRequest("1.00").offerCredit(true));
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("true", intent.getData().getQueryParameter("offer_paypal_credit"));
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"));
}
Aggregations