mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 5 | #include "components/payments/content/payment_request.h" |
| 6 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 7 | #include <algorithm> |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 8 | #include <unordered_map> |
| 9 | #include <utility> |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 10 | |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame] | 11 | #include "base/memory/ptr_util.h" |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 12 | #include "components/autofill/core/browser/autofill_data_util.h" |
| 13 | #include "components/autofill/core/browser/field_types.h" |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 14 | #include "components/autofill/core/browser/personal_data_manager.h" |
| 15 | #include "components/payments/content/payment_details_validation.h" |
| 16 | #include "components/payments/content/payment_request_web_contents_manager.h" |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame^] | 17 | #include "components/payments/core/autofill_payment_instrument.h" |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 18 | #include "components/payments/core/currency_formatter.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 19 | #include "content/public/browser/browser_thread.h" |
| 20 | #include "content/public/browser/web_contents.h" |
| 21 | |
| 22 | namespace payments { |
| 23 | |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame^] | 24 | namespace { |
| 25 | // Identifier for the basic card payment method in the PaymentMethodData. |
| 26 | static const char* const kBasicCardMethodName = "basic-card"; |
| 27 | } // namespace |
| 28 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 29 | PaymentRequest::PaymentRequest( |
| 30 | content::WebContents* web_contents, |
| 31 | std::unique_ptr<PaymentRequestDelegate> delegate, |
| 32 | PaymentRequestWebContentsManager* manager, |
| 33 | mojo::InterfaceRequest<payments::mojom::PaymentRequest> request) |
| 34 | : web_contents_(web_contents), |
| 35 | delegate_(std::move(delegate)), |
| 36 | manager_(manager), |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 37 | binding_(this, std::move(request)), |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 38 | is_ready_to_pay_(false), |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 39 | selected_shipping_profile_(nullptr), |
anthonyvd | 75bc466 | 2017-02-22 22:04:43 | [diff] [blame] | 40 | selected_contact_profile_(nullptr), |
| 41 | selected_credit_card_(nullptr) { |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 42 | // OnConnectionTerminated will be called when the Mojo pipe is closed. This |
| 43 | // will happen as a result of many renderer-side events (both successful and |
| 44 | // erroneous in nature). |
| 45 | // TODO(crbug.com/683636): Investigate using |
| 46 | // set_connection_error_with_reason_handler with Binding::CloseWithReason. |
| 47 | binding_.set_connection_error_handler(base::Bind( |
| 48 | &PaymentRequest::OnConnectionTerminated, base::Unretained(this))); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | PaymentRequest::~PaymentRequest() {} |
| 52 | |
| 53 | void PaymentRequest::Init( |
| 54 | payments::mojom::PaymentRequestClientPtr client, |
mathp | c2d07f96 | 2017-02-17 18:33:51 | [diff] [blame] | 55 | std::vector<payments::mojom::PaymentMethodDataPtr> method_data, |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 56 | payments::mojom::PaymentDetailsPtr details, |
| 57 | payments::mojom::PaymentOptionsPtr options) { |
| 58 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 59 | std::string error; |
| 60 | if (!payments::validatePaymentDetails(details, &error)) { |
| 61 | LOG(ERROR) << error; |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 62 | OnConnectionTerminated(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | client_ = std::move(client); |
| 66 | details_ = std::move(details); |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 67 | options_ = std::move(options); |
mathp | c2d07f96 | 2017-02-17 18:33:51 | [diff] [blame] | 68 | PopulateValidatedMethodData(method_data); |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 69 | PopulateProfileCache(); |
| 70 | SetDefaultProfileSelections(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void PaymentRequest::Show() { |
tmartino | 8ce92285 | 2017-01-09 22:23:10 | [diff] [blame] | 74 | if (!client_.is_bound() || !binding_.is_bound()) { |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 75 | LOG(ERROR) << "Attempted Show(), but binding(s) missing."; |
| 76 | OnConnectionTerminated(); |
tmartino | 8ce92285 | 2017-01-09 22:23:10 | [diff] [blame] | 77 | return; |
| 78 | } |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 79 | delegate_->ShowDialog(this); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 80 | } |
| 81 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 82 | void PaymentRequest::Abort() { |
| 83 | // The API user has decided to abort. We return a successful abort message to |
| 84 | // the renderer, which closes the Mojo message pipe, which triggers |
| 85 | // PaymentRequest::OnConnectionTerminated, which destroys this object. |
| 86 | if (client_.is_bound()) |
| 87 | client_->OnAbort(true /* aborted_successfully */); |
| 88 | } |
| 89 | |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame^] | 90 | void PaymentRequest::Complete(payments::mojom::PaymentComplete result) { |
| 91 | if (!client_.is_bound()) |
| 92 | return; |
| 93 | |
| 94 | // TODO(mathp): Validate |result|. |
| 95 | |
| 96 | // When the renderer closes the connection, |
| 97 | // PaymentRequest::OnConnectionTerminated will be called. |
| 98 | client_->OnComplete(); |
| 99 | } |
| 100 | |
| 101 | void PaymentRequest::CanMakePayment() { |
| 102 | // TODO(mathp): Return whether we can make payment. |
| 103 | client_->OnCanMakePayment(mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT); |
| 104 | } |
| 105 | |
| 106 | void PaymentRequest::OnInstrumentDetailsReady( |
| 107 | const std::string& method_name, |
| 108 | const std::string& stringified_details) { |
| 109 | payment_response_->method_name = method_name; |
| 110 | payment_response_->stringified_details = stringified_details; |
| 111 | client_->OnPaymentResponse(std::move(payment_response_)); |
| 112 | } |
| 113 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 114 | void PaymentRequest::UserCancelled() { |
| 115 | // If |client_| is not bound, then the object is already being destroyed as |
| 116 | // a result of a renderer event. |
| 117 | if (!client_.is_bound()) |
| 118 | return; |
| 119 | |
| 120 | // This sends an error to the renderer, which informs the API user. |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 121 | client_->OnError(payments::mojom::PaymentErrorReason::USER_CANCEL); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 122 | |
| 123 | // We close all bindings and ask to be destroyed. |
| 124 | client_.reset(); |
| 125 | binding_.Close(); |
| 126 | manager_->DestroyRequest(this); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 127 | } |
| 128 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 129 | void PaymentRequest::OnConnectionTerminated() { |
| 130 | // We are here because of a browser-side error, or likely as a result of the |
| 131 | // connection_error_handler on |binding_|, which can mean that the renderer |
| 132 | // has decided to close the pipe for various reasons (see all uses of |
| 133 | // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close |
| 134 | // the binding and the dialog, and ask to be deleted. |
| 135 | client_.reset(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 136 | binding_.Close(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 137 | delegate_->CloseDialog(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 138 | manager_->DestroyRequest(this); |
| 139 | } |
| 140 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 141 | void PaymentRequest::Pay() { |
| 142 | DCHECK(is_ready_to_pay_); |
| 143 | |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame^] | 144 | // TODO(mathp): Fill other fields in the PaymentResponsePtr object. |
| 145 | payment_response_ = mojom::PaymentResponse::New(); |
| 146 | |
| 147 | // TODO(mathp): PaymentRequest should know about the currently selected |
| 148 | // instrument, and not |selected_credit_card_| which is too specific. |
| 149 | // TODO(mathp): The method_name should reflect what the merchant asked, and |
| 150 | // not necessarily basic-card. |
| 151 | selected_payment_instrument_.reset(new AutofillPaymentInstrument( |
| 152 | kBasicCardMethodName, *selected_credit_card_, shipping_profiles_, |
| 153 | delegate_->GetApplicationLocale())); |
| 154 | // Fetch the instrument details, will call back into |
| 155 | // PaymentRequest::OnInstrumentsDetailsReady. |
| 156 | selected_payment_instrument_->InvokePaymentApp(this); |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void PaymentRequest::AddObserver(Observer* observer) { |
| 160 | CHECK(observer); |
| 161 | observers_.AddObserver(observer); |
| 162 | } |
| 163 | |
| 164 | void PaymentRequest::RemoveObserver(Observer* observer) { |
| 165 | observers_.RemoveObserver(observer); |
| 166 | } |
| 167 | |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 168 | CurrencyFormatter* PaymentRequest::GetOrCreateCurrencyFormatter( |
| 169 | const std::string& currency_code, |
jinho.bang | 4276454 | 2017-01-24 14:42:56 | [diff] [blame] | 170 | const std::string& currency_system, |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 171 | const std::string& locale_name) { |
| 172 | if (!currency_formatter_) { |
| 173 | currency_formatter_.reset( |
| 174 | new CurrencyFormatter(currency_code, currency_system, locale_name)); |
| 175 | } |
mathp | 6758be03 | 2017-01-13 04:49:50 | [diff] [blame] | 176 | return currency_formatter_.get(); |
| 177 | } |
| 178 | |
anthonyvd | b0233f2 | 2017-03-06 20:34:47 | [diff] [blame] | 179 | base::string16 PaymentRequest::GetFormattedCurrencyAmount( |
| 180 | const std::string& amount) { |
| 181 | CurrencyFormatter* formatter = |
| 182 | GetOrCreateCurrencyFormatter(details()->total->amount->currency, |
| 183 | details()->total->amount->currency_system, |
| 184 | delegate_->GetApplicationLocale()); |
| 185 | return formatter->Format(amount); |
| 186 | } |
| 187 | |
| 188 | std::string PaymentRequest::GetFormattedCurrencyCode() { |
| 189 | CurrencyFormatter* formatter = |
| 190 | GetOrCreateCurrencyFormatter(details()->total->amount->currency, |
| 191 | details()->total->amount->currency_system, |
| 192 | delegate_->GetApplicationLocale()); |
| 193 | |
| 194 | return formatter->formatted_currency_code(); |
| 195 | } |
| 196 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 197 | void PaymentRequest::SetSelectedShippingProfile( |
| 198 | autofill::AutofillProfile* profile) { |
| 199 | selected_shipping_profile_ = profile; |
| 200 | UpdateIsReadyToPayAndNotifyObservers(); |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 201 | } |
| 202 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 203 | void PaymentRequest::SetSelectedContactProfile( |
| 204 | autofill::AutofillProfile* profile) { |
| 205 | selected_contact_profile_ = profile; |
| 206 | UpdateIsReadyToPayAndNotifyObservers(); |
| 207 | } |
| 208 | |
| 209 | void PaymentRequest::SetSelectedCreditCard(autofill::CreditCard* card) { |
| 210 | selected_credit_card_ = card; |
| 211 | UpdateIsReadyToPayAndNotifyObservers(); |
tmartino | 68c0a27 | 2017-01-19 17:44:08 | [diff] [blame] | 212 | } |
| 213 | |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 214 | void PaymentRequest::PopulateProfileCache() { |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 215 | std::vector<autofill::AutofillProfile*> profiles = |
mathp | d4cfd8f | 2017-02-09 21:16:53 | [diff] [blame] | 216 | personal_data_manager()->GetProfilesToSuggest(); |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 217 | |
| 218 | // PaymentRequest may outlive the Profiles returned by the Data Manager. |
| 219 | // Thus, we store copies, and return a vector of pointers to these copies |
anthonyvd | 75bc466 | 2017-02-22 22:04:43 | [diff] [blame] | 220 | // whenever Profiles are requested. The same is true for credit cards. |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 221 | for (size_t i = 0; i < profiles.size(); i++) { |
| 222 | profile_cache_.push_back( |
| 223 | base::MakeUnique<autofill::AutofillProfile>(*profiles[i])); |
| 224 | |
| 225 | // TODO(tmartino): Implement deduplication rules specific to shipping and |
| 226 | // contact profiles. |
| 227 | shipping_profiles_.push_back(profile_cache_[i].get()); |
| 228 | contact_profiles_.push_back(profile_cache_[i].get()); |
| 229 | } |
anthonyvd | 75bc466 | 2017-02-22 22:04:43 | [diff] [blame] | 230 | |
| 231 | const std::vector<autofill::CreditCard*>& cards = |
| 232 | personal_data_manager()->GetCreditCardsToSuggest(); |
| 233 | for (autofill::CreditCard* card : cards) { |
| 234 | card_cache_.push_back(base::MakeUnique<autofill::CreditCard>(*card)); |
| 235 | credit_cards_.push_back(card_cache_.back().get()); |
| 236 | } |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void PaymentRequest::SetDefaultProfileSelections() { |
| 240 | if (!shipping_profiles().empty()) |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 241 | selected_shipping_profile_ = shipping_profiles()[0]; |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 242 | |
| 243 | if (!contact_profiles().empty()) |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 244 | selected_contact_profile_ = contact_profiles()[0]; |
anthonyvd | 75bc466 | 2017-02-22 22:04:43 | [diff] [blame] | 245 | |
| 246 | // TODO(anthonyvd): Change this code to prioritize server cards and implement |
| 247 | // a way to modify this function's return value. |
| 248 | const std::vector<autofill::CreditCard*> cards = credit_cards(); |
| 249 | auto first_complete_card = |
| 250 | std::find_if(cards.begin(), cards.end(), |
| 251 | [](autofill::CreditCard* card) { return card->IsValid(); }); |
| 252 | |
| 253 | selected_credit_card_ = |
| 254 | first_complete_card == cards.end() ? nullptr : *first_complete_card; |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 255 | |
| 256 | UpdateIsReadyToPayAndNotifyObservers(); |
tmartino | 3640562 | 2017-01-26 16:23:03 | [diff] [blame] | 257 | } |
| 258 | |
mathp | c2d07f96 | 2017-02-17 18:33:51 | [diff] [blame] | 259 | void PaymentRequest::PopulateValidatedMethodData( |
| 260 | const std::vector<payments::mojom::PaymentMethodDataPtr>& method_data) { |
| 261 | if (method_data.empty()) { |
| 262 | LOG(ERROR) << "Invalid payment methods or data"; |
| 263 | OnConnectionTerminated(); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | std::set<std::string> card_networks{"amex", "diners", "discover", |
| 268 | "jcb", "mastercard", "mir", |
| 269 | "unionpay", "visa"}; |
| 270 | for (const payments::mojom::PaymentMethodDataPtr& method_data_entry : |
| 271 | method_data) { |
| 272 | std::vector<std::string> supported_methods = |
| 273 | method_data_entry->supported_methods; |
| 274 | if (supported_methods.empty()) { |
| 275 | LOG(ERROR) << "Invalid payment methods or data"; |
| 276 | OnConnectionTerminated(); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | for (const std::string& method : supported_methods) { |
| 281 | if (method.empty()) |
| 282 | continue; |
| 283 | |
| 284 | // If a card network is specified right in "supportedMethods", add it. |
| 285 | auto card_it = card_networks.find(method); |
| 286 | if (card_it != card_networks.end()) { |
| 287 | supported_card_networks_.push_back(method); |
| 288 | // |method| removed from |card_networks| so that it is not doubly added |
| 289 | // to |supported_card_networks_| if "basic-card" is specified with no |
| 290 | // supported networks. |
| 291 | card_networks.erase(card_it); |
| 292 | } else if (method == kBasicCardMethodName) { |
| 293 | // For the "basic-card" method, check "supportedNetworks". |
| 294 | if (method_data_entry->supported_networks.empty()) { |
| 295 | // Empty |supported_networks| means all networks are supported. |
| 296 | supported_card_networks_.insert(supported_card_networks_.end(), |
| 297 | card_networks.begin(), |
| 298 | card_networks.end()); |
| 299 | // Clear the set so that no further networks are added to |
| 300 | // |supported_card_networks_|. |
| 301 | card_networks.clear(); |
| 302 | } else { |
| 303 | // The merchant has specified a few basic card supported networks. Use |
| 304 | // the mapping to transform to known basic-card types. |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 305 | using ::payments::mojom::BasicCardNetwork; |
mathp | c2d07f96 | 2017-02-17 18:33:51 | [diff] [blame] | 306 | std::unordered_map<BasicCardNetwork, std::string> networks = { |
| 307 | {BasicCardNetwork::AMEX, "amex"}, |
| 308 | {BasicCardNetwork::DINERS, "diners"}, |
| 309 | {BasicCardNetwork::DISCOVER, "discover"}, |
| 310 | {BasicCardNetwork::JCB, "jcb"}, |
| 311 | {BasicCardNetwork::MASTERCARD, "mastercard"}, |
| 312 | {BasicCardNetwork::MIR, "mir"}, |
| 313 | {BasicCardNetwork::UNIONPAY, "unionpay"}, |
| 314 | {BasicCardNetwork::VISA, "visa"}}; |
| 315 | for (const BasicCardNetwork& supported_network : |
| 316 | method_data_entry->supported_networks) { |
| 317 | // Make sure that the network was not already added to |
| 318 | // |supported_card_networks_|. |
| 319 | auto card_it = card_networks.find(networks[supported_network]); |
| 320 | if (card_it != card_networks.end()) { |
| 321 | supported_card_networks_.push_back(networks[supported_network]); |
| 322 | card_networks.erase(card_it); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 331 | void PaymentRequest::UpdateIsReadyToPayAndNotifyObservers() { |
| 332 | is_ready_to_pay_ = |
| 333 | ArePaymentDetailsSatisfied() && ArePaymentOptionsSatisfied(); |
| 334 | NotifyOnSelectedInformationChanged(); |
| 335 | } |
| 336 | |
| 337 | void PaymentRequest::NotifyOnSelectedInformationChanged() { |
| 338 | for (auto& observer : observers_) |
| 339 | observer.OnSelectedInformationChanged(); |
| 340 | } |
| 341 | |
| 342 | bool PaymentRequest::ArePaymentDetailsSatisfied() { |
| 343 | // TODO(mathp): A masked card may not satisfy IsValid(). |
| 344 | if (selected_credit_card_ == nullptr || !selected_credit_card_->IsValid()) |
| 345 | return false; |
| 346 | |
| 347 | const std::string basic_card_payment_type = |
| 348 | autofill::data_util::GetPaymentRequestData(selected_credit_card_->type()) |
| 349 | .basic_card_payment_type; |
| 350 | return !supported_card_networks_.empty() && |
| 351 | std::find(supported_card_networks_.begin(), |
| 352 | supported_card_networks_.end(), |
| 353 | basic_card_payment_type) != supported_card_networks_.end(); |
| 354 | } |
| 355 | |
| 356 | bool PaymentRequest::ArePaymentOptionsSatisfied() { |
| 357 | // TODO(mathp): Have a measure of shipping address completeness. |
mathp | abf6675 | 2017-03-01 22:16:44 | [diff] [blame] | 358 | if (request_shipping() && selected_shipping_profile_ == nullptr) |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 359 | return false; |
| 360 | |
| 361 | // TODO(mathp): Make an encompassing class to validate contact info. |
| 362 | const std::string& app_locale = delegate_->GetApplicationLocale(); |
mathp | abf6675 | 2017-03-01 22:16:44 | [diff] [blame] | 363 | if (request_payer_name() && |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 364 | (selected_contact_profile_ == nullptr || |
| 365 | selected_contact_profile_ |
| 366 | ->GetInfo(autofill::AutofillType(autofill::NAME_FULL), app_locale) |
| 367 | .empty())) { |
| 368 | return false; |
| 369 | } |
mathp | abf6675 | 2017-03-01 22:16:44 | [diff] [blame] | 370 | if (request_payer_email() && |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 371 | (selected_contact_profile_ == nullptr || |
| 372 | selected_contact_profile_ |
| 373 | ->GetInfo(autofill::AutofillType(autofill::EMAIL_ADDRESS), |
| 374 | app_locale) |
| 375 | .empty())) { |
| 376 | return false; |
| 377 | } |
mathp | abf6675 | 2017-03-01 22:16:44 | [diff] [blame] | 378 | if (request_payer_phone() && |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 379 | (selected_contact_profile_ == nullptr || |
| 380 | selected_contact_profile_ |
| 381 | ->GetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), |
| 382 | app_locale) |
| 383 | .empty())) { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | return true; |
| 388 | } |
| 389 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 390 | } // namespace payments |