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

Side by Side Diff: components/payments/content/payment_response_helper.cc

Issue 2810293002: [Payments] Format contact detail phone desktop (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/content/payment_response_helper.h" 5 #include "components/payments/content/payment_response_helper.h"
6 6
7 #include "base/strings/string_split.h" 7 #include "base/strings/string_split.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/autofill_type.h" 10 #include "components/autofill/core/browser/autofill_type.h"
11 #include "components/payments/content/payment_request_spec.h" 11 #include "components/payments/content/payment_request_spec.h"
12 #include "third_party/libphonenumber/phonenumber_api.h"
12 13
13 namespace payments { 14 namespace payments {
14 15
16 namespace {
17
18 using ::i18n::phonenumbers::PhoneNumberUtil;
19
20 } // namespace
21
15 PaymentResponseHelper::PaymentResponseHelper( 22 PaymentResponseHelper::PaymentResponseHelper(
16 const std::string& app_locale, 23 const std::string& app_locale,
17 PaymentRequestSpec* spec, 24 PaymentRequestSpec* spec,
18 PaymentInstrument* selected_instrument, 25 PaymentInstrument* selected_instrument,
19 autofill::AutofillProfile* selected_shipping_profile, 26 autofill::AutofillProfile* selected_shipping_profile,
20 autofill::AutofillProfile* selected_contact_profile, 27 autofill::AutofillProfile* selected_contact_profile,
21 Delegate* delegate) 28 Delegate* delegate)
22 : app_locale_(app_locale), 29 : app_locale_(app_locale),
23 spec_(spec), 30 spec_(spec),
24 delegate_(delegate), 31 delegate_(delegate),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 base::UTF16ToUTF8(selected_contact_profile_->GetInfo( 112 base::UTF16ToUTF8(selected_contact_profile_->GetInfo(
106 autofill::AutofillType(autofill::NAME_FULL), app_locale_)); 113 autofill::AutofillType(autofill::NAME_FULL), app_locale_));
107 } 114 }
108 if (spec_->request_payer_email()) { 115 if (spec_->request_payer_email()) {
109 DCHECK(selected_contact_profile_); 116 DCHECK(selected_contact_profile_);
110 payment_response->payer_email = base::UTF16ToUTF8( 117 payment_response->payer_email = base::UTF16ToUTF8(
111 selected_contact_profile_->GetRawInfo(autofill::EMAIL_ADDRESS)); 118 selected_contact_profile_->GetRawInfo(autofill::EMAIL_ADDRESS));
112 } 119 }
113 if (spec_->request_payer_phone()) { 120 if (spec_->request_payer_phone()) {
114 DCHECK(selected_contact_profile_); 121 DCHECK(selected_contact_profile_);
115 // TODO(crbug.com/705945): Format phone number according to spec. 122
116 payment_response->payer_phone = 123 // Try to format the phone number to the E.164 format to send in the Payment
117 base::UTF16ToUTF8(selected_contact_profile_->GetRawInfo( 124 // Response, as defined in the Payment Request spec. If it's not possible,
118 autofill::PHONE_HOME_WHOLE_NUMBER)); 125 // send the original. More info at:
126 // https://w3c.github.io/browser-payment-api/#paymentrequest-updated-algorit hm
127 const std::string original_number =
Mathieu 2017/04/12 21:03:30 TODO to move the code
128 base::UTF16ToUTF8(selected_contact_profile_->GetInfo(
129 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
130 app_locale_));
131 i18n::phonenumbers::PhoneNumber parsed_number;
132 PhoneNumberUtil* phone_number_util = PhoneNumberUtil::GetInstance();
133 if (phone_number_util->Parse(original_number, "US", &parsed_number) ==
134 ::i18n::phonenumbers::PhoneNumberUtil::NO_PARSING_ERROR) {
135 std::string formatted_number;
136 phone_number_util->Format(parsed_number,
137 PhoneNumberUtil::PhoneNumberFormat::E164,
138 &formatted_number);
139 payment_response->payer_phone = formatted_number;
140 } else {
141 payment_response->payer_phone = original_number;
Mathieu 2017/04/12 21:03:30 we really shouldn't get here, but coordinate with
142 }
119 } 143 }
120 144
121 delegate_->OnPaymentResponseReady(std::move(payment_response)); 145 delegate_->OnPaymentResponseReady(std::move(payment_response));
122 } 146 }
123 147
124 } // namespace payments 148 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/DEPS ('k') | components/payments/content/payment_response_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698