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

[PRImpl] Move UI methods into PaymentUIsManager

Change:
* Move the following methods from PRImpl to PaymentUIsManager without
logic changes.
 - getModifier
 - getLineItems
 - loadCurrencyFormattersForPaymentDetails
 - isMixedOrChangedCurrency
 - getOrCreateCurrencyFormatter
* Because the methods being moved reference some PR parameters, we also
add getModifiers and getRawTotals to PaymentRequestParams.
* Because the methods reference mCurrencyFormatterMap, mUiShoppingCart,
they are moved into PaymentUIsManager as well.

Bug: 1102522

Change-Id: Iaf69afee236bc9369bea4e87ee4d2547800d5487
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310900
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791515}
parent f0b6788e
......@@ -18,6 +18,8 @@ import org.chromium.components.payments.PaymentAppFactoryParams;
import org.chromium.components.payments.PaymentFeatureList;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentDetailsModifier;
import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
......@@ -84,7 +86,6 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
public PaymentApp createPaymentAppForCard(CreditCard card) {
if (!mCanMakePayment) return null;
String methodName = null;
if (!mNetworks.contains(card.getBasicCardIssuerNetwork())) return null;
AutofillProfile billingAddress = TextUtils.isEmpty(card.getBillingAddressId())
......@@ -127,7 +128,7 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
* @param methodData The payment methods and their corresponding data.
* @return Whether there's a usable Autofill card on file.
*/
public static boolean hasUsableAutofillCard(
static boolean hasUsableAutofillCard(
WebContents webContents, Map<String, PaymentMethodData> methodData) {
PaymentAppFactoryParams params = new PaymentAppFactoryParams() {
@Override
......@@ -135,20 +136,37 @@ public class AutofillPaymentAppFactory implements PaymentAppFactoryInterface {
return webContents;
}
@Override
public Map<String, PaymentMethodData> getMethodData() {
return methodData;
}
@Override
public RenderFrameHost getRenderFrameHost() {
// AutofillPaymentAppFactory.Creator doesn't need RenderFrameHost.
assert false : "getRenderFrameHost() should not be called";
return null;
}
@Override
public PaymentOptions getPaymentOptions() {
// AutofillPaymentAppFactory.Creator doesn't need PaymentOptions.
assert false : "getPaymentOptions() should not be called";
return null;
}
@Override
public Map<String, PaymentMethodData> getMethodData() {
return methodData;
public PaymentItem getRawTotal() {
// AutofillPaymentAppFactory.Creator doesn't need raw totals.
assert false : "getRawTotals() should not be called";
return null;
}
@Override
public Map<String, PaymentDetailsModifier> getModifiers() {
// AutofillPaymentAppFactory.Creator doesn't need modifiers.
assert false : "getModifiers() should not be called";
return null;
}
};
final class UsableCardFinder implements PaymentAppFactoryDelegate {
......
......@@ -33,6 +33,7 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.payments.mojom.PaymentDetailsModifier;
import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
import org.chromium.url.GURL;
......@@ -174,6 +175,13 @@ public class AndroidPaymentAppFinderTest
return mMethodData;
}
// PaymentAppFactoryParams implementation.
@Override
public PaymentItem getRawTotal() {
// This test doesn't need this value.
return null;
}
// PaymentAppFactoryParams implementation.
@Override
public PaymentOptions getPaymentOptions() {
......
......@@ -8,11 +8,8 @@ import androidx.annotation.Nullable;
import org.chromium.content_public.browser.RenderFrameHost;
import org.chromium.content_public.browser.WebContents;
import org.chromium.payments.mojom.PaymentDetailsModifier;
import org.chromium.url.Origin;
import java.util.Map;
/** Interface for providing information to a payment app factory. */
public interface PaymentAppFactoryParams extends PaymentRequestParams {
/** @return The web contents where the payment is being requested. */
......@@ -60,15 +57,6 @@ public interface PaymentAppFactoryParams extends PaymentRequestParams {
return null;
}
/**
* @return The unmodifiable mapping of method names to modifiers, which include modified totals
* and additional line items. Used to display modified totals for each payment app, modified
* total in order summary, and additional line items in order summary. Should not be null.
*/
default Map<String, PaymentDetailsModifier> getModifiers() {
return null;
}
/**
* @return Whether crawling the web for just-in-time installable payment handlers is enabled.
*/
......
......@@ -4,6 +4,8 @@
package org.chromium.components.payments;
import org.chromium.payments.mojom.PaymentDetailsModifier;
import org.chromium.payments.mojom.PaymentItem;
import org.chromium.payments.mojom.PaymentMethodData;
import org.chromium.payments.mojom.PaymentOptions;
......@@ -16,9 +18,22 @@ public interface PaymentRequestParams {
/** @return The PaymentOptions set by the merchant. */
PaymentOptions getPaymentOptions();
/**
* @return The unmodifiable mapping of method names to modifiers, which include modified totals
* and additional line items. Used to display modified totals for each payment app, modified
* total in order summary, and additional line items in order summary. Should not be null.
*/
Map<String, PaymentDetailsModifier> getModifiers();
/**
* @return The unmodifiable mapping of payment method identifier to the method-specific data in
* the payment request.
*/
Map<String, PaymentMethodData> getMethodData();
/**
* @return The raw total amount being charged - the total property of the PaymentDetails of
* payment request.
*/
PaymentItem getRawTotal();
}
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