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