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

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

Issue 2779453002: [Payments] Return the preferred payment method name to the merchant (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 2016 The Chromium Authors. All rights reserved. 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 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_request_state.h" 5 #include "components/payments/content/payment_request_state.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "components/autofill/core/browser/autofill_data_util.h" 9 #include "components/autofill/core/browser/autofill_data_util.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/personal_data_manager.h" 12 #include "components/autofill/core/browser/personal_data_manager.h"
13 #include "components/payments/content/payment_request_spec.h" 13 #include "components/payments/content/payment_request_spec.h"
14 #include "components/payments/core/autofill_payment_instrument.h" 14 #include "components/payments/core/autofill_payment_instrument.h"
15 15
16 namespace payments { 16 namespace payments {
17 17
18 const char kBasicCardMethodName[] = "basic-card";
19
18 PaymentRequestState::PaymentRequestState( 20 PaymentRequestState::PaymentRequestState(
19 PaymentRequestSpec* spec, 21 PaymentRequestSpec* spec,
20 Delegate* delegate, 22 Delegate* delegate,
21 const std::string& app_locale, 23 const std::string& app_locale,
22 autofill::PersonalDataManager* personal_data_manager) 24 autofill::PersonalDataManager* personal_data_manager)
23 : is_ready_to_pay_(false), 25 : is_ready_to_pay_(false),
24 app_locale_(app_locale), 26 app_locale_(app_locale),
25 spec_(spec), 27 spec_(spec),
26 delegate_(delegate), 28 delegate_(delegate),
27 personal_data_manager_(personal_data_manager), 29 personal_data_manager_(personal_data_manager),
(...skipping 28 matching lines...) Expand all
56 void PaymentRequestState::RemoveObserver(Observer* observer) { 58 void PaymentRequestState::RemoveObserver(Observer* observer) {
57 observers_.RemoveObserver(observer); 59 observers_.RemoveObserver(observer);
58 } 60 }
59 61
60 void PaymentRequestState::OnInstrumentDetailsReady( 62 void PaymentRequestState::OnInstrumentDetailsReady(
61 const std::string& method_name, 63 const std::string& method_name,
62 const std::string& stringified_details) { 64 const std::string& stringified_details) {
63 // TODO(mathp): Fill other fields in the PaymentResponsePtr object. 65 // TODO(mathp): Fill other fields in the PaymentResponsePtr object.
64 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New(); 66 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New();
65 67
66 payment_response->method_name = method_name; 68 // Make sure that we return the method name that the merchant specified for
69 // this instrument: cards can be either specified through their name (e.g.,
70 // "visa") or through basic-card's supportedNetworks.
71 payment_response->method_name =
72 spec_->IsMethodSupportedThroughBasicCard(method_name)
73 ? kBasicCardMethodName
74 : method_name;
67 payment_response->stringified_details = stringified_details; 75 payment_response->stringified_details = stringified_details;
68 delegate_->OnPaymentResponseAvailable(std::move(payment_response)); 76 delegate_->OnPaymentResponseAvailable(std::move(payment_response));
69 } 77 }
70 78
71 void PaymentRequestState::GeneratePaymentResponse() { 79 void PaymentRequestState::GeneratePaymentResponse() {
72 DCHECK(is_ready_to_pay()); 80 DCHECK(is_ready_to_pay());
73 // Fetch the instrument details, will call back into 81 // Fetch the instrument details, will call back into
74 // PaymentRequest::OnInstrumentsDetailsReady. 82 // PaymentRequest::OnInstrumentsDetailsReady.
75 selected_instrument_->InvokePaymentApp(this); 83 selected_instrument_->InvokePaymentApp(this);
76 } 84 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 spec_->details().shipping_options.rend(), 241 spec_->details().shipping_options.rend(),
234 [](const payments::mojom::PaymentShippingOptionPtr& element) { 242 [](const payments::mojom::PaymentShippingOptionPtr& element) {
235 return element->selected; 243 return element->selected;
236 }); 244 });
237 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) { 245 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) {
238 selected_shipping_option_ = selected_shipping_option_it->get(); 246 selected_shipping_option_ = selected_shipping_option_it->get();
239 } 247 }
240 } 248 }
241 249
242 } // namespace payments 250 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698