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

Unified Diff: components/payments/core/payment_request_data_util.cc

Issue 2800713003: [Payments] Move parsing the PaymentMethodData to "core" (Closed)
Patch Set: fixed TODO 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/core/payment_request_data_util.cc
diff --git a/components/payments/core/payment_request_data_util.cc b/components/payments/core/payment_request_data_util.cc
index 23e905e49c473a33ef10a768b77c38aac8ace5a6..8fbcc3353d15a9d3d1075a5c30d02ba7e7d46ff7 100644
--- a/components/payments/core/payment_request_data_util.cc
+++ b/components/payments/core/payment_request_data_util.cc
@@ -13,10 +13,17 @@
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/payments/core/basic_card_response.h"
#include "components/payments/core/payment_address.h"
+#include "components/payments/core/payment_method_data.h"
namespace payments {
namespace data_util {
+namespace {
+
+const char kBasicCardMethodName[] = "basic-card";
please use gerrit instead 2017/04/05 19:29:25 Nit: place immediately before where this is used,
Mathieu 2017/04/05 20:28:33 Done.
+
+} // namespace
+
PaymentAddress GetPaymentAddressFromAutofillProfile(
const autofill::AutofillProfile& profile,
const std::string& app_locale) {
@@ -70,5 +77,68 @@ BasicCardResponse GetBasicCardResponseFromAutofillCreditCard(
return response;
}
+bool ParseBasicCardSupportedNetworks(
+ const std::vector<PaymentMethodData>& method_data,
+ std::vector<std::string>* out_supported_networks,
+ std::set<std::string>* out_basic_card_specified_networks) {
+ DCHECK(out_supported_networks->empty());
+ DCHECK(out_basic_card_specified_networks->empty());
+
+ std::set<std::string> card_networks{"amex", "diners", "discover",
+ "jcb", "mastercard", "mir",
+ "unionpay", "visa"};
+ for (const PaymentMethodData& method_data_entry : method_data) {
+ if (method_data_entry.supported_methods.empty())
+ return false;
+
+ for (const std::string& method : method_data_entry.supported_methods) {
+ if (method.empty())
+ continue;
+
+ // If a card network is specified right in "supportedMethods", add it.
+ auto card_it = card_networks.find(method);
+ if (card_it != card_networks.end()) {
+ out_supported_networks->push_back(method);
+ // |method| removed from |card_networks| so that it is not doubly added
+ // to |supported_card_networks_| if "basic-card" is specified with no
+ // supported networks.
+ card_networks.erase(card_it);
+ } else if (method == kBasicCardMethodName) {
+ // For the "basic-card" method, check "supportedNetworks".
+ if (method_data_entry.supported_networks.empty()) {
+ // Empty |supported_networks| means all networks are supported.
+ out_supported_networks->insert(out_supported_networks->end(),
+ card_networks.begin(),
+ card_networks.end());
+ out_basic_card_specified_networks->insert(card_networks.begin(),
+ card_networks.end());
+ // Clear the set so that no further networks are added to
+ // |out_supported_networks|.
+ card_networks.clear();
+ } else {
+ // The merchant has specified a few basic card supported networks. Use
+ // the mapping to transform to known basic-card types.
+ for (const std::string& supported_network :
+ method_data_entry.supported_networks) {
+ // Make sure that the network was not already added to
+ // |out_supported_networks|. If it's still in |card_networks| it's
+ // fair game.
+ auto it = card_networks.find(supported_network);
+ if (it != card_networks.end()) {
+ out_supported_networks->push_back(supported_network);
+ out_basic_card_specified_networks->insert(supported_network);
+ card_networks.erase(it);
+ } else {
+ // It's invalid to specify an unsupported card network identifier.
+ return false;
+ }
+ }
+ }
+ }
+ }
+ }
+ return true;
+}
+
} // namespace data_util
} // namespace payments

Powered by Google App Engine
This is Rietveld 408576698