Braintree/src/main/java/com/braintreepayments/api/LocalPayment.java
public static void startPayment(final BraintreeFragment fragment, final LocalPaymentRequest request,
            final BraintreeResponseListener<LocalPaymentRequest> listener) {
        if (request == null) {
            fragment.postCallback(new BraintreeException("A LocalPaymentRequest is required."));
            return;
        } else if (request.getApprovalUrl() != null || request.getPaymentId() != null) {
            fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " +
                    "appovalUrl and paymentId should not be set."));
            return;
        } else if (request.getPaymentType() == null || request.getAmount() == null) {
            fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " +
                    "paymentType and amount are required."));
            return;
        } else if (listener == null) {
            fragment.postCallback(new BraintreeException("BraintreeResponseListener<LocalPaymentRequest> " +
                    "is required."));
            return;
        }

        fragment.waitForConfiguration(new ConfigurationListener() {
            @Override
            public void onConfigurationFetched(Configuration configuration) {
                if (!configuration.getPayPal().isEnabled()) {
                    fragment.postCallback(new ConfigurationException("Local payments are not enabled for this merchant."));
                    return;
                }

                sMerchantAccountId = request.getMerchantAccountId();
                sPaymentType = request.getPaymentType();
                String returnUrl =  fragment.getReturnUrlScheme() + "://" + LOCAL_PAYMENT_SUCCESSS;
                String cancel =  fragment.getReturnUrlScheme() + "://" + LOCAL_PAYMENT_CANCEL;

                fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.start-payment.selected");

                fragment.getHttpClient().post("/v1/paypal_hermes/create_payment_resource", request.build(returnUrl, cancel),
                        new HttpResponseCallback() {
                            @Override
                            public void success(String responseBody) {
                                try {
                                    JSONObject responseJson = new JSONObject(responseBody);
                                    request.approvalUrl(responseJson.getJSONObject("paymentResource").getString("redirectUrl"));
                                    request.paymentId(responseJson.getJSONObject("paymentResource").getString("paymentToken"));

                                    fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.create.succeeded");
                                    listener.onResponse(request);

                                } catch (JSONException jsonException) {
                                    failure(jsonException);
                                }
                            }

                            @Override
                            public void failure(Exception exception) {
                                fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.webswitch.initiate.failed");
                                fragment.postCallback(exception);
                            }
                        });
            }
        });
    }
public static void startPayment(final BraintreeFragment fragment, final LocalPaymentRequest request,
            final BraintreeResponseListener<LocalPaymentRequest> listener) {
        if (request == null) {
            fragment.postCallback(new BraintreeException("A LocalPaymentRequest is required."));
            return;
        } else if (request.getApprovalUrl() != null || request.getPaymentId() != null) {
            fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " +
                    "appovalUrl and paymentId should not be set."));
            return;
        } else if (request.getPaymentType() == null || request.getAmount() == null) {
            fragment.postCallback(new BraintreeException("LocalPaymentRequest is invalid, " +
                    "paymentType and amount are required."));
            return;
        } else if (listener == null) {
            fragment.postCallback(new BraintreeException("BraintreeResponseListener<LocalPaymentRequest> " +
                    "is required."));
            return;
        }

        fragment.waitForConfiguration(new ConfigurationListener() {
            @Override
            public void onConfigurationFetched(Configuration configuration) {
                if (!configuration.getPayPal().isEnabled()) {
                    fragment.postCallback(new ConfigurationException("Local payments are not enabled for this merchant."));
                    return;
                }

                sMerchantAccountId = request.getMerchantAccountId();
                sPaymentType = request.getPaymentType();
                String returnUrl =  fragment.getReturnUrlScheme() + "://" + LOCAL_PAYMENT_SUCCESSS;
                String cancel =  fragment.getReturnUrlScheme() + "://" + LOCAL_PAYMENT_CANCEL;

                fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.start-payment.selected");

                fragment.getHttpClient().post("/v1/paypal_hermes/create_payment_resource", request.build(returnUrl, cancel),
                        new HttpResponseCallback() {
                            @Override
                            public void success(String responseBody) {
                                try {
                                    JSONObject responseJson = new JSONObject(responseBody);
                                    request.approvalUrl(responseJson.getJSONObject("paymentResource").getString("redirectUrl"));
                                    request.paymentId(responseJson.getJSONObject("paymentResource").getString("paymentToken"));

                                    fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.create.succeeded");
                                    listener.onResponse(request);

                                } catch (JSONException jsonException) {
                                    failure(jsonException);
                                }
                            }

                            @Override
                            public void failure(Exception exception) {
                                fragment.sendAnalyticsEvent(paymentTypeForAnalytics() + ".local-payment.webswitch.initiate.failed");
                                fragment.postCallback(exception);
                            }
                        });
            }
        });
    }
