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

Side by Side Diff: ios/chrome/browser/payments/payment_request.mm

Issue 2803543005: [Payments] iOS: Support basic-card (Closed)
Patch Set: addressed comments 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
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 "ios/chrome/browser/payments/payment_request.h" 5 #include "ios/chrome/browser/payments/payment_request.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/browser/autofill_data_util.h" 8 #include "components/autofill/core/browser/autofill_data_util.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/credit_card.h" 10 #include "components/autofill/core/browser/credit_card.h"
11 #include "components/autofill/core/browser/personal_data_manager.h" 11 #include "components/autofill/core/browser/personal_data_manager.h"
12 #include "components/payments/core/currency_formatter.h" 12 #include "components/payments/core/currency_formatter.h"
13 #include "components/payments/core/payment_request_data_util.h"
13 #include "ios/chrome/browser/application_context.h" 14 #include "ios/chrome/browser/application_context.h"
14 #include "ios/web/public/payments/payment_request.h" 15 #include "ios/web/public/payments/payment_request.h"
15 16
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 18 #error "This file requires ARC support."
18 #endif 19 #endif
19 20
20 PaymentRequest::PaymentRequest( 21 PaymentRequest::PaymentRequest(
21 const web::PaymentRequest& web_payment_request, 22 const web::PaymentRequest& web_payment_request,
22 autofill::PersonalDataManager* personal_data_manager) 23 autofill::PersonalDataManager* personal_data_manager)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // TODO(crbug.com/602666): Implement prioritization rules for shipping and 77 // TODO(crbug.com/602666): Implement prioritization rules for shipping and
77 // contact profiles. 78 // contact profiles.
78 79
79 if (!shipping_profiles_.empty()) 80 if (!shipping_profiles_.empty())
80 selected_shipping_profile_ = shipping_profiles_[0]; 81 selected_shipping_profile_ = shipping_profiles_[0];
81 if (!contact_profiles_.empty()) 82 if (!contact_profiles_.empty())
82 selected_contact_profile_ = contact_profiles_[0]; 83 selected_contact_profile_ = contact_profiles_[0];
83 } 84 }
84 85
85 void PaymentRequest::PopulateCreditCardCache() { 86 void PaymentRequest::PopulateCreditCardCache() {
86 for (const auto& method_data : web_payment_request_.method_data) { 87 if (!payments::data_util::ParseBasicCardSupportedNetworks(
87 for (const std::string& supported_method : method_data.supported_methods) { 88 web_payment_request_.method_data, &supported_card_networks_,
88 supported_card_networks_.push_back(supported_method); 89 &basic_card_specified_networks_)) {
89 } 90 // TODO(crbug.com/709036): close the UI and reject the promise since the
91 // data is invalid.
92 return;
90 } 93 }
91 94
92 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest = 95 const std::vector<autofill::CreditCard*>& credit_cards_to_suggest =
93 personal_data_manager_->GetCreditCardsToSuggest(); 96 personal_data_manager_->GetCreditCardsToSuggest();
94 credit_card_cache_.reserve(credit_cards_to_suggest.size()); 97 credit_card_cache_.reserve(credit_cards_to_suggest.size());
95 98
96 // TODO(crbug.com/602666): Update the following logic to allow basic card
97 // payment. https://w3c.github.io/webpayments-methods-card/
98 // new PaymentRequest([{supportedMethods: ['basic-card'],
99 // data: {supportedNetworks:['visa']}]}], ...);
100
101 for (const auto* credit_card : credit_cards_to_suggest) { 99 for (const auto* credit_card : credit_cards_to_suggest) {
102 std::string spec_card_type = 100 std::string spec_card_type =
103 autofill::data_util::GetPaymentRequestData(credit_card->type()) 101 autofill::data_util::GetPaymentRequestData(credit_card->type())
104 .basic_card_payment_type; 102 .basic_card_payment_type;
105 if (std::find(supported_card_networks_.begin(), 103 if (std::find(supported_card_networks_.begin(),
106 supported_card_networks_.end(), 104 supported_card_networks_.end(),
107 spec_card_type) != supported_card_networks_.end()) { 105 spec_card_type) != supported_card_networks_.end()) {
108 credit_card_cache_.push_back(*credit_card); 106 credit_card_cache_.push_back(*credit_card);
109 credit_cards_.push_back(&credit_card_cache_.back()); 107 credit_cards_.push_back(&credit_card_cache_.back());
110 } 108 }
(...skipping 16 matching lines...) Expand all
127 125
128 selected_shipping_option_ = nullptr; 126 selected_shipping_option_ = nullptr;
129 for (auto* shipping_option : shipping_options_) { 127 for (auto* shipping_option : shipping_options_) {
130 if (shipping_option->selected) { 128 if (shipping_option->selected) {
131 // If more than one option has |selected| set, the last one in the 129 // If more than one option has |selected| set, the last one in the
132 // sequence should be treated as the selected item. 130 // sequence should be treated as the selected item.
133 selected_shipping_option_ = shipping_option; 131 selected_shipping_option_ = shipping_option;
134 } 132 }
135 } 133 }
136 } 134 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/payment_request.h ('k') | ios/chrome/browser/payments/payment_request_coordinator.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698