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

Unified Diff: components/payments/payment_request.cc

Issue 2698353002: [Payments] Add the "Cards accepted" row at the top of CC editor. (Closed)
Patch Set: Initial Created 3 years, 10 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/payment_request.cc
diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
index fd2fc4f54f366cd201807bc14cfc42f360bdb452..d6e96e13b283fc0b8344c5ee7fed5c97c64ea1e3 100644
--- a/components/payments/payment_request.cc
+++ b/components/payments/payment_request.cc
@@ -10,8 +10,17 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
+using payments::mojom::BasicCardNetwork;
+
namespace payments {
+namespace {
+
+// Identifier for the basic card payment method in the PaymentMethodData.
+const char* const kBasicCardMethodName = "basic-card";
+
+} // namespace
+
PaymentRequest::PaymentRequest(
content::WebContents* web_contents,
std::unique_ptr<PaymentRequestDelegate> delegate,
@@ -37,7 +46,7 @@ PaymentRequest::~PaymentRequest() {}
void PaymentRequest::Init(
payments::mojom::PaymentRequestClientPtr client,
- std::vector<payments::mojom::PaymentMethodDataPtr> methodData,
+ std::vector<payments::mojom::PaymentMethodDataPtr> method_data,
payments::mojom::PaymentDetailsPtr details,
payments::mojom::PaymentOptionsPtr options) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
@@ -49,6 +58,7 @@ void PaymentRequest::Init(
}
client_ = std::move(client);
details_ = std::move(details);
+ PopulateValidatedMethodData(method_data);
PopulateProfileCache();
SetDefaultProfileSelections();
}
@@ -160,4 +170,60 @@ void PaymentRequest::SetDefaultProfileSelections() {
set_selected_contact_profile(contact_profiles()[0]);
}
+void PaymentRequest::PopulateValidatedMethodData(
+ const std::vector<payments::mojom::PaymentMethodDataPtr>& method_data) {
+ if (method_data.empty()) {
+ LOG(ERROR) << "Invalid payment methods or data";
+ OnConnectionTerminated();
+ return;
+ }
+
+ for (const payments::mojom::PaymentMethodDataPtr& method_data_entry :
+ method_data) {
+ std::vector<std::string> supported_methods =
+ method_data_entry->supported_methods;
+ if (supported_methods.empty()) {
+ LOG(ERROR) << "Invalid payment methods or data";
+ OnConnectionTerminated();
+ return;
+ }
+
+ const std::set<std::string> all_networks{
+ "amex", "diners", "discover", "jcb",
+ "mastercard", "mir", "unionpay", "visa"};
+ for (const std::string& method : supported_methods) {
+ if (method.empty())
+ continue;
+
+ // If a card network is specified right in "supportedMethods", add it.
+ if (all_networks.find(method) != all_networks.end()) {
+ supported_card_networks_.insert(method);
+ } 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.
+ supported_card_networks_.insert(all_networks.begin(),
+ all_networks.end());
+ } else {
+ // The merchant has specified a few basic card supported networks. Use
+ // the mapping to transform to known basic-card types.
+ std::unordered_map<BasicCardNetwork, std::string> networks = {
+ {BasicCardNetwork::AMEX, "amex"},
+ {BasicCardNetwork::DINERS, "diners"},
+ {BasicCardNetwork::DISCOVER, "discover"},
+ {BasicCardNetwork::JCB, "jcb"},
+ {BasicCardNetwork::MASTERCARD, "mastercard"},
+ {BasicCardNetwork::MIR, "mir"},
+ {BasicCardNetwork::UNIONPAY, "unionpay"},
+ {BasicCardNetwork::VISA, "visa"}};
+ for (const BasicCardNetwork& supported_network :
+ method_data_entry->supported_networks) {
+ supported_card_networks_.insert(networks[supported_network]);
+ }
+ }
+ }
+ }
+ }
+}
+
} // namespace payments
« components/payments/payment_request.h ('K') | « components/payments/payment_request.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698