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 | |
anthonyvd | d23ed70 | 2017-04-05 15:29:00 | [diff] [blame] | 7 | #include <string> |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 8 | #include <utility> |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 9 | |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 10 | #include "base/feature_list.h" |
Mathieu Perreault | 627b97c | 2017-08-12 00:44:22 | [diff] [blame] | 11 | #include "base/stl_util.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 12 | #include "components/payments/content/can_make_payment_query_factory.h" |
Rouslan Solomakhin | 4eea9bc2 | 2017-10-10 15:18:51 | [diff] [blame] | 13 | #include "components/payments/content/content_payment_request_delegate.h" |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 14 | #include "components/payments/content/origin_security_checker.h" |
Mohamad Ahmadi | f5544bb | 2017-09-01 21:48:22 | [diff] [blame] | 15 | #include "components/payments/content/payment_request_converter.h" |
rouslan | 908248c | 2017-02-27 21:30:24 | [diff] [blame] | 16 | #include "components/payments/content/payment_request_web_contents_manager.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 17 | #include "components/payments/core/can_make_payment_query.h" |
Anthony Vallee-Dubois | 968ae4d | 2018-03-15 16:56:36 | [diff] [blame] | 18 | #include "components/payments/core/features.h" |
Mohamad Ahmadi | f5544bb | 2017-09-01 21:48:22 | [diff] [blame] | 19 | #include "components/payments/core/payment_details.h" |
| 20 | #include "components/payments/core/payment_details_validation.h" |
Mathieu Perreault | 23d25bfb8 | 2018-05-11 14:45:37 | [diff] [blame] | 21 | #include "components/payments/core/payment_instrument.h" |
anthonyvd | 6a43b93 | 2017-05-11 18:39:27 | [diff] [blame] | 22 | #include "components/payments/core/payment_prefs.h" |
Jinho Bang | be463a2 | 2018-08-02 10:26:50 | [diff] [blame] | 23 | #include "components/payments/core/payments_validators.h" |
anthonyvd | 6a43b93 | 2017-05-11 18:39:27 | [diff] [blame] | 24 | #include "components/prefs/pref_service.h" |
Steven Holte | 2083e8bc | 2018-07-16 23:50:36 | [diff] [blame] | 25 | #include "components/ukm/content/source_url_recorder.h" |
Rouslan Solomakhin | 6e979ab | 2017-08-30 17:30:39 | [diff] [blame] | 26 | #include "components/url_formatter/elide_url.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 27 | #include "content/public/browser/browser_thread.h" |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 28 | #include "content/public/browser/render_frame_host.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 29 | #include "content/public/browser/web_contents.h" |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 30 | #include "content/public/common/content_features.h" |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 31 | |
Danyao Wang | ce175bf | 2018-12-21 22:35:58 | [diff] [blame^] | 32 | namespace { |
| 33 | |
| 34 | using ::payments::mojom::HasEnrolledInstrumentQueryResult; |
| 35 | |
| 36 | } // namespace |
| 37 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 38 | namespace payments { |
| 39 | |
| 40 | PaymentRequest::PaymentRequest( |
rouslan | 69099768 | 2017-05-09 18:07:39 | [diff] [blame] | 41 | content::RenderFrameHost* render_frame_host, |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 42 | content::WebContents* web_contents, |
Rouslan Solomakhin | 4eea9bc2 | 2017-10-10 15:18:51 | [diff] [blame] | 43 | std::unique_ptr<ContentPaymentRequestDelegate> delegate, |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 44 | PaymentRequestWebContentsManager* manager, |
Anthony Vallee-Dubois | c7ae733 | 2017-12-19 20:44:07 | [diff] [blame] | 45 | PaymentRequestDisplayManager* display_manager, |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 46 | mojo::InterfaceRequest<mojom::PaymentRequest> request, |
mathp | 300fa54 | 2017-03-27 19:29:37 | [diff] [blame] | 47 | ObserverForTest* observer_for_testing) |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 48 | : web_contents_(web_contents), |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 49 | log_(web_contents_), |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 50 | delegate_(std::move(delegate)), |
| 51 | manager_(manager), |
Anthony Vallee-Dubois | c7ae733 | 2017-12-19 20:44:07 | [diff] [blame] | 52 | display_manager_(display_manager), |
| 53 | display_handle_(nullptr), |
mathp | 300fa54 | 2017-03-27 19:29:37 | [diff] [blame] | 54 | binding_(this, std::move(request)), |
Rouslan Solomakhin | 6e979ab | 2017-08-30 17:30:39 | [diff] [blame] | 55 | top_level_origin_(url_formatter::FormatUrlForSecurityDisplay( |
| 56 | web_contents_->GetLastCommittedURL())), |
| 57 | frame_origin_(url_formatter::FormatUrlForSecurityDisplay( |
| 58 | render_frame_host->GetLastCommittedURL())), |
sebsg | 20b49d7b | 2017-05-04 20:23:17 | [diff] [blame] | 59 | observer_for_testing_(observer_for_testing), |
| 60 | journey_logger_(delegate_->IsIncognito(), |
Steven Holte | 2083e8bc | 2018-07-16 23:50:36 | [diff] [blame] | 61 | ukm::GetSourceIdForWebContentsDocument(web_contents)), |
Anthony Vallee-Dubois | dc1dbf1a | 2017-07-17 15:01:13 | [diff] [blame] | 62 | weak_ptr_factory_(this) { |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 63 | // OnConnectionTerminated will be called when the Mojo pipe is closed. This |
| 64 | // will happen as a result of many renderer-side events (both successful and |
| 65 | // erroneous in nature). |
| 66 | // TODO(crbug.com/683636): Investigate using |
| 67 | // set_connection_error_with_reason_handler with Binding::CloseWithReason. |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 68 | binding_.set_connection_error_handler(base::BindOnce( |
Anthony Vallee-Dubois | dc1dbf1a | 2017-07-17 15:01:13 | [diff] [blame] | 69 | &PaymentRequest::OnConnectionTerminated, weak_ptr_factory_.GetWeakPtr())); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | PaymentRequest::~PaymentRequest() {} |
| 73 | |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 74 | void PaymentRequest::Init(mojom::PaymentRequestClientPtr client, |
| 75 | std::vector<mojom::PaymentMethodDataPtr> method_data, |
| 76 | mojom::PaymentDetailsPtr details, |
| 77 | mojom::PaymentOptionsPtr options) { |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 78 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 79 | |
| 80 | if (is_initialized_) { |
| 81 | log_.Error("Attempted initialization twice"); |
| 82 | OnConnectionTerminated(); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | is_initialized_ = true; |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 87 | client_ = std::move(client); |
| 88 | |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 89 | const GURL last_committed_url = delegate_->GetLastCommittedURL(); |
| 90 | if (!OriginSecurityChecker::IsOriginSecure(last_committed_url)) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 91 | log_.Error("Not in a secure origin"); |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 92 | OnConnectionTerminated(); |
| 93 | return; |
| 94 | } |
| 95 | |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 96 | bool allowed_origin = |
| 97 | OriginSecurityChecker::IsSchemeCryptographic(last_committed_url) || |
| 98 | OriginSecurityChecker::IsOriginLocalhostOrFile(last_committed_url); |
| 99 | if (!allowed_origin) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 100 | log_.Error( |
| 101 | "Only localhost, file://, and cryptographic scheme origins allowed"); |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | bool invalid_ssl = |
| 105 | OriginSecurityChecker::IsSchemeCryptographic(last_committed_url) && |
| 106 | !delegate_->IsSslCertificateValid(); |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 107 | if (invalid_ssl) { |
| 108 | log_.Error("SSL certificate is not valid."); |
| 109 | } |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 110 | |
| 111 | if (!allowed_origin || invalid_ssl) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 112 | // Intentionally don't set |spec_| and |state_|, so the UI is never shown. |
| 113 | log_.Error( |
| 114 | "No UI will be shown. CanMakePayment will always return false. " |
| 115 | "Show will be rejected with NotSupportedError."); |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 119 | std::string error; |
Mohamad Ahmadi | f5544bb | 2017-09-01 21:48:22 | [diff] [blame] | 120 | if (!ValidatePaymentDetails(ConvertPaymentDetails(details), &error)) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 121 | log_.Error(error); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 122 | OnConnectionTerminated(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 123 | return; |
| 124 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 125 | |
jinho.bang | fcb5ec9 | 2017-03-29 08:08:02 | [diff] [blame] | 126 | if (!details->total) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 127 | log_.Error("Missing total"); |
jinho.bang | fcb5ec9 | 2017-03-29 08:08:02 | [diff] [blame] | 128 | OnConnectionTerminated(); |
| 129 | return; |
| 130 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 131 | |
sebsg | a70a6da | 2017-12-21 22:27:02 | [diff] [blame] | 132 | spec_ = std::make_unique<PaymentRequestSpec>( |
mathp | c0d616a | 2017-03-15 14:09:33 | [diff] [blame] | 133 | std::move(options), std::move(details), std::move(method_data), this, |
| 134 | delegate_->GetApplicationLocale()); |
sebsg | a70a6da | 2017-12-21 22:27:02 | [diff] [blame] | 135 | state_ = std::make_unique<PaymentRequestState>( |
Rouslan Solomakhin | dbf593d9 | 2017-11-21 19:20:57 | [diff] [blame] | 136 | web_contents_, top_level_origin_, frame_origin_, spec_.get(), this, |
| 137 | delegate_->GetApplicationLocale(), delegate_->GetPersonalDataManager(), |
| 138 | delegate_.get(), &journey_logger_); |
Mathieu Perreault | 627b97c | 2017-08-12 00:44:22 | [diff] [blame] | 139 | |
| 140 | journey_logger_.SetRequestedInformation( |
| 141 | spec_->request_shipping(), spec_->request_payer_email(), |
| 142 | spec_->request_payer_phone(), spec_->request_payer_name()); |
| 143 | |
| 144 | // Log metrics around which payment methods are requested by the merchant. |
| 145 | GURL google_pay_url(kGooglePayMethodName); |
| 146 | GURL android_pay_url(kAndroidPayMethodName); |
| 147 | // Looking for payment methods that are NOT google-related payment methods. |
| 148 | auto non_google_it = |
| 149 | std::find_if(spec_->url_payment_method_identifiers().begin(), |
| 150 | spec_->url_payment_method_identifiers().end(), |
| 151 | [google_pay_url, android_pay_url](const GURL& url) { |
| 152 | return url != google_pay_url && url != android_pay_url; |
| 153 | }); |
| 154 | journey_logger_.SetRequestedPaymentMethodTypes( |
| 155 | /*requested_basic_card=*/!spec_->supported_card_networks().empty(), |
| 156 | /*requested_method_google=*/ |
| 157 | base::ContainsValue(spec_->url_payment_method_identifiers(), |
| 158 | google_pay_url) || |
| 159 | base::ContainsValue(spec_->url_payment_method_identifiers(), |
| 160 | android_pay_url), |
| 161 | /*requested_method_other=*/non_google_it != |
| 162 | spec_->url_payment_method_identifiers().end()); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 163 | } |
| 164 | |
Rouslan Solomakhin | 833f851 | 2018-04-03 23:19:25 | [diff] [blame] | 165 | void PaymentRequest::Show(bool is_user_gesture) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 166 | if (!IsInitialized()) { |
| 167 | log_.Error("Attempted show without initialization"); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 168 | OnConnectionTerminated(); |
tmartino | 8ce92285 | 2017-01-09 22:23:10 | [diff] [blame] | 169 | return; |
| 170 | } |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 171 | |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 172 | if (is_show_called_) { |
| 173 | log_.Error("Attempted show twice"); |
| 174 | OnConnectionTerminated(); |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | is_show_called_ = true; |
| 179 | |
rouslan | 7d433cc2 | 2017-05-08 15:18:07 | [diff] [blame] | 180 | // A tab can display only one PaymentRequest UI at a time. |
Anthony Vallee-Dubois | 8f5e7e1 | 2018-01-12 16:14:06 | [diff] [blame] | 181 | display_handle_ = display_manager_->TryShow(delegate_.get()); |
Anthony Vallee-Dubois | c7ae733 | 2017-12-19 20:44:07 | [diff] [blame] | 182 | if (!display_handle_) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 183 | log_.Error("A PaymentRequest UI is already showing"); |
sebsg | 828269bc | 2017-06-09 19:11:12 | [diff] [blame] | 184 | journey_logger_.SetNotShown( |
| 185 | JourneyLogger::NOT_SHOWN_REASON_CONCURRENT_REQUESTS); |
Rouslan Solomakhin | b2d233c4 | 2018-08-30 16:18:40 | [diff] [blame] | 186 | client_->OnError(mojom::PaymentErrorReason::ALREADY_SHOWING); |
rouslan | 7d433cc2 | 2017-05-08 15:18:07 | [diff] [blame] | 187 | OnConnectionTerminated(); |
| 188 | return; |
| 189 | } |
| 190 | |
Rouslan Solomakhin | 5b51043 | 2017-09-26 16:59:32 | [diff] [blame] | 191 | if (!delegate_->IsBrowserWindowActive()) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 192 | log_.Error("Cannot show PaymentRequest UI in a background tab"); |
Rouslan Solomakhin | 5b51043 | 2017-09-26 16:59:32 | [diff] [blame] | 193 | journey_logger_.SetNotShown(JourneyLogger::NOT_SHOWN_REASON_OTHER); |
| 194 | client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
| 195 | OnConnectionTerminated(); |
| 196 | return; |
| 197 | } |
| 198 | |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 199 | if (!state_) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 200 | // SSL is not valid. Reject show with NotSupportedError, disconnect the |
| 201 | // mojo pipe, and destroy this object. |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 202 | AreRequestedMethodsSupportedCallback(false); |
| 203 | return; |
| 204 | } |
| 205 | |
Rouslan Solomakhin | 833f851 | 2018-04-03 23:19:25 | [diff] [blame] | 206 | is_show_user_gesture_ = is_user_gesture; |
| 207 | |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 208 | display_handle_->Show(this); |
| 209 | |
gogerald | 0a7ee6c | 2017-11-13 18:23:19 | [diff] [blame] | 210 | state_->AreRequestedMethodsSupported( |
| 211 | base::BindOnce(&PaymentRequest::AreRequestedMethodsSupportedCallback, |
| 212 | weak_ptr_factory_.GetWeakPtr())); |
| 213 | } |
| 214 | |
Jinho Bang | be463a2 | 2018-08-02 10:26:50 | [diff] [blame] | 215 | void PaymentRequest::Retry(mojom::PaymentValidationErrorsPtr errors) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 216 | if (!IsInitialized()) { |
| 217 | log_.Error("Attempted retry without initialization"); |
Jinho Bang | cac8d9a0 | 2018-08-23 19:47:22 | [diff] [blame] | 218 | OnConnectionTerminated(); |
| 219 | return; |
| 220 | } |
| 221 | |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 222 | if (!IsThisPaymentRequestShowing()) { |
| 223 | log_.Error("Attempted retry without show"); |
Jinho Bang | cac8d9a0 | 2018-08-23 19:47:22 | [diff] [blame] | 224 | OnConnectionTerminated(); |
| 225 | return; |
| 226 | } |
| 227 | |
Jinho Bang | be463a2 | 2018-08-02 10:26:50 | [diff] [blame] | 228 | std::string error; |
| 229 | if (!PaymentsValidators::IsValidPaymentValidationErrorsFormat(errors, |
| 230 | &error)) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 231 | log_.Error(error); |
Jinho Bang | be463a2 | 2018-08-02 10:26:50 | [diff] [blame] | 232 | client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
| 233 | OnConnectionTerminated(); |
| 234 | return; |
| 235 | } |
| 236 | |
Jinho Bang | 092e716 | 2018-09-06 23:41:19 | [diff] [blame] | 237 | spec()->Retry(std::move(errors)); |
Jinho Bang | cac8d9a0 | 2018-08-23 19:47:22 | [diff] [blame] | 238 | display_handle_->Retry(); |
Jinho Bang | be463a2 | 2018-08-02 10:26:50 | [diff] [blame] | 239 | } |
| 240 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 241 | void PaymentRequest::UpdateWith(mojom::PaymentDetailsPtr details) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 242 | if (!IsInitialized()) { |
| 243 | log_.Error("Attempted updateWith without initialization"); |
| 244 | OnConnectionTerminated(); |
| 245 | return; |
| 246 | } |
| 247 | |
| 248 | if (!IsThisPaymentRequestShowing()) { |
| 249 | log_.Error("Attempted updateWith without show"); |
| 250 | OnConnectionTerminated(); |
| 251 | return; |
| 252 | } |
| 253 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 254 | std::string error; |
Mohamad Ahmadi | f5544bb | 2017-09-01 21:48:22 | [diff] [blame] | 255 | if (!ValidatePaymentDetails(ConvertPaymentDetails(details), &error)) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 256 | log_.Error(error); |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 257 | OnConnectionTerminated(); |
| 258 | return; |
| 259 | } |
Rouslan Solomakhin | 4cbda82 | 2017-08-23 18:50:39 | [diff] [blame] | 260 | |
Jinho Bang | 092e716 | 2018-09-06 23:41:19 | [diff] [blame] | 261 | if (details->shipping_address_errors && |
| 262 | !PaymentsValidators::IsValidAddressErrorsFormat( |
| 263 | details->shipping_address_errors, &error)) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 264 | log_.Error(error); |
Jinho Bang | 092e716 | 2018-09-06 23:41:19 | [diff] [blame] | 265 | OnConnectionTerminated(); |
| 266 | return; |
| 267 | } |
| 268 | |
Rouslan Solomakhin | 4cbda82 | 2017-08-23 18:50:39 | [diff] [blame] | 269 | if (!details->total) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 270 | log_.Error("Missing total"); |
Rouslan Solomakhin | 4cbda82 | 2017-08-23 18:50:39 | [diff] [blame] | 271 | OnConnectionTerminated(); |
| 272 | return; |
| 273 | } |
| 274 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 275 | spec_->UpdateWith(std::move(details)); |
| 276 | } |
| 277 | |
Rouslan Solomakhin | a9ff928 | 2017-10-31 21:58:05 | [diff] [blame] | 278 | void PaymentRequest::NoUpdatedPaymentDetails() { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 279 | // This Mojo call is triggered by the user of the API doing nothing in |
| 280 | // response to a shipping address update event, so the error messages cannot |
| 281 | // be more verbose. |
| 282 | if (!IsInitialized()) { |
| 283 | log_.Error("Not initialized"); |
| 284 | OnConnectionTerminated(); |
| 285 | return; |
| 286 | } |
| 287 | |
| 288 | if (!IsThisPaymentRequestShowing()) { |
| 289 | log_.Error("Not shown"); |
| 290 | OnConnectionTerminated(); |
| 291 | return; |
| 292 | } |
| 293 | |
Rouslan Solomakhin | a9ff928 | 2017-10-31 21:58:05 | [diff] [blame] | 294 | spec_->RecomputeSpecForDetails(); |
| 295 | } |
| 296 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 297 | void PaymentRequest::Abort() { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 298 | if (!IsInitialized()) { |
| 299 | log_.Error("Attempted abort without initialization"); |
| 300 | OnConnectionTerminated(); |
| 301 | return; |
| 302 | } |
| 303 | |
| 304 | if (!IsThisPaymentRequestShowing()) { |
| 305 | log_.Error("Attempted abort without show"); |
| 306 | OnConnectionTerminated(); |
| 307 | return; |
| 308 | } |
| 309 | |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 310 | // The API user has decided to abort. If a successful abort message is |
| 311 | // returned to the renderer, the Mojo message pipe is closed, which triggers |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 312 | // PaymentRequest::OnConnectionTerminated, which destroys this object. |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 313 | // Otherwise, the abort promise is rejected and the pipe is not closed. |
| 314 | // The abort is only successful if the payment app wasn't yet invoked. |
| 315 | // TODO(crbug.com/716546): Add a merchant abort metric |
| 316 | |
| 317 | bool accepting_abort = !state_->IsPaymentAppInvoked(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 318 | if (accepting_abort) |
| 319 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT); |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 320 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 321 | if (client_.is_bound()) |
Anthony Vallee-Dubois | 6813c144 | 2017-05-17 19:32:56 | [diff] [blame] | 322 | client_->OnAbort(accepting_abort); |
| 323 | |
| 324 | if (observer_for_testing_) |
| 325 | observer_for_testing_->OnAbortCalled(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 326 | } |
| 327 | |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 328 | void PaymentRequest::Complete(mojom::PaymentComplete result) { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 329 | if (!IsInitialized()) { |
| 330 | log_.Error("Attempted complete without initialization"); |
| 331 | OnConnectionTerminated(); |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 332 | return; |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | if (!IsThisPaymentRequestShowing()) { |
| 336 | log_.Error("Attempted complete without show"); |
| 337 | OnConnectionTerminated(); |
| 338 | return; |
| 339 | } |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 340 | |
Rouslan Solomakhin | e347319 | 2017-06-16 14:54:57 | [diff] [blame] | 341 | // Failed transactions show an error. Successful and unknown-state |
| 342 | // transactions don't show an error. |
| 343 | if (result == mojom::PaymentComplete::FAIL) { |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 344 | delegate_->ShowErrorMessage(); |
| 345 | } else { |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 346 | DCHECK(!has_recorded_completion_); |
sebsg | f8272a2 | 2017-05-26 14:32:58 | [diff] [blame] | 347 | journey_logger_.SetCompleted(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 348 | has_recorded_completion_ = true; |
| 349 | |
anthonyvd | 6a43b93 | 2017-05-11 18:39:27 | [diff] [blame] | 350 | delegate_->GetPrefService()->SetBoolean(kPaymentsFirstTransactionCompleted, |
| 351 | true); |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 352 | // When the renderer closes the connection, |
| 353 | // PaymentRequest::OnConnectionTerminated will be called. |
| 354 | client_->OnComplete(); |
sebsg | 8a93b27 | 2017-05-11 19:30:22 | [diff] [blame] | 355 | state_->RecordUseStats(); |
mathp | 21879589 | 2017-03-29 15:15:34 | [diff] [blame] | 356 | } |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | void PaymentRequest::CanMakePayment() { |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 360 | if (!IsInitialized()) { |
| 361 | log_.Error("Attempted canMakePayment without initialization"); |
| 362 | OnConnectionTerminated(); |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | // It's valid to call canMakePayment() without calling show() first. |
| 367 | |
gogerald | 8189d52 | 2017-09-15 17:52:18 | [diff] [blame] | 368 | if (observer_for_testing_) |
| 369 | observer_for_testing_->OnCanMakePaymentCalled(); |
Mathieu Perreault | cacb85e | 2018-06-06 20:40:13 | [diff] [blame] | 370 | |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 371 | if (!delegate_->GetPrefService()->GetBoolean(kCanMakePaymentEnabled) || |
| 372 | !state_) { |
Mathieu Perreault | cacb85e | 2018-06-06 20:40:13 | [diff] [blame] | 373 | CanMakePaymentCallback(/*can_make_payment=*/false); |
| 374 | } else { |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 375 | state_->CanMakePayment( |
Mathieu Perreault | cacb85e | 2018-06-06 20:40:13 | [diff] [blame] | 376 | base::BindOnce(&PaymentRequest::CanMakePaymentCallback, |
| 377 | weak_ptr_factory_.GetWeakPtr())); |
| 378 | } |
gogerald | 8189d52 | 2017-09-15 17:52:18 | [diff] [blame] | 379 | } |
| 380 | |
Danyao Wang | ce175bf | 2018-12-21 22:35:58 | [diff] [blame^] | 381 | void PaymentRequest::HasEnrolledInstrument() { |
| 382 | if (!IsInitialized()) { |
| 383 | log_.Error("Attempted hasEnrolledInstrument without initialization"); |
| 384 | OnConnectionTerminated(); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | // It's valid to call hasEnrolledInstrument() without calling show() first. |
| 389 | |
| 390 | if (observer_for_testing_) |
| 391 | observer_for_testing_->OnHasEnrolledInstrumentCalled(); |
| 392 | |
| 393 | if (!delegate_->GetPrefService()->GetBoolean(kCanMakePaymentEnabled) || |
| 394 | !state_) { |
| 395 | HasEnrolledInstrumentCallback(/*has_enrolled_instrument=*/false); |
| 396 | } else { |
| 397 | state_->HasEnrolledInstrument( |
| 398 | base::BindOnce(&PaymentRequest::HasEnrolledInstrumentCallback, |
| 399 | weak_ptr_factory_.GetWeakPtr())); |
| 400 | } |
| 401 | } |
| 402 | |
Rouslan Solomakhin | 2706470 | 2018-12-14 21:15:33 | [diff] [blame] | 403 | void PaymentRequest::AreRequestedMethodsSupportedCallback( |
| 404 | bool methods_supported) { |
| 405 | if (methods_supported) { |
| 406 | if (SatisfiesSkipUIConstraints()) { |
| 407 | skipped_payment_request_ui_ = true; |
| 408 | Pay(); |
| 409 | } |
| 410 | } else { |
| 411 | journey_logger_.SetNotShown( |
| 412 | JourneyLogger::NOT_SHOWN_REASON_NO_SUPPORTED_PAYMENT_METHOD); |
| 413 | client_->OnError(mojom::PaymentErrorReason::NOT_SUPPORTED); |
| 414 | if (observer_for_testing_) |
| 415 | observer_for_testing_->OnNotSupportedError(); |
| 416 | OnConnectionTerminated(); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | bool PaymentRequest::IsInitialized() const { |
| 421 | return is_initialized_ && client_ && client_.is_bound() && |
| 422 | binding_.is_bound(); |
| 423 | } |
| 424 | |
| 425 | bool PaymentRequest::IsThisPaymentRequestShowing() const { |
| 426 | return is_show_called_ && display_handle_ && spec_ && state_; |
| 427 | } |
| 428 | |
| 429 | bool PaymentRequest::SatisfiesSkipUIConstraints() const { |
| 430 | return base::FeatureList::IsEnabled(features::kWebPaymentsSingleAppUiSkip) && |
| 431 | base::FeatureList::IsEnabled(::features::kServiceWorkerPaymentApps) && |
| 432 | is_show_user_gesture_ && state()->is_get_all_instruments_finished() && |
| 433 | state()->available_instruments().size() == 1 && |
| 434 | spec()->stringified_method_data().size() == 1 && |
| 435 | !spec()->request_shipping() && !spec()->request_payer_name() && |
| 436 | !spec()->request_payer_phone() && |
| 437 | !spec()->request_payer_email() |
| 438 | // Only allowing URL base payment apps to skip the payment sheet. |
| 439 | && spec()->url_payment_method_identifiers().size() == 1; |
| 440 | } |
| 441 | |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 442 | void PaymentRequest::OnPaymentResponseAvailable( |
| 443 | mojom::PaymentResponsePtr response) { |
mathp | 57c8c86 | 2017-06-16 20:15:45 | [diff] [blame] | 444 | journey_logger_.SetEventOccurred( |
| 445 | JourneyLogger::EVENT_RECEIVED_INSTRUMENT_DETAILS); |
gogerald | 7a2b761e | 2017-11-09 18:30:19 | [diff] [blame] | 446 | |
| 447 | // Do not send invalid response to client. |
| 448 | if (response->method_name.empty() || response->stringified_details.empty()) { |
| 449 | RecordFirstAbortReason( |
| 450 | JourneyLogger::ABORT_REASON_INSTRUMENT_DETAILS_ERROR); |
| 451 | delegate_->ShowErrorMessage(); |
| 452 | return; |
| 453 | } |
| 454 | |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 455 | client_->OnPaymentResponse(std::move(response)); |
mathp | 4b85b58 | 2017-03-08 21:07:16 | [diff] [blame] | 456 | } |
| 457 | |
mathp | 151bd31 | 2017-04-03 21:07:24 | [diff] [blame] | 458 | void PaymentRequest::OnShippingOptionIdSelected( |
| 459 | std::string shipping_option_id) { |
| 460 | client_->OnShippingOptionChange(shipping_option_id); |
| 461 | } |
| 462 | |
| 463 | void PaymentRequest::OnShippingAddressSelected( |
| 464 | mojom::PaymentAddressPtr address) { |
| 465 | client_->OnShippingAddressChange(std::move(address)); |
| 466 | } |
| 467 | |
Jinho Bang | bb17815 | 2018-09-13 09:44:43 | [diff] [blame] | 468 | void PaymentRequest::OnPayerInfoSelected(mojom::PayerDetailPtr payer_info) { |
| 469 | client_->OnPayerDetailChange(std::move(payer_info)); |
| 470 | } |
| 471 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 472 | void PaymentRequest::UserCancelled() { |
| 473 | // If |client_| is not bound, then the object is already being destroyed as |
| 474 | // a result of a renderer event. |
| 475 | if (!client_.is_bound()) |
| 476 | return; |
| 477 | |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 478 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_ABORTED_BY_USER); |
sebsg | 20b49d7b | 2017-05-04 20:23:17 | [diff] [blame] | 479 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 480 | // This sends an error to the renderer, which informs the API user. |
rouslan | 6e3cf7c6 | 2017-04-17 21:23:28 | [diff] [blame] | 481 | client_->OnError(mojom::PaymentErrorReason::USER_CANCEL); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 482 | |
| 483 | // We close all bindings and ask to be destroyed. |
| 484 | client_.reset(); |
| 485 | binding_.Close(); |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 486 | if (observer_for_testing_) |
| 487 | observer_for_testing_->OnConnectionTerminated(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 488 | manager_->DestroyRequest(this); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 489 | } |
| 490 | |
sebsg | d56b3e42 | 2017-10-20 18:08:08 | [diff] [blame] | 491 | void PaymentRequest::DidStartMainFrameNavigationToDifferentDocument( |
| 492 | bool is_user_initiated) { |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 493 | RecordFirstAbortReason(is_user_initiated |
| 494 | ? JourneyLogger::ABORT_REASON_USER_NAVIGATION |
| 495 | : JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION); |
sebsg | 2c8558a | 2017-05-17 18:54:10 | [diff] [blame] | 496 | } |
| 497 | |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 498 | void PaymentRequest::OnConnectionTerminated() { |
| 499 | // We are here because of a browser-side error, or likely as a result of the |
| 500 | // connection_error_handler on |binding_|, which can mean that the renderer |
| 501 | // has decided to close the pipe for various reasons (see all uses of |
| 502 | // PaymentRequest::clearResolversAndCloseMojoConnection() in Blink). We close |
| 503 | // the binding and the dialog, and ask to be deleted. |
| 504 | client_.reset(); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 505 | binding_.Close(); |
mathp | f4bc50e | 2017-01-24 05:17:50 | [diff] [blame] | 506 | delegate_->CloseDialog(); |
rouslan | b28f453 | 2017-05-08 15:41:47 | [diff] [blame] | 507 | if (observer_for_testing_) |
| 508 | observer_for_testing_->OnConnectionTerminated(); |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 509 | |
| 510 | RecordFirstAbortReason(JourneyLogger::ABORT_REASON_MOJO_CONNECTION_ERROR); |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 511 | manager_->DestroyRequest(this); |
| 512 | } |
| 513 | |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 514 | void PaymentRequest::Pay() { |
mathp | 57c8c86 | 2017-06-16 20:15:45 | [diff] [blame] | 515 | journey_logger_.SetEventOccurred(JourneyLogger::EVENT_PAY_CLICKED); |
Mathieu Perreault | 23d25bfb8 | 2018-05-11 14:45:37 | [diff] [blame] | 516 | |
| 517 | // Log the correct "selected instrument" metric according to type. |
| 518 | DCHECK(state_->selected_instrument()); |
| 519 | JourneyLogger::Event selected_event = |
| 520 | JourneyLogger::Event::EVENT_SELECTED_OTHER; |
| 521 | switch (state_->selected_instrument()->type()) { |
| 522 | case PaymentInstrument::Type::AUTOFILL: |
| 523 | selected_event = JourneyLogger::Event::EVENT_SELECTED_CREDIT_CARD; |
| 524 | break; |
| 525 | case PaymentInstrument::Type::SERVICE_WORKER_APP: |
| 526 | selected_event = JourneyLogger::Event::EVENT_SELECTED_OTHER; |
| 527 | break; |
| 528 | case PaymentInstrument::Type::NATIVE_MOBILE_APP: |
| 529 | NOTREACHED(); |
| 530 | break; |
| 531 | } |
| 532 | journey_logger_.SetEventOccurred(selected_event); |
| 533 | |
mathp | f1a7a375 | 2017-03-15 11:23:37 | [diff] [blame] | 534 | state_->GeneratePaymentResponse(); |
mathp | d4be8de8 | 2017-03-01 00:51:48 | [diff] [blame] | 535 | } |
| 536 | |
Anthony Vallee-Dubois | c7ae733 | 2017-12-19 20:44:07 | [diff] [blame] | 537 | void PaymentRequest::HideIfNecessary() { |
| 538 | display_handle_.reset(); |
| 539 | } |
| 540 | |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 541 | void PaymentRequest::RecordDialogShownEventInJourneyLogger() { |
| 542 | journey_logger_.SetEventOccurred(JourneyLogger::EVENT_SHOWN); |
| 543 | } |
| 544 | |
Anthony Vallee-Dubois | 10d131a | 2018-02-22 15:41:04 | [diff] [blame] | 545 | bool PaymentRequest::IsIncognito() const { |
| 546 | return delegate_->IsIncognito(); |
| 547 | } |
| 548 | |
sebsg | fcdd13c | 2017-06-08 15:49:33 | [diff] [blame] | 549 | void PaymentRequest::RecordFirstAbortReason( |
| 550 | JourneyLogger::AbortReason abort_reason) { |
| 551 | if (!has_recorded_completion_) { |
| 552 | has_recorded_completion_ = true; |
| 553 | journey_logger_.SetAborted(abort_reason); |
sebsg | 2c8558a | 2017-05-17 18:54:10 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 557 | void PaymentRequest::CanMakePaymentCallback(bool can_make_payment) { |
Rouslan Solomakhin | d2cae95a | 2018-08-09 00:16:10 | [diff] [blame] | 558 | if (!spec_ || CanMakePaymentQueryFactory::GetInstance() |
| 559 | ->GetForContext(web_contents_->GetBrowserContext()) |
| 560 | ->CanQuery(top_level_origin_, frame_origin_, |
| 561 | spec_->stringified_method_data())) { |
Rouslan Solomakhin | 16ee5520 | 2017-10-03 19:04:42 | [diff] [blame] | 562 | RespondToCanMakePaymentQuery(can_make_payment, false); |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 563 | } else if (OriginSecurityChecker::IsOriginLocalhostOrFile(frame_origin_)) { |
Rouslan Solomakhin | 16ee5520 | 2017-10-03 19:04:42 | [diff] [blame] | 564 | RespondToCanMakePaymentQuery(can_make_payment, true); |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 565 | } else { |
| 566 | client_->OnCanMakePayment( |
| 567 | mojom::CanMakePaymentQueryResult::QUERY_QUOTA_EXCEEDED); |
| 568 | } |
| 569 | |
| 570 | if (observer_for_testing_) |
| 571 | observer_for_testing_->OnCanMakePaymentReturned(); |
| 572 | } |
| 573 | |
Danyao Wang | ce175bf | 2018-12-21 22:35:58 | [diff] [blame^] | 574 | void PaymentRequest::HasEnrolledInstrumentCallback( |
| 575 | bool has_enrolled_instrument) { |
| 576 | if (!spec_ || CanMakePaymentQueryFactory::GetInstance() |
| 577 | ->GetForContext(web_contents_->GetBrowserContext()) |
| 578 | ->CanQuery(top_level_origin_, frame_origin_, |
| 579 | spec_->stringified_method_data())) { |
| 580 | RespondToHasEnrolledInstrumentQuery(has_enrolled_instrument, |
| 581 | /*warn_localhost_or_file=*/false); |
| 582 | } else if (OriginSecurityChecker::IsOriginLocalhostOrFile(frame_origin_)) { |
| 583 | RespondToHasEnrolledInstrumentQuery(has_enrolled_instrument, |
| 584 | /*warn_localhost_or_file=*/true); |
| 585 | } else { |
| 586 | client_->OnHasEnrolledInstrument( |
| 587 | HasEnrolledInstrumentQueryResult::QUERY_QUOTA_EXCEEDED); |
| 588 | } |
| 589 | |
| 590 | if (observer_for_testing_) |
| 591 | observer_for_testing_->OnHasEnrolledInstrumentReturned(); |
| 592 | } |
| 593 | |
Rouslan Solomakhin | 16ee5520 | 2017-10-03 19:04:42 | [diff] [blame] | 594 | void PaymentRequest::RespondToCanMakePaymentQuery(bool can_make_payment, |
| 595 | bool warn_localhost_or_file) { |
Rouslan Solomakhin | 16ee5520 | 2017-10-03 19:04:42 | [diff] [blame] | 596 | mojom::CanMakePaymentQueryResult positive = |
| 597 | warn_localhost_or_file |
| 598 | ? mojom::CanMakePaymentQueryResult::WARNING_CAN_MAKE_PAYMENT |
| 599 | : mojom::CanMakePaymentQueryResult::CAN_MAKE_PAYMENT; |
| 600 | mojom::CanMakePaymentQueryResult negative = |
| 601 | warn_localhost_or_file |
| 602 | ? mojom::CanMakePaymentQueryResult::WARNING_CANNOT_MAKE_PAYMENT |
| 603 | : mojom::CanMakePaymentQueryResult::CANNOT_MAKE_PAYMENT; |
| 604 | |
| 605 | client_->OnCanMakePayment(can_make_payment ? positive : negative); |
Rouslan Solomakhin | 1804ee4 | 2017-10-03 14:27:43 | [diff] [blame] | 606 | journey_logger_.SetCanMakePaymentValue(can_make_payment); |
| 607 | } |
| 608 | |
Danyao Wang | ce175bf | 2018-12-21 22:35:58 | [diff] [blame^] | 609 | void PaymentRequest::RespondToHasEnrolledInstrumentQuery( |
| 610 | bool has_enrolled_instrument, |
| 611 | bool warn_localhost_or_file) { |
| 612 | HasEnrolledInstrumentQueryResult positive = |
| 613 | warn_localhost_or_file |
| 614 | ? HasEnrolledInstrumentQueryResult::WARNING_HAS_ENROLLED_INSTRUMENT |
| 615 | : HasEnrolledInstrumentQueryResult::HAS_ENROLLED_INSTRUMENT; |
| 616 | HasEnrolledInstrumentQueryResult negative = |
| 617 | warn_localhost_or_file |
| 618 | ? HasEnrolledInstrumentQueryResult::WARNING_HAS_NO_ENROLLED_INSTRUMENT |
| 619 | : HasEnrolledInstrumentQueryResult::HAS_NO_ENROLLED_INSTRUMENT; |
| 620 | |
| 621 | client_->OnHasEnrolledInstrument(has_enrolled_instrument ? positive |
| 622 | : negative); |
| 623 | journey_logger_.SetCanMakePaymentValue(has_enrolled_instrument); |
| 624 | } |
| 625 | |
mathp | f709499d | 2017-01-09 20:48:36 | [diff] [blame] | 626 | } // namespace payments |