| Index: components/payments/payment_request.cc
|
| diff --git a/components/payments/payment_request.cc b/components/payments/payment_request.cc
|
| index fd2fc4f54f366cd201807bc14cfc42f360bdb452..9ea28a891e564eff5c2fcc82fd7f0e9f186bb51d 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,75 @@ 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;
|
| + }
|
| +
|
| + std::set<std::string> card_networks{"amex", "diners", "discover",
|
| + "jcb", "mastercard", "mir",
|
| + "unionpay", "visa"};
|
| + 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;
|
| + }
|
| +
|
| + for (const std::string& method : 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()) {
|
| + supported_card_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.
|
| + supported_card_networks_.insert(supported_card_networks_.end(),
|
| + card_networks.begin(),
|
| + card_networks.end());
|
| + // Clear the set so that no further networks are added to
|
| + // |supported_card_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.
|
| + 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) {
|
| + // Make sure that the network was not already added to
|
| + // |supported_card_networks_|.
|
| + auto card_it = card_networks.find(networks[supported_network]);
|
| + if (card_it != card_networks.end()) {
|
| + supported_card_networks_.push_back(networks[supported_network]);
|
| + card_networks.erase(card_it);
|
| + }
|
| + }
|
| + }
|
| + }
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace payments
|
|
|