OLD | NEW |
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/credit_card_editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 autofill::AutofillType(field.second.type).group()); | 197 autofill::AutofillType(field.second.type).group()); |
198 ValidatingCombobox* combobox = field.first; | 198 ValidatingCombobox* combobox = field.first; |
199 if (combobox->invalid()) | 199 if (combobox->invalid()) |
200 return false; | 200 return false; |
201 | 201 |
202 credit_card.SetInfo(autofill::AutofillType(field.second.type), | 202 credit_card.SetInfo(autofill::AutofillType(field.second.type), |
203 combobox->GetTextForRow(combobox->selected_index()), | 203 combobox->GetTextForRow(combobox->selected_index()), |
204 locale); | 204 locale); |
205 } | 205 } |
206 | 206 |
207 // TODO(mathp): Display global error message. | 207 // TODO(crbug.com/711365): Display global error message. |
208 if (!credit_card.IsValid()) | 208 if (autofill::GetCompletionStatusForCard(credit_card, locale) != |
| 209 autofill::CREDIT_CARD_COMPLETE) { |
209 return false; | 210 return false; |
| 211 } |
210 | 212 |
211 if (!credit_card_to_edit_) { | 213 if (!credit_card_to_edit_) { |
212 // Add the card (will not add a duplicate). | 214 // Add the card (will not add a duplicate). |
213 state()->GetPersonalDataManager()->AddCreditCard(credit_card); | 215 state()->GetPersonalDataManager()->AddCreditCard(credit_card); |
214 std::move(on_added_).Run(credit_card); | 216 std::move(on_added_).Run(credit_card); |
215 } else { | 217 } else { |
216 // We were in edit mode. Copy the data from the temporary object to retain | 218 // We were in edit mode. Copy the data from the temporary object to retain |
217 // the edited object's other properties (use count, use date, guid, etc.). | 219 // the edited object's other properties (use count, use date, guid, etc.). |
218 for (const auto& field : text_fields()) { | 220 for (const auto& field : text_fields()) { |
219 credit_card_to_edit_->SetInfo( | 221 credit_card_to_edit_->SetInfo( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 bool is_required_valid = !field_.required; | 315 bool is_required_valid = !field_.required; |
314 const base::string16 displayed_message = | 316 const base::string16 displayed_message = |
315 is_required_valid ? base::ASCIIToUTF16("") | 317 is_required_valid ? base::ASCIIToUTF16("") |
316 : l10n_util::GetStringUTF16( | 318 : l10n_util::GetStringUTF16( |
317 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 319 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
318 controller_->DisplayErrorMessageForField(field_, displayed_message); | 320 controller_->DisplayErrorMessageForField(field_, displayed_message); |
319 return is_required_valid; | 321 return is_required_valid; |
320 } | 322 } |
321 | 323 |
322 } // namespace payments | 324 } // namespace payments |
OLD | NEW |