Commit 6800e252 authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[WebLayer] Move disconnectForStrictShow, mRejectShowErrorMessage

Moved disconnectForStrictShow, mRejectShowErrorMessage from CPRService
to PRService, because they are the logic that is shareable with
WebLayer.

Change: 1144527

Change-Id: I1449b7e145918f057e7289984a4eb7364f05e900
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519202
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824631}
parent 19c5aea1
...@@ -24,7 +24,6 @@ import org.chromium.components.embedder_support.util.UrlConstants; ...@@ -24,7 +24,6 @@ import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.payments.AbortReason; import org.chromium.components.payments.AbortReason;
import org.chromium.components.payments.BrowserPaymentRequest; import org.chromium.components.payments.BrowserPaymentRequest;
import org.chromium.components.payments.CheckoutFunnelStep; import org.chromium.components.payments.CheckoutFunnelStep;
import org.chromium.components.payments.ErrorMessageUtil;
import org.chromium.components.payments.ErrorStrings; import org.chromium.components.payments.ErrorStrings;
import org.chromium.components.payments.Event; import org.chromium.components.payments.Event;
import org.chromium.components.payments.JourneyLogger; import org.chromium.components.payments.JourneyLogger;
...@@ -125,9 +124,6 @@ public class ChromePaymentRequestService ...@@ -125,9 +124,6 @@ public class ChromePaymentRequestService
/** The helper to create and fill the response to send to the merchant. */ /** The helper to create and fill the response to send to the merchant. */
private PaymentResponseHelper mPaymentResponseHelper; private PaymentResponseHelper mPaymentResponseHelper;
/** If not empty, use this error message for rejecting PaymentRequest.show(). */
private String mRejectShowErrorMessage;
/** A helper to manage the Skip-to-GPay experimental flow. */ /** A helper to manage the Skip-to-GPay experimental flow. */
private SkipToGPayHelper mSkipToGPayHelper; private SkipToGPayHelper mSkipToGPayHelper;
private boolean mIsGooglePayBridgeActivated; private boolean mIsGooglePayBridgeActivated;
...@@ -1147,38 +1143,6 @@ public class ChromePaymentRequestService ...@@ -1147,38 +1143,6 @@ public class ChromePaymentRequestService
return mPaymentUiService.canUserAddCreditCard(); return mPaymentUiService.canUserAddCreditCard();
} }
// Implements BrowserPaymentRequest:
@Override
public String getRejectShowErrorMessage() {
return mRejectShowErrorMessage;
}
// Implements BrowserPaymentRequest:
@Override
public void setRejectShowErrorMessage(String errorMessage) {
mRejectShowErrorMessage = errorMessage;
}
// Implements BrowserPaymentRequest:
@Override
public boolean disconnectForStrictShow(boolean isUserGestureShow) {
if (!isUserGestureShow || !mSpec.getMethodData().containsKey(MethodStrings.BASIC_CARD)
|| mPaymentRequestService.getHasEnrolledInstrument()
|| mPaymentRequestService.getHasNonAutofillApp()
|| !PaymentFeatureList.isEnabledOrExperimentalFeaturesEnabled(
PaymentFeatureList.STRICT_HAS_ENROLLED_AUTOFILL_INSTRUMENT)) {
return false;
}
mRejectShowErrorMessage = ErrorStrings.STRICT_BASIC_CARD_SHOW_REJECT;
disconnectFromClientWithDebugMessage(
ErrorMessageUtil.getNotSupportedErrorMessage(mSpec.getMethodData().keySet()) + " "
+ mRejectShowErrorMessage,
PaymentErrorReason.NOT_SUPPORTED);
return true;
}
// Implements PaymentApp.InstrumentDetailsCallback: // Implements PaymentApp.InstrumentDetailsCallback:
/** Called after retrieving payment details. */ /** Called after retrieving payment details. */
@Override @Override
......
...@@ -129,15 +129,6 @@ public interface BrowserPaymentRequest { ...@@ -129,15 +129,6 @@ public interface BrowserPaymentRequest {
return false; return false;
} }
/**
* If strict show() conditions are not satisfied, disconnect from client and return true.
* @param isUserGestureShow Whether the PaymentRequest.show() is triggered by user gesture.
* @return Whether client has been disconnected.
*/
default boolean disconnectForStrictShow(boolean isUserGestureShow) {
return false;
}
/** /**
* Shows the payment apps selector. * Shows the payment apps selector.
* @return Whether the showing is successful. * @return Whether the showing is successful.
...@@ -158,11 +149,6 @@ public interface BrowserPaymentRequest { ...@@ -158,11 +149,6 @@ public interface BrowserPaymentRequest {
*/ */
default void triggerPaymentAppUiSkipIfApplicable() {} default void triggerPaymentAppUiSkipIfApplicable() {}
/** @return The error message of rejecting the show() request. */
default String getRejectShowErrorMessage() {
return "";
}
/** /**
* Called when a new payment app is created. * Called when a new payment app is created.
* @param paymentApp The new payment app. * @param paymentApp The new payment app.
...@@ -183,12 +169,4 @@ public interface BrowserPaymentRequest { ...@@ -183,12 +169,4 @@ public interface BrowserPaymentRequest {
default boolean isPaymentSheetBasedPaymentAppSupported() { default boolean isPaymentSheetBasedPaymentAppSupported() {
return false; return false;
} }
// TODO(crbug.com/1144527): this method will be removed once PaymentRequestService has taken
// over mRejectShowErrorMessage.
/**
* Set the error message for show rejection.
* @param errorMessage The error message for show rejection.
*/
default void setRejectShowErrorMessage(String errorMessage) {}
} }
...@@ -86,6 +86,9 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment ...@@ -86,6 +86,9 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment
private boolean mIsFinishedQueryingPaymentApps; private boolean mIsFinishedQueryingPaymentApps;
private boolean mIsCurrentPaymentRequestShowing; private boolean mIsCurrentPaymentRequestShowing;
/** If not empty, use this error message for rejecting PaymentRequest.show(). */
private String mRejectShowErrorMessage;
/** Whether PaymentRequest.show() was invoked with a user gesture. */ /** Whether PaymentRequest.show() was invoked with a user gesture. */
private boolean mIsUserGestureShow; private boolean mIsUserGestureShow;
...@@ -581,16 +584,15 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment ...@@ -581,16 +584,15 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment
sNativeObserverForTest.onNotSupportedError(); sNativeObserverForTest.onNotSupportedError();
} }
String rejectShowErrorMessage = mBrowserPaymentRequest.getRejectShowErrorMessage(); if (TextUtils.isEmpty(mRejectShowErrorMessage) && !isInTwa()
if (TextUtils.isEmpty(rejectShowErrorMessage) && !isInTwa()
&& mSpec.getMethodData().get(MethodStrings.GOOGLE_PLAY_BILLING) != null) { && mSpec.getMethodData().get(MethodStrings.GOOGLE_PLAY_BILLING) != null) {
rejectShowErrorMessage = ErrorStrings.APP_STORE_METHOD_ONLY_SUPPORTED_IN_TWA; mRejectShowErrorMessage = ErrorStrings.APP_STORE_METHOD_ONLY_SUPPORTED_IN_TWA;
} }
mBrowserPaymentRequest.disconnectFromClientWithDebugMessage( mBrowserPaymentRequest.disconnectFromClientWithDebugMessage(
ErrorMessageUtil.getNotSupportedErrorMessage(mSpec.getMethodData().keySet()) ErrorMessageUtil.getNotSupportedErrorMessage(mSpec.getMethodData().keySet())
+ (TextUtils.isEmpty(rejectShowErrorMessage) + (TextUtils.isEmpty(mRejectShowErrorMessage)
? "" ? ""
: " " + rejectShowErrorMessage), : " " + mRejectShowErrorMessage),
PaymentErrorReason.NOT_SUPPORTED); PaymentErrorReason.NOT_SUPPORTED);
} }
if (sObserverForTest != null) { if (sObserverForTest != null) {
...@@ -598,11 +600,32 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment ...@@ -598,11 +600,32 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment
} }
return true; return true;
} }
boolean isDisconnected = mBrowserPaymentRequest.disconnectForStrictShow(mIsUserGestureShow); return disconnectForStrictShow(mIsUserGestureShow);
if (isDisconnected && sObserverForTest != null) { }
/**
* If strict show() conditions are not satisfied, disconnect from client and return true.
* @param isUserGestureShow Whether the PaymentRequest.show() is triggered by user gesture.
* @return Whether client has been disconnected.
*/
private boolean disconnectForStrictShow(boolean isUserGestureShow) {
if (!isUserGestureShow || !mSpec.getMethodData().containsKey(MethodStrings.BASIC_CARD)
|| mHasEnrolledInstrument || mHasNonAutofillApp
|| !PaymentFeatureList.isEnabledOrExperimentalFeaturesEnabled(
PaymentFeatureList.STRICT_HAS_ENROLLED_AUTOFILL_INSTRUMENT)) {
return false;
}
if (sObserverForTest != null) {
sObserverForTest.onPaymentRequestServiceShowFailed(); sObserverForTest.onPaymentRequestServiceShowFailed();
} }
return isDisconnected; mRejectShowErrorMessage = ErrorStrings.STRICT_BASIC_CARD_SHOW_REJECT;
mBrowserPaymentRequest.disconnectFromClientWithDebugMessage(
ErrorMessageUtil.getNotSupportedErrorMessage(mSpec.getMethodData().keySet()) + " "
+ mRejectShowErrorMessage,
PaymentErrorReason.NOT_SUPPORTED);
return true;
} }
private boolean isInTwa() { private boolean isInTwa() {
...@@ -755,9 +778,8 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment ...@@ -755,9 +778,8 @@ public class PaymentRequestService implements PaymentAppFactoryDelegate, Payment
// Implements PaymentAppFactoryDelegate: // Implements PaymentAppFactoryDelegate:
@Override @Override
public void onPaymentAppCreationError(String errorMessage) { public void onPaymentAppCreationError(String errorMessage) {
if (mBrowserPaymentRequest != null if (TextUtils.isEmpty(mRejectShowErrorMessage)) {
&& TextUtils.isEmpty(mBrowserPaymentRequest.getRejectShowErrorMessage())) { mRejectShowErrorMessage = errorMessage;
mBrowserPaymentRequest.setRejectShowErrorMessage(errorMessage);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment