OLD | NEW |
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_details_validation.h" | 5 #include "components/payments/content/payment_details_validation.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "components/payments/content/payment_request.mojom.h" | 10 #include "components/payments/content/payment_request.mojom.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 if (item->amount->currency.empty()) { | 33 if (item->amount->currency.empty()) { |
34 *error_message = "Currency code required"; | 34 *error_message = "Currency code required"; |
35 return false; | 35 return false; |
36 } | 36 } |
37 | 37 |
38 if (item->amount->value.empty()) { | 38 if (item->amount->value.empty()) { |
39 *error_message = "Currency value required"; | 39 *error_message = "Currency value required"; |
40 return false; | 40 return false; |
41 } | 41 } |
42 | 42 |
43 if (total && item->amount->currency != total->amount->currency) { | 43 if (item->amount->currency != total->amount->currency) { |
44 *error_message = "Currencies must all be equal"; | 44 *error_message = "Currencies must all be equal"; |
45 return false; | 45 return false; |
46 } | 46 } |
47 | 47 |
48 if (item->amount->currency_system.empty()) { | 48 if (item->amount->currency_system.empty()) { |
49 *error_message = "Currency system can't be empty"; | 49 *error_message = "Currency system can't be empty"; |
50 return false; | 50 return false; |
51 } | 51 } |
52 | 52 |
53 if (!payments::PaymentsValidators::isValidCurrencyCodeFormat( | 53 if (!payments::PaymentsValidators::isValidCurrencyCodeFormat( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 } // namespace | 141 } // namespace |
142 | 142 |
143 bool validatePaymentDetails(const mojom::PaymentDetailsPtr& details, | 143 bool validatePaymentDetails(const mojom::PaymentDetailsPtr& details, |
144 std::string* error_message) { | 144 std::string* error_message) { |
145 if (details->total) { | 145 if (details->total.is_null()) { |
146 if (!validateShippingOptionOrPaymentItem(details->total, details->total, | 146 *error_message = "Must specify total"; |
147 error_message)) | 147 return false; |
148 return false; | 148 } |
149 | 149 |
150 if (details->total->amount->value[0] == '-') { | 150 if (!validateShippingOptionOrPaymentItem(details->total, details->total, |
151 *error_message = "Total amount value should be non-negative"; | 151 error_message)) |
152 return false; | 152 return false; |
153 } | 153 |
| 154 if (details->total->amount->value[0] == '-') { |
| 155 *error_message = "Total amount value should be non-negative"; |
| 156 return false; |
154 } | 157 } |
155 | 158 |
156 if (details->display_items.size()) { | 159 if (details->display_items.size()) { |
157 if (!validateDisplayItems(details->display_items, details->total, | 160 if (!validateDisplayItems(details->display_items, details->total, |
158 error_message)) | 161 error_message)) |
159 return false; | 162 return false; |
160 } | 163 } |
161 | 164 |
162 if (details->shipping_options.size()) { | 165 if (details->shipping_options.size()) { |
163 if (!validateShippingOptions(details->shipping_options, details->total, | 166 if (!validateShippingOptions(details->shipping_options, details->total, |
164 error_message)) | 167 error_message)) |
165 return false; | 168 return false; |
166 } | 169 } |
167 | 170 |
168 if (details->modifiers.size()) { | 171 if (details->modifiers.size()) { |
169 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, | 172 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, |
170 error_message)) | 173 error_message)) |
171 return false; | 174 return false; |
172 } | 175 } |
173 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) | 176 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) |
174 return false; | 177 return false; |
175 return true; | 178 return true; |
176 } | 179 } |
177 | 180 |
178 } // namespace payments | 181 } // namespace payments |
OLD | NEW |