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

Side by Side Diff: components/payments/core/payment_request_data_util.cc

Issue 2800713003: [Payments] Move parsing the PaymentMethodData to "core" (Closed)
Patch Set: fix test 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
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/core/payment_request_data_util.h" 5 #include "components/payments/core/payment_request_data_util.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/string_split.h" 8 #include "base/strings/string_split.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
11 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
12 #include "components/autofill/core/browser/field_types.h" 12 #include "components/autofill/core/browser/field_types.h"
13 #include "components/autofill/core/browser/personal_data_manager.h" 13 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/payments/core/basic_card_response.h" 14 #include "components/payments/core/basic_card_response.h"
15 #include "components/payments/core/payment_address.h" 15 #include "components/payments/core/payment_address.h"
16 #include "components/payments/core/payment_method_data.h"
16 17
17 namespace payments { 18 namespace payments {
18 namespace data_util { 19 namespace data_util {
19 20
20 PaymentAddress GetPaymentAddressFromAutofillProfile( 21 PaymentAddress GetPaymentAddressFromAutofillProfile(
21 const autofill::AutofillProfile& profile, 22 const autofill::AutofillProfile& profile,
22 const std::string& app_locale) { 23 const std::string& app_locale) {
23 PaymentAddress address; 24 PaymentAddress address;
24 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY); 25 address.country = profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY);
25 address.address_line = base::SplitString( 26 address.address_line = base::SplitString(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( 64 autofill::PersonalDataManager::GetProfileFromProfilesByGUID(
64 card.billing_address_id(), billing_profiles); 65 card.billing_address_id(), billing_profiles);
65 DCHECK(billing_address); 66 DCHECK(billing_address);
66 response.billing_address = 67 response.billing_address =
67 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale); 68 GetPaymentAddressFromAutofillProfile(*billing_address, app_locale);
68 } 69 }
69 70
70 return response; 71 return response;
71 } 72 }
72 73
74 bool ParseBasicCardSupportedNetworks(
75 const std::vector<PaymentMethodData>& method_data,
76 std::vector<std::string>* out_supported_networks,
77 std::set<std::string>* out_basic_card_specified_networks) {
78 DCHECK(out_supported_networks->empty());
79 DCHECK(out_basic_card_specified_networks->empty());
80
81 std::set<std::string> card_networks{"amex", "diners", "discover",
82 "jcb", "mastercard", "mir",
83 "unionpay", "visa"};
84 for (const PaymentMethodData& method_data_entry : method_data) {
85 if (method_data_entry.supported_methods.empty())
86 return false;
87
88 for (const std::string& method : method_data_entry.supported_methods) {
89 if (method.empty())
90 continue;
91
92 // If a card network is specified right in "supportedMethods", add it.
93 const char kBasicCardMethodName[] = "basic-card";
94 auto card_it = card_networks.find(method);
95 if (card_it != card_networks.end()) {
96 out_supported_networks->push_back(method);
97 // |method| removed from |card_networks| so that it is not doubly added
98 // to |supported_card_networks_| if "basic-card" is specified with no
99 // supported networks.
100 card_networks.erase(card_it);
101 } else if (method == kBasicCardMethodName) {
102 // For the "basic-card" method, check "supportedNetworks".
103 if (method_data_entry.supported_networks.empty()) {
104 // Empty |supported_networks| means all networks are supported.
105 out_supported_networks->insert(out_supported_networks->end(),
106 card_networks.begin(),
107 card_networks.end());
108 out_basic_card_specified_networks->insert(card_networks.begin(),
109 card_networks.end());
110 // Clear the set so that no further networks are added to
111 // |out_supported_networks|.
112 card_networks.clear();
113 } else {
114 // The merchant has specified a few basic card supported networks. Use
115 // the mapping to transform to known basic-card types.
116 for (const std::string& supported_network :
117 method_data_entry.supported_networks) {
118 // Make sure that the network was not already added to
119 // |out_supported_networks|. If it's still in |card_networks| it's
120 // fair game.
121 auto it = card_networks.find(supported_network);
122 if (it != card_networks.end()) {
123 out_supported_networks->push_back(supported_network);
124 out_basic_card_specified_networks->insert(supported_network);
125 card_networks.erase(it);
126 }
127 }
128 }
129 }
130 }
131 }
132 return true;
133 }
134
73 } // namespace data_util 135 } // namespace data_util
74 } // namespace payments 136 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payment_request_data_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698