Index: components/payments/content/payment_request_state.cc |
diff --git a/components/payments/content/payment_request_state.cc b/components/payments/content/payment_request_state.cc |
index 5628fadf082bc092d1a9dd21c379a2b2d38253bf..36dcc3676ada83c25076e0d76980dde311e4771b 100644 |
--- a/components/payments/content/payment_request_state.cc |
+++ b/components/payments/content/payment_request_state.cc |
@@ -9,6 +9,7 @@ |
#include <utility> |
#include "base/strings/utf_string_conversions.h" |
+#include "components/autofill/core/browser/autofill_country.h" |
#include "components/autofill/core/browser/autofill_data_util.h" |
#include "components/autofill/core/browser/autofill_profile.h" |
#include "components/autofill/core/browser/credit_card.h" |
@@ -47,6 +48,21 @@ void PaymentRequestState::OnPaymentResponseReady( |
delegate_->OnPaymentResponseAvailable(std::move(payment_response)); |
} |
+void PaymentRequestState::OnAddressNormalized( |
+ const autofill::AutofillProfile& normalized_profile) { |
+ UpdateIsReadyToPayAndNotifyObservers(); |
Mathieu
2017/04/26 13:09:49
what could have changed that may affect "is ready
sebsg
2017/04/26 19:28:53
I made a bunch of changes to this logic, to make s
|
+ delegate_->OnShippingAddressSelected( |
+ PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
+ normalized_profile, app_locale_)); |
+} |
+ |
+void PaymentRequestState::OnCouldNotNormalize( |
+ const autofill::AutofillProfile& profile) { |
+ // Since the phone number is formatted in either case, this profile should be |
+ // used. |
+ OnAddressNormalized(profile); |
+} |
+ |
bool PaymentRequestState::CanMakePayment() const { |
for (const std::unique_ptr<PaymentInstrument>& instrument : |
available_instruments_) { |
@@ -133,10 +149,17 @@ void PaymentRequestState::SetSelectedShippingProfile( |
spec_->StartWaitingForUpdateWith( |
PaymentRequestSpec::UpdateReason::SHIPPING_ADDRESS); |
selected_shipping_profile_ = profile; |
- UpdateIsReadyToPayAndNotifyObservers(); |
- delegate_->OnShippingAddressSelected( |
- PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile( |
- selected_shipping_profile_, app_locale_)); |
+ |
+ // Start the normalization of the shipping address. |
+ // Use the country code from the profile if it is set, otherwise infer it |
+ // from the |app_locale_|. |
+ std::string country_code = base::UTF16ToUTF8( |
+ selected_shipping_profile_->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
+ if (!autofill::data_util::IsValidCountryCode(country_code)) { |
Mathieu
2017/04/26 13:09:49
no curlies
sebsg
2017/04/26 19:28:53
Done.
|
+ country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale_); |
+ } |
+ payment_request_delegate_->GetAddressNormalizer()->StartAddressNormalization( |
+ *selected_shipping_profile_, country_code, /*timeout_seconds=*/2, this); |
} |
void PaymentRequestState::SetSelectedContactProfile( |