| 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 #ifndef IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ | 5 #ifndef IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ |
| 6 #define IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ | 6 #define IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ |
| 7 | 7 |
| 8 #include <set> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "ios/web/public/payments/payment_request.h" | 13 #include "ios/web/public/payments/payment_request.h" |
| 13 | 14 |
| 14 namespace autofill { | 15 namespace autofill { |
| 15 class AutofillProfile; | 16 class AutofillProfile; |
| 16 class CreditCard; | 17 class CreditCard; |
| 17 class PersonalDataManager; | 18 class PersonalDataManager; |
| 18 } // namespace autofill | 19 } // namespace autofill |
| 19 | 20 |
| 20 namespace payments { | 21 namespace payments { |
| 21 class CurrencyFormatter; | 22 class CurrencyFormatter; |
| 22 } // namespace payments | 23 } // namespace payments |
| 23 | 24 |
| 24 // Owns an instance of web::PaymentRequest as provided by the page invoking the | 25 // Owns an instance of web::PaymentRequest as provided by the page invoking the |
| 25 // PaymentRequest API. Also caches credit cards and addresses provided by the | 26 // PaymentRequest API. Also caches credit cards and addresses provided by the |
| 26 // |personal_data_manager| and manages shared resources and user selections for | 27 // |personal_data_manager| and manages shared resources and user selections for |
| 27 // the current PaymentRequest flow. It takes ownership of |web_payment_request| | 28 // the current PaymentRequest flow. It takes ownership of |web_payment_request| |
| 28 // and must be initialized with a non-null instance of |personal_data_manager| | 29 // and must be initialized with a non-null instance of |personal_data_manager| |
| 29 // that outlives this class. | 30 // that outlives this class. |
| 30 class PaymentRequest { | 31 class PaymentRequest { |
| 31 public: | 32 public: |
| 32 // |personal_data_manager| should not be null and should outlive this object. | 33 // |personal_data_manager| should not be null and should outlive this object. |
| 33 PaymentRequest(std::unique_ptr<web::PaymentRequest> web_payment_request, | 34 PaymentRequest(std::unique_ptr<web::PaymentRequest> web_payment_request, |
| 34 autofill::PersonalDataManager* personal_data_manager); | 35 autofill::PersonalDataManager* personal_data_manager); |
| 35 ~PaymentRequest(); | 36 ~PaymentRequest(); |
| 36 | 37 |
| 38 autofill::PersonalDataManager* GetPersonalDataManager() const { |
| 39 return personal_data_manager_; |
| 40 } |
| 41 |
| 37 // Returns the payment details from |web_payment_request_|. | 42 // Returns the payment details from |web_payment_request_|. |
| 38 const web::PaymentDetails& payment_details() const { | 43 const web::PaymentDetails& payment_details() const { |
| 39 return web_payment_request_->details; | 44 return web_payment_request_->details; |
| 40 } | 45 } |
| 41 | 46 |
| 42 // Returns the payment options from |web_payment_request_|. | 47 // Returns the payment options from |web_payment_request_|. |
| 43 const web::PaymentOptions& payment_options() const { | 48 const web::PaymentOptions& payment_options() const { |
| 44 return web_payment_request_->options; | 49 return web_payment_request_->options; |
| 45 } | 50 } |
| 46 | 51 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 void set_selected_contact_profile(autofill::AutofillProfile* profile) { | 92 void set_selected_contact_profile(autofill::AutofillProfile* profile) { |
| 88 selected_contact_profile_ = profile; | 93 selected_contact_profile_ = profile; |
| 89 } | 94 } |
| 90 | 95 |
| 91 // Returns the available autofill profiles for this user to be used as | 96 // Returns the available autofill profiles for this user to be used as |
| 92 // billing profiles. | 97 // billing profiles. |
| 93 const std::vector<autofill::AutofillProfile*>& billing_profiles() const { | 98 const std::vector<autofill::AutofillProfile*>& billing_profiles() const { |
| 94 return shipping_profiles_; | 99 return shipping_profiles_; |
| 95 } | 100 } |
| 96 | 101 |
| 102 const std::set<std::string>& supported_card_networks() { |
| 103 return supported_card_networks_; |
| 104 } |
| 105 |
| 106 // Adds |credit_card| to the list of cached credit cards. |
| 107 void AddCreditCard(std::unique_ptr<autofill::CreditCard> credit_card); |
| 108 |
| 97 // Returns the available autofill credit cards for this user that match a | 109 // Returns the available autofill credit cards for this user that match a |
| 98 // supported type specified in |web_payment_request_|. | 110 // supported type specified in |web_payment_request_|. |
| 99 const std::vector<autofill::CreditCard*>& credit_cards() const { | 111 const std::vector<autofill::CreditCard*>& credit_cards() const { |
| 100 return credit_cards_; | 112 return credit_cards_; |
| 101 } | 113 } |
| 102 | 114 |
| 103 // Returns the currently selected credit card for this PaymentRequest flow if | 115 // Returns the currently selected credit card for this PaymentRequest flow if |
| 104 // there is one. Returns nullptr if there is no selected credit card. | 116 // there is one. Returns nullptr if there is no selected credit card. |
| 105 autofill::CreditCard* selected_credit_card() const { | 117 autofill::CreditCard* selected_credit_card() const { |
| 106 return selected_credit_card_; | 118 return selected_credit_card_; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 172 |
| 161 // Credit cards returnd by the Data Manager may change due to (e.g.) | 173 // Credit cards returnd by the Data Manager may change due to (e.g.) |
| 162 // sync events, meaning PaymentRequest may outlive them. Therefore, credit | 174 // sync events, meaning PaymentRequest may outlive them. Therefore, credit |
| 163 // cards are fetched once and owned here. Whenever credit cards are requested | 175 // cards are fetched once and owned here. Whenever credit cards are requested |
| 164 // a vector of pointers to these copies are returned. | 176 // a vector of pointers to these copies are returned. |
| 165 std::vector<std::unique_ptr<autofill::CreditCard>> credit_card_cache_; | 177 std::vector<std::unique_ptr<autofill::CreditCard>> credit_card_cache_; |
| 166 | 178 |
| 167 std::vector<autofill::CreditCard*> credit_cards_; | 179 std::vector<autofill::CreditCard*> credit_cards_; |
| 168 autofill::CreditCard* selected_credit_card_; | 180 autofill::CreditCard* selected_credit_card_; |
| 169 | 181 |
| 182 // A set of supported basic card networks. |
| 183 std::set<std::string> supported_card_networks_; |
| 184 |
| 170 // A vector of pointers to the shipping options in |web_payment_request_|. | 185 // A vector of pointers to the shipping options in |web_payment_request_|. |
| 171 std::vector<web::PaymentShippingOption*> shipping_options_; | 186 std::vector<web::PaymentShippingOption*> shipping_options_; |
| 172 web::PaymentShippingOption* selected_shipping_option_; | 187 web::PaymentShippingOption* selected_shipping_option_; |
| 173 | 188 |
| 174 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); | 189 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
| 175 }; | 190 }; |
| 176 | 191 |
| 177 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ | 192 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ |
| OLD | NEW |