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

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

Issue 2750363002: [Payment Request] supported card networks + adding a credit card. (Closed)
Patch Set: Addressed comments Created 3 years, 9 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 <unordered_set> 7 #include "base/strings/string_util.h"
8
9 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_data_util.h" 9 #include "components/autofill/core/browser/autofill_data_util.h"
11 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/autofill/core/browser/credit_card.h" 11 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/personal_data_manager.h" 12 #include "components/autofill/core/browser/personal_data_manager.h"
14 #include "components/payments/core/currency_formatter.h" 13 #include "components/payments/core/currency_formatter.h"
15 #include "ios/chrome/browser/application_context.h" 14 #include "ios/chrome/browser/application_context.h"
16 #include "ios/web/public/payments/payment_request.h" 15 #include "ios/web/public/payments/payment_request.h"
17 16
18 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 27 matching lines...) Expand all
46 if (!currency_formatter_) { 45 if (!currency_formatter_) {
47 currency_formatter_.reset(new payments::CurrencyFormatter( 46 currency_formatter_.reset(new payments::CurrencyFormatter(
48 base::UTF16ToASCII(web_payment_request_->details.total.amount.currency), 47 base::UTF16ToASCII(web_payment_request_->details.total.amount.currency),
49 base::UTF16ToASCII( 48 base::UTF16ToASCII(
50 web_payment_request_->details.total.amount.currency_system), 49 web_payment_request_->details.total.amount.currency_system),
51 GetApplicationContext()->GetApplicationLocale())); 50 GetApplicationContext()->GetApplicationLocale()));
52 } 51 }
53 return currency_formatter_.get(); 52 return currency_formatter_.get();
54 } 53 }
55 54
55 void PaymentRequest::AddCreditCard(
56 std::unique_ptr<autofill::CreditCard> credit_card) {
57 credit_card_cache_.insert(credit_card_cache_.begin(), std::move(credit_card));
58 credit_cards_.insert(credit_cards_.begin(), credit_card_cache_.front().get());
59 }
60
56 void PaymentRequest::PopulateProfileCache() { 61 void PaymentRequest::PopulateProfileCache() {
57 for (const auto* profile : personal_data_manager_->GetProfilesToSuggest()) { 62 for (const auto* profile : personal_data_manager_->GetProfilesToSuggest()) {
58 profile_cache_.push_back( 63 profile_cache_.push_back(
59 base::MakeUnique<autofill::AutofillProfile>(*profile)); 64 base::MakeUnique<autofill::AutofillProfile>(*profile));
60 shipping_profiles_.push_back(profile_cache_.back().get()); 65 shipping_profiles_.push_back(profile_cache_.back().get());
61 // TODO(crbug.com/602666): Implement deduplication rules for profiles. 66 // TODO(crbug.com/602666): Implement deduplication rules for profiles.
62 contact_profiles_.push_back(profile_cache_.back().get()); 67 contact_profiles_.push_back(profile_cache_.back().get());
63 } 68 }
64 69
65 // TODO(crbug.com/602666): Implement prioritization rules for shipping and 70 // TODO(crbug.com/602666): Implement prioritization rules for shipping and
66 // contact profiles. 71 // contact profiles.
67 72
68 if (!shipping_profiles_.empty()) 73 if (!shipping_profiles_.empty())
69 selected_shipping_profile_ = shipping_profiles_[0]; 74 selected_shipping_profile_ = shipping_profiles_[0];
70 if (!contact_profiles_.empty()) 75 if (!contact_profiles_.empty())
71 selected_contact_profile_ = contact_profiles_[0]; 76 selected_contact_profile_ = contact_profiles_[0];
72 } 77 }
73 78
74 void PaymentRequest::PopulateCreditCardCache() { 79 void PaymentRequest::PopulateCreditCardCache() {
75 DCHECK(web_payment_request_); 80 DCHECK(web_payment_request_);
76 std::unordered_set<base::string16> supported_method_types;
77 for (const auto& method_data : web_payment_request_->method_data) { 81 for (const auto& method_data : web_payment_request_->method_data) {
78 for (const auto& supported_method : method_data.supported_methods) 82 for (const auto& supported_method : method_data.supported_methods) {
79 supported_method_types.insert(supported_method); 83 // Reject non-ASCII supported methods.
84 if (base::IsStringASCII(supported_method)) {
85 supported_card_networks_.push_back(
86 base::UTF16ToASCII(supported_method));
87 }
88 }
80 } 89 }
81 90
82 std::vector<autofill::CreditCard*> credit_cards = 91 std::vector<autofill::CreditCard*> credit_cards =
83 personal_data_manager_->GetCreditCardsToSuggest(); 92 personal_data_manager_->GetCreditCardsToSuggest();
84 93
85 // TODO(crbug.com/602666): Update the following logic to allow basic card 94 // TODO(crbug.com/602666): Update the following logic to allow basic card
86 // payment. https://w3c.github.io/webpayments-methods-card/ 95 // payment. https://w3c.github.io/webpayments-methods-card/
87 // new PaymentRequest([{supportedMethods: ['basic-card'], 96 // new PaymentRequest([{supportedMethods: ['basic-card'],
88 // data: {supportedNetworks:['visa']}]}], ...); 97 // data: {supportedNetworks:['visa']}]}], ...);
89 98
90 for (const auto* credit_card : credit_cards) { 99 for (const auto* credit_card : credit_cards) {
91 std::string spec_card_type = 100 std::string spec_card_type =
92 autofill::data_util::GetPaymentRequestData(credit_card->type()) 101 autofill::data_util::GetPaymentRequestData(credit_card->type())
93 .basic_card_payment_type; 102 .basic_card_payment_type;
94 if (supported_method_types.find(base::ASCIIToUTF16(spec_card_type)) != 103 if (std::find(supported_card_networks_.begin(),
95 supported_method_types.end()) { 104 supported_card_networks_.end(),
105 spec_card_type) != supported_card_networks_.end()) {
96 credit_card_cache_.push_back( 106 credit_card_cache_.push_back(
97 base::MakeUnique<autofill::CreditCard>(*credit_card)); 107 base::MakeUnique<autofill::CreditCard>(*credit_card));
98 credit_cards_.push_back(credit_card_cache_.back().get()); 108 credit_cards_.push_back(credit_card_cache_.back().get());
99 } 109 }
100 } 110 }
101 111
102 // TODO(crbug.com/602666): Implement prioritization rules for credit cards. 112 // TODO(crbug.com/602666): Implement prioritization rules for credit cards.
103 113
104 if (!credit_cards_.empty()) 114 if (!credit_cards_.empty())
105 selected_credit_card_ = credit_cards_[0]; 115 selected_credit_card_ = credit_cards_[0];
(...skipping 11 matching lines...) Expand all
117 127
118 selected_shipping_option_ = nullptr; 128 selected_shipping_option_ = nullptr;
119 for (auto* shipping_option : shipping_options_) { 129 for (auto* shipping_option : shipping_options_) {
120 if (shipping_option->selected) { 130 if (shipping_option->selected) {
121 // If more than one option has |selected| set, the last one in the 131 // If more than one option has |selected| set, the last one in the
122 // sequence should be treated as the selected item. 132 // sequence should be treated as the selected item.
123 selected_shipping_option_ = shipping_option; 133 selected_shipping_option_ = shipping_option;
124 } 134 }
125 } 135 }
126 } 136 }
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/payment_request.h ('k') | ios/chrome/browser/payments/payment_request_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698