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

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

Issue 2779813003: [Payments] Add Ship. Addr. & Contact Info in Payment Response on Desktop. (Closed)
Patch Set: Addressed comments 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 "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_data_util.h" 10 #include "components/autofill/core/browser/autofill_data_util.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/personal_data_manager.h" 13 #include "components/autofill/core/browser/personal_data_manager.h"
13 #include "components/payments/content/payment_request_spec.h" 14 #include "components/payments/content/payment_request_spec.h"
15 #include "components/payments/content/payment_response_helper.h"
14 #include "components/payments/core/autofill_payment_instrument.h" 16 #include "components/payments/core/autofill_payment_instrument.h"
15 17
16 namespace payments { 18 namespace payments {
17 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),
(...skipping 25 matching lines...) Expand all
49 void PaymentRequestState::AddObserver(Observer* observer) { 51 void PaymentRequestState::AddObserver(Observer* observer) {
50 CHECK(observer); 52 CHECK(observer);
51 observers_.AddObserver(observer); 53 observers_.AddObserver(observer);
52 } 54 }
53 PaymentRequestState::~PaymentRequestState() {} 55 PaymentRequestState::~PaymentRequestState() {}
54 56
55 void PaymentRequestState::RemoveObserver(Observer* observer) { 57 void PaymentRequestState::RemoveObserver(Observer* observer) {
56 observers_.RemoveObserver(observer); 58 observers_.RemoveObserver(observer);
57 } 59 }
58 60
61 // TODO(sebsg): Move this to the PaymentResponseHelper.
59 void PaymentRequestState::OnInstrumentDetailsReady( 62 void PaymentRequestState::OnInstrumentDetailsReady(
60 const std::string& method_name, 63 const std::string& method_name,
61 const std::string& stringified_details) { 64 const std::string& stringified_details) {
62 // TODO(mathp): Fill other fields in the PaymentResponsePtr object.
63 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New(); 65 mojom::PaymentResponsePtr payment_response = mojom::PaymentResponse::New();
64 66
65 // Make sure that we return the method name that the merchant specified for 67 // Make sure that we return the method name that the merchant specified for
66 // this instrument: cards can be either specified through their name (e.g., 68 // this instrument: cards can be either specified through their name (e.g.,
67 // "visa") or through basic-card's supportedNetworks. 69 // "visa") or through basic-card's supportedNetworks.
68 payment_response->method_name = 70 payment_response->method_name =
69 spec_->IsMethodSupportedThroughBasicCard(method_name) 71 spec_->IsMethodSupportedThroughBasicCard(method_name)
70 ? kBasicCardMethodName 72 ? kBasicCardMethodName
71 : method_name; 73 : method_name;
72 payment_response->stringified_details = stringified_details; 74 payment_response->stringified_details = stringified_details;
75
76 // Shipping Address section
77 if (spec_->request_shipping()) {
78 DCHECK(selected_shipping_profile_);
79 payment_response->shipping_address =
80 PaymentResponseHelper::GetMojomPaymentAddressFromAutofillProfile(
81 selected_shipping_profile_, app_locale_);
82
83 DCHECK(selected_shipping_option_);
84 payment_response->shipping_option = selected_shipping_option_->id;
85 }
86
87 // Contact Details section.
88 if (spec_->request_payer_name()) {
89 DCHECK(selected_contact_profile_);
90 payment_response->payer_name =
91 base::UTF16ToUTF8(selected_contact_profile_->GetInfo(
92 autofill::AutofillType(autofill::NAME_FULL), app_locale_));
93 }
94 if (spec_->request_payer_email()) {
95 DCHECK(selected_contact_profile_);
96 payment_response->payer_email = base::UTF16ToUTF8(
97 selected_contact_profile_->GetRawInfo(autofill::EMAIL_ADDRESS));
98 }
99 if (spec_->request_payer_phone()) {
100 DCHECK(selected_contact_profile_);
101 // TODO(crbug.com/705945): Format phone number according to spec.
102 payment_response->payer_phone =
103 base::UTF16ToUTF8(selected_contact_profile_->GetRawInfo(
104 autofill::PHONE_HOME_WHOLE_NUMBER));
105 }
106
73 delegate_->OnPaymentResponseAvailable(std::move(payment_response)); 107 delegate_->OnPaymentResponseAvailable(std::move(payment_response));
74 } 108 }
75 109
76 void PaymentRequestState::GeneratePaymentResponse() { 110 void PaymentRequestState::GeneratePaymentResponse() {
77 DCHECK(is_ready_to_pay()); 111 DCHECK(is_ready_to_pay());
78 // Fetch the instrument details, will call back into 112 // Fetch the instrument details, will call back into
79 // PaymentRequest::OnInstrumentsDetailsReady. 113 // PaymentRequest::OnInstrumentDetailsReady.
80 selected_instrument_->InvokePaymentApp(this); 114 selected_instrument_->InvokePaymentApp(this);
81 } 115 }
82 116
83 void PaymentRequestState::SetSelectedShippingOption( 117 void PaymentRequestState::SetSelectedShippingOption(
84 mojom::PaymentShippingOption* option) { 118 mojom::PaymentShippingOption* option) {
85 selected_shipping_option_ = option; 119 selected_shipping_option_ = option;
86 UpdateIsReadyToPayAndNotifyObservers(); 120 UpdateIsReadyToPayAndNotifyObservers();
87 } 121 }
88 122
89 void PaymentRequestState::SetSelectedShippingProfile( 123 void PaymentRequestState::SetSelectedShippingProfile(
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 spec_->details().shipping_options.rend(), 272 spec_->details().shipping_options.rend(),
239 [](const payments::mojom::PaymentShippingOptionPtr& element) { 273 [](const payments::mojom::PaymentShippingOptionPtr& element) {
240 return element->selected; 274 return element->selected;
241 }); 275 });
242 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) { 276 if (selected_shipping_option_it != spec_->details().shipping_options.rend()) {
243 selected_shipping_option_ = selected_shipping_option_it->get(); 277 selected_shipping_option_ = selected_shipping_option_it->get();
244 } 278 }
245 } 279 }
246 280
247 } // namespace payments 281 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/content/BUILD.gn ('k') | components/payments/content/payment_request_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698