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

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

Issue 2808983003: [Payments] Format shipping and billing phone number in normalizer. (Closed)
Patch Set: Nits Created 3 years, 8 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
« no previous file with comments | « components/payments/core/DEPS ('k') | components/payments/core/address_normalizer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/payments/core/address_normalizer.cc
diff --git a/components/payments/core/address_normalizer.cc b/components/payments/core/address_normalizer.cc
index 3114c5a89229cfc2a60ca2e02ebaf7f9b13819c1..d432ff11e15db4ef13718c99c3fec1cf22d97269 100644
--- a/components/payments/core/address_normalizer.cc
+++ b/components/payments/core/address_normalizer.cc
@@ -18,6 +18,7 @@
#include "base/time/time.h"
#include "components/autofill/core/browser/address_i18n.h"
#include "components/autofill/core/browser/autofill_profile.h"
+#include "components/payments/core/payment_request_data_util.h"
#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
#include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h"
@@ -62,6 +63,9 @@ class AddressNormalizationRequest : public AddressNormalizer::Request {
return;
has_responded_ = true;
+ // In either case, format the phone number.
+ FormatPhoneNumberForResponse();
+
if (!success) {
delegate_->OnCouldNotNormalize(profile_);
return;
@@ -90,6 +94,22 @@ class AddressNormalizationRequest : public AddressNormalizer::Request {
}
private:
+ // Tries to format the phone number to the E.164 format to send in the Payment
+ // Response, as defined in the Payment Request spec. Keeps the original
+ // if it cannot be formatted. More info at:
+ // https://w3c.github.io/browser-payment-api/#paymentrequest-updated-algorithm
+ void FormatPhoneNumberForResponse() {
+ const std::string original_number = base::UTF16ToUTF8(profile_.GetInfo(
+ autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
+ region_code_));
+
+ std::string formatted_number =
+ data_util::FormatPhoneForResponse(original_number, region_code_);
+
+ profile_.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
+ base::UTF8ToUTF16(formatted_number));
+ }
+
AutofillProfile profile_;
std::string region_code_;
AddressNormalizer::Delegate* delegate_;
« no previous file with comments | « components/payments/core/DEPS ('k') | components/payments/core/address_normalizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698