Search in sources :

Example 26 with Request

use of com.paypal.android.sdk.onetouch.core.Request in project braintree_android by braintree.

the class PayPal method requestOneTimePayment.

private static void requestOneTimePayment(final BraintreeFragment fragment, final PayPalRequest paypalRequest, final boolean isBillingAgreement, final PayPalApprovalHandler handler) {
    final HttpResponseCallback callback = new HttpResponseCallback() {

        @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);
        }

        @Override
        public void failure(Exception e) {
            fragment.postCallback(e);
        }
    };
    fragment.waitForConfiguration(new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
            if (!configuration.isPayPalEnabled()) {
                fragment.postCallback(new BraintreeException("PayPal is not enabled"));
                return;
            }
            if (!isManifestValid(fragment)) {
                fragment.sendAnalyticsEvent("paypal.invalid-manifest");
                fragment.postCallback(new BraintreeException("BraintreeBrowserSwitchActivity missing, " + "incorrectly configured in AndroidManifest.xml or another app defines the same browser " + "switch url as this app. See " + "https://developers.braintreepayments.com/guides/client-sdk/android/v2#browser-switch " + "for the correct configuration"));
                return;
            }
            try {
                persistPayPalRequest(fragment.getApplicationContext(), paypalRequest);
                createPaymentResource(fragment, paypalRequest, isBillingAgreement, callback);
            } catch (JSONException | ErrorWithResponse | BraintreeException ex) {
                fragment.postCallback(ex);
            }
        }
    });
}
Also used : ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) PayPalPaymentResource(com.braintreepayments.api.models.PayPalPaymentResource) PayPalConfiguration(com.braintreepayments.api.models.PayPalConfiguration) Configuration(com.braintreepayments.api.models.Configuration) Request(com.paypal.android.sdk.onetouch.core.Request) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) BillingAgreementRequest(com.paypal.android.sdk.onetouch.core.BillingAgreementRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) CheckoutRequest(com.paypal.android.sdk.onetouch.core.CheckoutRequest) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest) JSONException(org.json.JSONException) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) HttpResponseCallback(com.braintreepayments.api.interfaces.HttpResponseCallback) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) JSONException(org.json.JSONException) BrowserSwitchException(com.braintreepayments.api.exceptions.BrowserSwitchException)

Aggregations

AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)26 Request (com.paypal.android.sdk.onetouch.core.Request)26 Test (org.junit.Test)23 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)21 Intent (android.content.Intent)12 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)12 Configuration (com.braintreepayments.api.models.Configuration)10 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)8 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)6 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)6 Result (com.paypal.android.sdk.onetouch.core.Result)6 Context (android.content.Context)5 Bundle (android.os.Bundle)5 ContextInspector (com.paypal.android.sdk.onetouch.core.base.ContextInspector)5 Protocol (com.paypal.android.sdk.onetouch.core.enums.Protocol)5 TestSetupHelper.getMockContextInspector (com.paypal.android.sdk.onetouch.core.test.TestSetupHelper.getMockContextInspector)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)3 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)3 PaymentMethodBuilder (com.braintreepayments.api.models.PaymentMethodBuilder)3