@Override public void success(String responseBody) { final PayPalPaymentResource paypalPaymentResource; try { paypalPaymentResource = PayPalPaymentResource.fromJson(responseBody); } catch (JSONException e) { fragment.postCallback(e); return; } String redirectUrl = Uri.parse(paypalPaymentResource.getRedirectUrl()) .buildUpon() .appendQueryParameter(USER_ACTION_KEY, paypalRequest.getUserAction()) .toString(); Request request; if (isBillingAgreement) { request = getBillingAgreementRequest(fragment, redirectUrl); } else { request = getCheckoutRequest(fragment, redirectUrl); } startPayPal(fragment, request, handler); }
@Test public void getBillingAgreement_containsCorrectValues() throws JSONException { Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json")); BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build(); BillingAgreementRequest request = PayPal.getBillingAgreementRequest(fragment, "https://paypal.com/?ba_token=pairingId"); assertEquals(EnvironmentManager.MOCK, request.getEnvironment()); assertEquals("com.braintreepayments.api.braintree://onetouch/v1/cancel", request.getCancelUrl()); assertEquals("com.braintreepayments.api.braintree://onetouch/v1/success", request.getSuccessUrl()); assertEquals("paypal_client_id", request.getClientId()); assertEquals("pairingId", request.getPairingId()); }
@Test public void getBillingAgreementRequest_buildsWithOfflineStageUrl() throws JSONException { Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_offline_paypal.json")); BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build(); Request request = PayPal.getBillingAgreementRequest(fragment, null); assertEquals(EnvironmentManager.MOCK, request.getEnvironment()); }
@Test public void getBillingAgreementRequest_buildsWithLiveStageUrl() throws JSONException { Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_live_paypal.json")); BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build(); Request request = PayPal.getBillingAgreementRequest(fragment, null); assertEquals(EnvironmentManager.LIVE, request.getEnvironment()); }
@Test public void getBillingAgreementRequest_buildsWithCustomStageUrl() throws JSONException { Configuration configuration = Configuration.fromJson(stringFromFixture("configuration/with_custom_paypal.json")); BraintreeFragment fragment = mMockFragmentBuilder.configuration(configuration).build(); Request request = PayPal.getBillingAgreementRequest(fragment, null); assertEquals("custom", request.getEnvironment()); }