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

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

Issue 2780773004: Reland "PaymentRequest: Introduce PaymentDetailsInit and PaymentDetailsUpdate." (Closed)
Patch Set: Reland "PaymentRequest: Introduce PaymentDetailsInit and PaymentDetailsUpdate." 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_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
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 (item->amount->currency != total->amount->currency) { 43 if (total && 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
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.is_null()) { 145 if (details->total) {
146 *error_message = "Must specify total"; 146 if (!validateShippingOptionOrPaymentItem(details->total, details->total,
147 return false; 147 error_message))
148 } 148 return false;
149 149
150 if (!validateShippingOptionOrPaymentItem(details->total, details->total, 150 if (details->total->amount->value[0] == '-') {
151 error_message)) 151 *error_message = "Total amount value should be non-negative";
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;
157 } 154 }
158 155
159 if (details->display_items.size()) { 156 if (details->display_items.size()) {
160 if (!validateDisplayItems(details->display_items, details->total, 157 if (!validateDisplayItems(details->display_items, details->total,
161 error_message)) 158 error_message))
162 return false; 159 return false;
163 } 160 }
164 161
165 if (details->shipping_options.size()) { 162 if (details->shipping_options.size()) {
166 if (!validateShippingOptions(details->shipping_options, details->total, 163 if (!validateShippingOptions(details->shipping_options, details->total,
167 error_message)) 164 error_message))
168 return false; 165 return false;
169 } 166 }
170 167
171 if (details->modifiers.size()) { 168 if (details->modifiers.size()) {
172 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, 169 if (!validatePaymentDetailsModifiers(details->modifiers, details->total,
173 error_message)) 170 error_message))
174 return false; 171 return false;
175 } 172 }
176 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) 173 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message))
177 return false; 174 return false;
178 return true; 175 return true;
179 } 176 }
180 177
181 } // namespace payments 178 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698