public static void startPayment ( final BraintreeFragment fragment , final LocalPaymentRequest request , final BraintreeResponseListener < LocalPaymentRequest > listener ) { if ( request == null ) { fragment . postCallback ( new BraintreeException ( "A LocalPaymentRequest is required." ) ) ; return ; } else if ( request . getApprovalUrl ( ) != null || request . getPaymentId ( ) != null ) { fragment . postCallback ( new BraintreeException ( "LocalPaymentRequest is invalid, " + "appovalUrl and paymentId should not be set." ) ) ; return ; } else if ( request . getPaymentType ( ) == null || request . getAmount ( ) == null ) { fragment . postCallback ( new BraintreeException ( "LocalPaymentRequest is invalid, " + "paymentType and amount are required." ) ) ; return ; } else if ( listener == null ) { fragment . postCallback ( new BraintreeException ( "BraintreeResponseListener<LocalPaymentRequest> " + "is required." ) ) ; return ; } fragment . waitForConfiguration ( new ConfigurationListener ( ) { @ Override public void onConfigurationFetched ( Configuration configuration ) { if ( ! configuration . getPayPal ( ) . isEnabled ( ) ) { fragment . postCallback ( new ConfigurationException ( "Local payments are not enabled for this merchant." ) ) ; return ; } sMerchantAccountId = request . getMerchantAccountId ( ) ; sPaymentType = request . getPaymentType ( ) ; String returnUrl = fragment . getReturnUrlScheme ( ) + "://" + LOCAL_PAYMENT_SUCCESSS ; String cancel = fragment . getReturnUrlScheme ( ) + "://" + LOCAL_PAYMENT_CANCEL ; fragment . sendAnalyticsEvent ( paymentTypeForAnalytics ( ) + ".local-payment.start-payment.selected" ) ; fragment . getHttpClient ( ) . post ( "/v1/paypal_hermes/create_payment_resource" , request . build ( returnUrl , cancel ) , new HttpResponseCallback ( ) { @ Override public void success ( String responseBody ) { try { JSONObject responseJson = new JSONObject ( responseBody ) ; request . approvalUrl ( responseJson . getJSONObject ( "paymentResource" ) . getString ( "redirectUrl" ) ) ; request . paymentId ( responseJson . getJSONObject ( "paymentResource" ) . getString ( "paymentToken" ) ) ; fragment . sendAnalyticsEvent ( paymentTypeForAnalytics ( ) + ".local-payment.create.succeeded" ) ; listener . onResponse ( request ) ; } catch ( JSONException jsonException ) { failure ( jsonException ) ; } } @ Override public void failure ( Exception exception ) { fragment . sendAnalyticsEvent ( paymentTypeForAnalytics ( ) + ".local-payment.webswitch.initiate.failed" ) ; fragment . postCallback ( exception ) ; } } ) ; } } ) ; }
Prepares the payment flow for a specific type of local payment.

@param fragment {@link BraintreeFragment}
@param request {@link LocalPaymentRequest} with the payment details.
@param listener {@link BraintreeResponseListener} the callback to which the {@link LocalPaymentRequest} will be sent
with a payment ID for preprocessing and an approval URL. Once ready, use {@link #approvePayment(BraintreeFragment, LocalPaymentRequest)}
to initiate the browser switch.
Prepares the payment flow for a specific type of local payment .