Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | 99 // TODO(crbug.com/602666): Update the following logic to allow basic card |
|
Moe
2017/04/06 20:51:03
Could you please remove this comment now that we d
Mathieu
2017/04/06 21:04:41
haha. good catch.
| |
| 97 // payment. https://w3c.github.io/webpayments-methods-card/ | 100 // payment. https://w3c.github.io/webpayments-methods-card/ |
| 98 // new PaymentRequest([{supportedMethods: ['basic-card'], | 101 // new PaymentRequest([{supportedMethods: ['basic-card'], |
| 99 // data: {supportedNetworks:['visa']}]}], ...); | 102 // data: {supportedNetworks:['visa']}]}], ...); |
| 100 | 103 |
| 101 for (const auto* credit_card : credit_cards_to_suggest) { | 104 for (const auto* credit_card : credit_cards_to_suggest) { |
| 102 std::string spec_card_type = | 105 std::string spec_card_type = |
| 103 autofill::data_util::GetPaymentRequestData(credit_card->type()) | 106 autofill::data_util::GetPaymentRequestData(credit_card->type()) |
| 104 .basic_card_payment_type; | 107 .basic_card_payment_type; |
| 105 if (std::find(supported_card_networks_.begin(), | 108 if (std::find(supported_card_networks_.begin(), |
| 106 supported_card_networks_.end(), | 109 supported_card_networks_.end(), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 127 | 130 |
| 128 selected_shipping_option_ = nullptr; | 131 selected_shipping_option_ = nullptr; |
| 129 for (auto* shipping_option : shipping_options_) { | 132 for (auto* shipping_option : shipping_options_) { |
| 130 if (shipping_option->selected) { | 133 if (shipping_option->selected) { |
| 131 // If more than one option has |selected| set, the last one in the | 134 // If more than one option has |selected| set, the last one in the |
| 132 // sequence should be treated as the selected item. | 135 // sequence should be treated as the selected item. |
| 133 selected_shipping_option_ = shipping_option; | 136 selected_shipping_option_ = shipping_option; |
| 134 } | 137 } |
| 135 } | 138 } |
| 136 } | 139 } |
| OLD | NEW |