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

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

Issue 2489943003: Revert of [Web Payments] Mojom namespace blink -> payments (Closed)
Patch Set: Created 4 years, 1 month 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/payment_details_validation.h" 5 #include "components/payments/payment_details_validation.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "components/payments/payment_request.mojom.h" 10 #include "components/payments/payment_request.mojom.h"
11 #include "components/payments/payments_validators.h" 11 #include "components/payments/payments_validators.h"
12 12
13 namespace { 13 namespace {
14 14
15 // Validates ShippingOption or PaymentItem, which happen to have identical 15 // Validates ShippingOption or PaymentItem, which happen to have identical
16 // fields, except for "id", which is present only in ShippingOption. 16 // fields, except for "id", which is present only in ShippingOption.
17 template <typename T> 17 template <typename T>
18 bool validateShippingOptionOrPaymentItem( 18 bool validateShippingOptionOrPaymentItem(
19 const T& item, 19 const T& item,
20 const payments::mojom::PaymentItemPtr& total, 20 const blink::mojom::PaymentItemPtr& total,
21 std::string* error_message) { 21 std::string* error_message) {
22 if (item->label.empty()) { 22 if (item->label.empty()) {
23 *error_message = "Item label required"; 23 *error_message = "Item label required";
24 return false; 24 return false;
25 } 25 }
26 26
27 if (!item->amount) { 27 if (!item->amount) {
28 *error_message = "Currency amount required"; 28 *error_message = "Currency amount required";
29 return false; 29 return false;
30 } 30 }
(...skipping 28 matching lines...) Expand all
59 } 59 }
60 60
61 if (!payments::PaymentsValidators::isValidAmountFormat(item->amount->value, 61 if (!payments::PaymentsValidators::isValidAmountFormat(item->amount->value,
62 error_message)) { 62 error_message)) {
63 return false; 63 return false;
64 } 64 }
65 return true; 65 return true;
66 } 66 }
67 67
68 bool validateDisplayItems( 68 bool validateDisplayItems(
69 const std::vector<payments::mojom::PaymentItemPtr>& items, 69 const std::vector<blink::mojom::PaymentItemPtr>& items,
70 const payments::mojom::PaymentItemPtr& total, 70 const blink::mojom::PaymentItemPtr& total,
71 std::string* error_message) { 71 std::string* error_message) {
72 for (const auto& item : items) { 72 for (const auto& item : items) {
73 if (!validateShippingOptionOrPaymentItem(item, total, error_message)) 73 if (!validateShippingOptionOrPaymentItem(item, total, error_message))
74 return false; 74 return false;
75 } 75 }
76 return true; 76 return true;
77 } 77 }
78 78
79 bool validateShippingOptions( 79 bool validateShippingOptions(
80 const std::vector<payments::mojom::PaymentShippingOptionPtr>& options, 80 const std::vector<blink::mojom::PaymentShippingOptionPtr>& options,
81 const payments::mojom::PaymentItemPtr& total, 81 const blink::mojom::PaymentItemPtr& total,
82 std::string* error_message) { 82 std::string* error_message) {
83 std::set<std::string> uniqueIds; 83 std::set<std::string> uniqueIds;
84 for (const auto& option : options) { 84 for (const auto& option : options) {
85 if (option->id.empty()) { 85 if (option->id.empty()) {
86 *error_message = "ShippingOption id required"; 86 *error_message = "ShippingOption id required";
87 return false; 87 return false;
88 } 88 }
89 89
90 if (uniqueIds.find(option->id) != uniqueIds.end()) { 90 if (uniqueIds.find(option->id) != uniqueIds.end()) {
91 *error_message = "Duplicate shipping option identifiers are not allowed"; 91 *error_message = "Duplicate shipping option identifiers are not allowed";
92 return false; 92 return false;
93 } 93 }
94 uniqueIds.insert(option->id); 94 uniqueIds.insert(option->id);
95 95
96 if (!validateShippingOptionOrPaymentItem(option, total, error_message)) 96 if (!validateShippingOptionOrPaymentItem(option, total, error_message))
97 return false; 97 return false;
98 } 98 }
99 return true; 99 return true;
100 } 100 }
101 101
102 bool validatePaymentDetailsModifiers( 102 bool validatePaymentDetailsModifiers(
103 const std::vector<payments::mojom::PaymentDetailsModifierPtr>& modifiers, 103 const std::vector<blink::mojom::PaymentDetailsModifierPtr>& modifiers,
104 const payments::mojom::PaymentItemPtr& total, 104 const blink::mojom::PaymentItemPtr& total,
105 std::string* error_message) { 105 std::string* error_message) {
106 if (modifiers.empty()) { 106 if (modifiers.empty()) {
107 *error_message = "Must specify at least one payment details modifier"; 107 *error_message = "Must specify at least one payment details modifier";
108 return false; 108 return false;
109 } 109 }
110 110
111 std::set<mojo::String> uniqueMethods; 111 std::set<mojo::String> uniqueMethods;
112 for (const auto& modifier : modifiers) { 112 for (const auto& modifier : modifiers) {
113 if (modifier->supported_methods.empty()) { 113 if (modifier->supported_methods.empty()) {
114 *error_message = "Must specify at least one payment method identifier"; 114 *error_message = "Must specify at least one payment method identifier";
(...skipping 26 matching lines...) Expand all
141 } 141 }
142 } 142 }
143 } 143 }
144 return true; 144 return true;
145 } 145 }
146 146
147 } // namespace 147 } // namespace
148 148
149 namespace payments { 149 namespace payments {
150 150
151 bool validatePaymentDetails(const mojom::PaymentDetailsPtr& details, 151 bool validatePaymentDetails(const blink::mojom::PaymentDetailsPtr& details,
152 std::string* error_message) { 152 std::string* error_message) {
153 if (details->total.is_null()) { 153 if (details->total.is_null()) {
154 *error_message = "Must specify total"; 154 *error_message = "Must specify total";
155 return false; 155 return false;
156 } 156 }
157 157
158 if (!validateShippingOptionOrPaymentItem(details->total, details->total, 158 if (!validateShippingOptionOrPaymentItem(details->total, details->total,
159 error_message)) 159 error_message))
160 return false; 160 return false;
161 161
(...skipping 18 matching lines...) Expand all
180 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, 180 if (!validatePaymentDetailsModifiers(details->modifiers, details->total,
181 error_message)) 181 error_message))
182 return false; 182 return false;
183 } 183 }
184 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) 184 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message))
185 return false; 185 return false;
186 return true; 186 return true;
187 } 187 }
188 188
189 } // namespace payments 189 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/payment_details_validation.h ('k') | components/payments/payment_request.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698