Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Unified Diff: components/payments/core/payment_request_data_util.cc

Issue 2949813003: [Payment Request] Formats phone number and credit card number in editors. (Closed)
Patch Set: Fixed broken tests Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/payments/core/payment_request_data_util.cc
diff --git a/components/payments/core/payment_request_data_util.cc b/components/payments/core/payment_request_data_util.cc
index 7f689419603a7f6ac6d17d0017c271ce194d0820..8a9585f7c2fc03d1e1870814ed9f7e3019150c9b 100644
--- a/components/payments/core/payment_request_data_util.cc
+++ b/components/payments/core/payment_request_data_util.cc
@@ -6,6 +6,7 @@
#include "base/strings/string16.h"
#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_country.h"
#include "components/autofill/core/browser/autofill_data_util.h"
@@ -191,6 +192,26 @@ std::string FormatPhoneForResponse(const std::string& phone_number,
PhoneNumberUtil::PhoneNumberFormat::E164);
}
+base::string16 FormatCardNumberForDisplay(const base::string16& card_number) {
+ base::string16 number = autofill::CreditCard::StripSeparators(card_number);
+ if (number.empty() || !base::IsAsciiDigit(number[0]))
+ return card_number;
+
+ std::vector<size_t> positions = {4U, 9U, 14U};
+ if (autofill::CreditCard::GetCardNetwork(number) ==
+ autofill::kAmericanExpressCard) {
+ positions = {4U, 11U};
+ }
+
+ static const base::char16 kSeparator = base::ASCIIToUTF16(" ")[0];
+ for (size_t i : positions) {
+ if (number.size() > i)
+ number.insert(i, 1U, kSeparator);
+ }
+
+ return number;
+}
+
std::string GetCountryCodeWithFallback(const autofill::AutofillProfile* profile,
const std::string& app_locale) {
std::string country_code =
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | ios/chrome/browser/ui/payments/address_edit_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698