[iOS][Gpay Settings] Update edit table edit button redirection
Previously it redirected to the general gpay web page. Now it redirects
to the detail page for the card.
Impl:
https://screenshot.googleplex.com/7X4rZYaj3Qy3vYU
https://screenshot.googleplex.com/4yH2nQi66BCoPdu
Bug: b/281595962
Change-Id: If30dcc69b8b3d39e6825738878297ea71f8f8c32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5362426
Reviewed-by: Olivia Saul <jsaul@google.com>
Reviewed-by: Vidhan Jain <vidhanj@google.com>
Commit-Queue: Siyu An <siyua@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1272435}
diff --git a/components/autofill/core/browser/payments/payments_service_url.cc b/components/autofill/core/browser/payments/payments_service_url.cc
index 074d955..490f0b7 100644
--- a/components/autofill/core/browser/payments/payments_service_url.cc
+++ b/components/autofill/core/browser/payments/payments_service_url.cc
@@ -76,6 +76,17 @@
: kSandboxPaymentsManageCardsUrl));
}
+GURL GetManageInstrumentUrl(int64_t instrument_id) {
+ CHECK(base::FeatureList::IsEnabled(
+ features::kAutofillUpdateChromeSettingsLinkToGPayWeb));
+ GURL url = GetManageInstrumentsUrl();
+ std::string new_query =
+ base::StrCat({url.query(), "&id=", base::NumberToString(instrument_id)});
+ GURL::Replacements replacements;
+ replacements.SetQueryStr(new_query);
+ return url.ReplaceComponents(replacements);
+}
+
GURL GetManageAddressesUrl() {
// Billing addresses are now managed as a part of the payment instrument.
return GetManageInstrumentsUrl();
diff --git a/components/autofill/core/browser/payments/payments_service_url.h b/components/autofill/core/browser/payments/payments_service_url.h
index 7bff52c..5c363dd 100644
--- a/components/autofill/core/browser/payments/payments_service_url.h
+++ b/components/autofill/core/browser/payments/payments_service_url.h
@@ -6,11 +6,11 @@
#define COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_URL_H_
#include <stddef.h>
+#include <stdint.h>
class GURL;
-namespace autofill {
-namespace payments {
+namespace autofill::payments {
// Returns true if production Payments URLs should be used or false if sandbox
// should be used.
@@ -21,14 +21,17 @@
// Returns the URL to navigate to in order to allow the user to edit or delete
// payment instruments (credit cards) or addresses, respectively.
+// `GetManageInstrumentsUrl` redirects to the top level page that contains a
+// list of instruments while `GetManageInstrumentUrl` redirects to the detail
+// page for a particular instrument given the `instrument_id`.
GURL GetManageInstrumentsUrl();
+GURL GetManageInstrumentUrl(int64_t instrument_id);
GURL GetManageAddressesUrl();
// Returns the support URL for users to learn more about virtual cards during
// the virtual card enrollment bubble.
GURL GetVirtualCardEnrollmentSupportUrl();
-} // namespace payments
-} // namespace autofill
+} // namespace autofill::payments
#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_PAYMENTS_PAYMENTS_SERVICE_URL_H_
diff --git a/components/autofill/core/browser/payments/payments_service_url_unittest.cc b/components/autofill/core/browser/payments/payments_service_url_unittest.cc
index 9ed72e74..1846fd5 100644
--- a/components/autofill/core/browser/payments/payments_service_url_unittest.cc
+++ b/components/autofill/core/browser/payments/payments_service_url_unittest.cc
@@ -78,5 +78,17 @@
EXPECT_EQ(kExpectedURL, GetManageAddressesUrl().spec());
}
+TEST(PaymentsServiceUrl, UrlWithInstrumentId) {
+ base::test::ScopedFeatureList feature_list(
+ features::kAutofillUpdateChromeSettingsLinkToGPayWeb);
+
+ const char kExpectedURL[] =
+ "https://pay.google.com/"
+ "pay?p=paymentmethods&utm_source=chrome&utm_medium=settings&utm_campaign="
+ "payment_methods&id=123";
+
+ EXPECT_EQ(kExpectedURL, GetManageInstrumentUrl(/*instrument_id=*/123).spec());
+}
+
} // namespace payments
} // namespace autofill
diff --git a/ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.mm b/ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.mm
index 589c1e4..88286fad 100644
--- a/ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.mm
+++ b/ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.mm
@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.h"
#import "base/apple/foundation_util.h"
+#import "base/feature_list.h"
#import "base/format_macros.h"
#import "base/ios/block_types.h"
#import "base/memory/raw_ptr.h"
@@ -93,7 +94,12 @@
// In the case of server cards, open the Payments editing page instead.
if (_creditCard.record_type() ==
autofill::CreditCard::RecordType::kMaskedServerCard) {
- GURL paymentsURL = autofill::payments::GetManageInstrumentsUrl();
+ GURL paymentsURL =
+ base::FeatureList::IsEnabled(
+ autofill::features::kAutofillUpdateChromeSettingsLinkToGPayWeb)
+ ? autofill::payments::GetManageInstrumentUrl(
+ _creditCard.instrument_id())
+ : autofill::payments::GetManageInstrumentsUrl();
OpenNewTabCommand* command =
[OpenNewTabCommand commandWithURLFromChrome:paymentsURL];
[self.applicationHandler closeSettingsUIAndOpenURL:command];