Search in sources :

Example 1 with PendingRequest

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

the class PayPal method getDefaultApprovalHandler.

private static PayPalApprovalHandler getDefaultApprovalHandler(final BraintreeFragment fragment) {
    return new PayPalApprovalHandler() {

        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            PendingRequest pendingRequest = PayPalOneTouchCore.getStartIntent(fragment.getApplicationContext(), request);
            if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.wallet) {
                sendAnalyticsForPayPal(fragment, request, true, RequestTarget.wallet);
                fragment.startActivityForResult(pendingRequest.getIntent(), BraintreeRequestCodes.PAYPAL);
            } else if (pendingRequest.isSuccess() && pendingRequest.getRequestTarget() == RequestTarget.browser) {
                sendAnalyticsForPayPal(fragment, request, true, RequestTarget.browser);
                fragment.browserSwitch(BraintreeRequestCodes.PAYPAL, pendingRequest.getIntent());
            } else {
                sendAnalyticsForPayPal(fragment, request, false, null);
            }
        }
    };
}
Also used : PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) 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) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest)

Example 2 with PendingRequest

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

the class PayPalOneTouchCore method getStartIntent.

/**
 * Get a {@link PendingRequest} containing an {@link Intent} used to start a PayPal
 * authentication request using the best possible authentication mechanism: wallet or browser.
 *
 * @param context
 * @param request the {@link Request} used to build the {@link Intent}.
 * @return {@link PendingRequest}. {@link PendingRequest#isSuccess()} should be
 *         checked before attempting to use the {@link Intent} it contains. If {@code true} an
 *         {@link Intent} was created and can be used to start a PayPal authentication request.
 *         If {@code false} it is not possible to authenticate given the current environment
 *         and request.
 */
public static PendingRequest getStartIntent(Context context, Request request) {
    initService(context);
    // calling this method functionally does nothing, but ensures that we send off FPTI data about wallet installs.
    isWalletAppInstalled(context);
    Recipe recipe = request.getRecipeToExecute(context, sConfigManager.getConfig());
    if (recipe == null) {
        return new PendingRequest(false, null, null, null);
    }
    if (RequestTarget.wallet == recipe.getTarget()) {
        request.trackFpti(context, TrackingPoint.SwitchToWallet, recipe.getProtocol());
        return new PendingRequest(true, RequestTarget.wallet, request.getClientMetadataId(), AppSwitchHelper.getAppSwitchIntent(sContextInspector, sConfigManager, request, recipe));
    } else {
        Intent intent = BrowserSwitchHelper.getBrowserSwitchIntent(sContextInspector, sConfigManager, request);
        if (intent != null) {
            return new PendingRequest(true, RequestTarget.browser, request.getClientMetadataId(), intent);
        } else {
            return new PendingRequest(false, RequestTarget.browser, request.getClientMetadataId(), null);
        }
    }
}
Also used : OAuth2Recipe(com.paypal.android.sdk.onetouch.core.config.OAuth2Recipe) Recipe(com.paypal.android.sdk.onetouch.core.config.Recipe) Intent(android.content.Intent) PendingRequest(com.paypal.android.sdk.onetouch.core.sdk.PendingRequest)

Aggregations

PendingRequest (com.paypal.android.sdk.onetouch.core.sdk.PendingRequest)2 Intent (android.content.Intent)1 PayPalApprovalCallback (com.braintreepayments.api.interfaces.PayPalApprovalCallback)1 PayPalApprovalHandler (com.braintreepayments.api.interfaces.PayPalApprovalHandler)1 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)1 AuthorizationRequest (com.paypal.android.sdk.onetouch.core.AuthorizationRequest)1 BillingAgreementRequest (com.paypal.android.sdk.onetouch.core.BillingAgreementRequest)1 CheckoutRequest (com.paypal.android.sdk.onetouch.core.CheckoutRequest)1 Request (com.paypal.android.sdk.onetouch.core.Request)1 OAuth2Recipe (com.paypal.android.sdk.onetouch.core.config.OAuth2Recipe)1 Recipe (com.paypal.android.sdk.onetouch.core.config.Recipe)1