| 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/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" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 bool validatePaymentDetailsModifiers( | 102 bool validatePaymentDetailsModifiers( |
| 103 const std::vector<payments::mojom::PaymentDetailsModifierPtr>& modifiers, | 103 const std::vector<payments::mojom::PaymentDetailsModifierPtr>& modifiers, |
| 104 const payments::mojom::PaymentItemPtr& total, | 104 const payments::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; | |
| 112 for (const auto& modifier : modifiers) { | 111 for (const auto& modifier : modifiers) { |
| 113 if (modifier->supported_methods.empty()) { | 112 if (!modifier->method_data) { |
| 113 *error_message = "Method data required"; |
| 114 return false; |
| 115 } |
| 116 |
| 117 if (modifier->method_data->supported_methods.empty()) { |
| 114 *error_message = "Must specify at least one payment method identifier"; | 118 *error_message = "Must specify at least one payment method identifier"; |
| 115 return false; | 119 return false; |
| 116 } | 120 } |
| 117 | 121 |
| 118 for (const auto& method : modifier->supported_methods) { | |
| 119 if (uniqueMethods.find(method) != uniqueMethods.end()) { | |
| 120 *error_message = "Duplicate payment method identifiers are not allowed"; | |
| 121 return false; | |
| 122 } | |
| 123 uniqueMethods.insert(method); | |
| 124 } | |
| 125 | |
| 126 if (modifier->total) { | 122 if (modifier->total) { |
| 127 if (!validateShippingOptionOrPaymentItem(modifier->total, total, | 123 if (!validateShippingOptionOrPaymentItem(modifier->total, total, |
| 128 error_message)) | 124 error_message)) |
| 129 return false; | 125 return false; |
| 130 | 126 |
| 131 if (modifier->total->amount->value[0] == '-') { | 127 if (modifier->total->amount->value[0] == '-') { |
| 132 *error_message = "Total amount value should be non-negative"; | 128 *error_message = "Total amount value should be non-negative"; |
| 133 return false; | 129 return false; |
| 134 } | 130 } |
| 135 } | 131 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, | 176 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, |
| 181 error_message)) | 177 error_message)) |
| 182 return false; | 178 return false; |
| 183 } | 179 } |
| 184 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) | 180 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) |
| 185 return false; | 181 return false; |
| 186 return true; | 182 return true; |
| 187 } | 183 } |
| 188 | 184 |
| 189 } // namespace payments | 185 } // namespace payments |
| OLD | NEW |