Search in sources :

Example 1 with BrowserSwitchException

use of com.braintreepayments.api.exceptions.BrowserSwitchException in project braintree_android by braintree.

the class PayPal method onActivityResult.

/**
 * The result from PayPal's request.
 *
 * @param fragment A {@link BraintreeFragment} used to process the request.
 * @param data Data associated with the result.
 */
protected static void onActivityResult(final BraintreeFragment fragment, int resultCode, Intent data) {
    Request request = getPersistedRequest(fragment.getApplicationContext());
    if (resultCode == Activity.RESULT_OK && data != null && request != null) {
        boolean isAppSwitch = isAppSwitch(data);
        Result result = PayPalOneTouchCore.parseResponse(fragment.getApplicationContext(), request, data);
        switch(result.getResultType()) {
            case Error:
                fragment.postCallback(new BrowserSwitchException(result.getError().getMessage()));
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "failed");
                break;
            case Cancel:
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "canceled");
                fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
                break;
            case Success:
                onSuccess(fragment, data, request, result);
                sendAnalyticsEventForSwitchResult(fragment, request, isAppSwitch, "succeeded");
                break;
        }
    } else {
        String type;
        if (request != null) {
            type = request.getClass().getSimpleName().toLowerCase();
        } else {
            type = "unknown";
        }
        fragment.sendAnalyticsEvent("paypal." + type + ".canceled");
        if (resultCode != Activity.RESULT_CANCELED) {
            fragment.postCancelCallback(BraintreeRequestCodes.PAYPAL);
        }
    }
}
Also used : 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) BrowserSwitchException(com.braintreepayments.api.exceptions.BrowserSwitchException) Result(com.paypal.android.sdk.onetouch.core.Result)

Aggregations

BrowserSwitchException (com.braintreepayments.api.exceptions.BrowserSwitchException)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 Result (com.paypal.android.sdk.onetouch.core.Result)1 PendingRequest (com.paypal.android.sdk.onetouch.core.sdk.PendingRequest)1