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

Side by Side Diff: chrome/browser/ui/views/payments/payment_method_view_controller.cc

Issue 2849523003: Add billing address as a mandatory field of Payments credit cards. (Closed)
Patch Set: Components Unittests fix Created 3 years, 7 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 "chrome/browser/ui/views/payments/payment_method_view_controller.h" 5 #include "chrome/browser/ui/views/payments/payment_method_view_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 26 matching lines...) Expand all
37 37
38 namespace { 38 namespace {
39 39
40 constexpr int kFirstTagValue = static_cast<int>( 40 constexpr int kFirstTagValue = static_cast<int>(
41 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX); 41 payments::PaymentRequestCommonTags::PAYMENT_REQUEST_COMMON_TAG_MAX);
42 42
43 enum class PaymentMethodViewControllerTags : int { 43 enum class PaymentMethodViewControllerTags : int {
44 // The tag for the button that triggers the "add card" flow. Starts at 44 // The tag for the button that triggers the "add card" flow. Starts at
45 // |kFirstTagValue| not to conflict with tags common to all views. 45 // |kFirstTagValue| not to conflict with tags common to all views.
46 ADD_CREDIT_CARD_BUTTON = kFirstTagValue, 46 ADD_CREDIT_CARD_BUTTON = kFirstTagValue,
47 // This value is passed to inner views so they can use it as a starting tag.
48 MAX_TAG,
47 }; 49 };
48 50
49 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item { 51 class PaymentMethodListItem : public payments::PaymentRequestItemList::Item {
50 public: 52 public:
51 // Does not take ownership of |instrument|, which should not be null and 53 // Does not take ownership of |instrument|, which should not be null and
52 // should outlive this object. |list| is the PaymentRequestItemList object 54 // should outlive this object. |list| is the PaymentRequestItemList object
53 // that will own this. 55 // that will own this.
54 PaymentMethodListItem(PaymentInstrument* instrument, 56 PaymentMethodListItem(PaymentInstrument* instrument,
55 PaymentRequestSpec* spec, 57 PaymentRequestSpec* spec,
56 PaymentRequestState* state, 58 PaymentRequestState* state,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // If an instrument can't be selected, PerformSelectionFallback is called, 116 // If an instrument can't be selected, PerformSelectionFallback is called,
115 // where the instrument can be made complete. 117 // where the instrument can be made complete.
116 return instrument_->IsCompleteForPayment(); 118 return instrument_->IsCompleteForPayment();
117 } 119 }
118 120
119 void PerformSelectionFallback() override { 121 void PerformSelectionFallback() override {
120 switch (instrument_->type()) { 122 switch (instrument_->type()) {
121 case PaymentInstrument::Type::AUTOFILL: 123 case PaymentInstrument::Type::AUTOFILL:
122 // Since we are a list item, we only care about the on_edited callback. 124 // Since we are a list item, we only care about the on_edited callback.
123 dialog_->ShowCreditCardEditor( 125 dialog_->ShowCreditCardEditor(
124 /*on_edited=*/base::BindOnce( 126 BackNavigationType::kPaymentSheet,
125 &PaymentRequestState::SetSelectedInstrument, 127 static_cast<int>(PaymentMethodViewControllerTags::MAX_TAG),
126 base::Unretained(state()), instrument_), 128 /*on_edited=*/
129 base::BindOnce(&PaymentRequestState::SetSelectedInstrument,
130 base::Unretained(state()), instrument_),
127 /*on_added=*/ 131 /*on_added=*/
128 base::OnceCallback<void(const autofill::CreditCard&)>(), 132 base::OnceCallback<void(const autofill::CreditCard&)>(),
129 static_cast<AutofillPaymentInstrument*>(instrument_) 133 static_cast<AutofillPaymentInstrument*>(instrument_)
130 ->credit_card()); 134 ->credit_card());
131 return; 135 return;
132 } 136 }
133 NOTREACHED(); 137 NOTREACHED();
134 } 138 }
135 139
136 PaymentInstrument* instrument_; 140 PaymentInstrument* instrument_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return extra_view; 196 return extra_view;
193 } 197 }
194 198
195 void PaymentMethodViewController::ButtonPressed(views::Button* sender, 199 void PaymentMethodViewController::ButtonPressed(views::Button* sender,
196 const ui::Event& event) { 200 const ui::Event& event) {
197 switch (sender->tag()) { 201 switch (sender->tag()) {
198 case static_cast<int>( 202 case static_cast<int>(
199 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON): 203 PaymentMethodViewControllerTags::ADD_CREDIT_CARD_BUTTON):
200 // Only provide the |on_added| callback, in response to this button. 204 // Only provide the |on_added| callback, in response to this button.
201 dialog()->ShowCreditCardEditor( 205 dialog()->ShowCreditCardEditor(
206 BackNavigationType::kPaymentSheet,
207 static_cast<int>(PaymentMethodViewControllerTags::MAX_TAG),
202 /*on_edited=*/base::OnceClosure(), 208 /*on_edited=*/base::OnceClosure(),
203 /*on_added=*/ 209 /*on_added=*/
204 base::BindOnce(&PaymentRequestState::AddAutofillPaymentInstrument, 210 base::BindOnce(&PaymentRequestState::AddAutofillPaymentInstrument,
205 base::Unretained(state()), /*selected=*/true), 211 base::Unretained(state()), /*selected=*/true),
206 /*credit_card=*/nullptr); 212 /*credit_card=*/nullptr);
207 break; 213 break;
208 default: 214 default:
209 PaymentRequestSheetController::ButtonPressed(sender, event); 215 PaymentRequestSheetController::ButtonPressed(sender, event);
210 break; 216 break;
211 } 217 }
212 } 218 }
213 219
214 } // namespace payments 220 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698