| 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 <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 @protocol PaymentRequestUIDelegate<NSObject> | 43 @protocol PaymentRequestUIDelegate<NSObject> |
| 44 | 44 |
| 45 - (void) | 45 - (void) |
| 46 requestFullCreditCard:(const autofill::CreditCard&)creditCard | 46 requestFullCreditCard:(const autofill::CreditCard&)creditCard |
| 47 resultDelegate: | 47 resultDelegate: |
| 48 (base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>) | 48 (base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>) |
| 49 resultDelegate; | 49 resultDelegate; |
| 50 | 50 |
| 51 @end | 51 @end |
| 52 | 52 |
| 53 namespace payments { |
| 54 |
| 53 // Has a copy of web::PaymentRequest as provided by the page invoking the | 55 // Has a copy of web::PaymentRequest as provided by the page invoking the |
| 54 // PaymentRequest API. Also caches credit cards and addresses provided by the | 56 // PaymentRequest API. Also caches credit cards and addresses provided by the |
| 55 // |personal_data_manager| and manages shared resources and user selections for | 57 // |personal_data_manager| and manages shared resources and user selections for |
| 56 // the current PaymentRequest flow. It must be initialized with a non-null | 58 // the current PaymentRequest flow. It must be initialized with a non-null |
| 57 // instance of |personal_data_manager| that outlives this class. | 59 // instance of |personal_data_manager| that outlives this class. |
| 58 class PaymentRequest : public payments::PaymentOptionsProvider, | 60 class PaymentRequest : public PaymentOptionsProvider, |
| 59 public payments::PaymentRequestBaseDelegate { | 61 public PaymentRequestBaseDelegate { |
| 60 public: | 62 public: |
| 61 // |personal_data_manager| should not be null and should outlive this object. | 63 // |personal_data_manager| should not be null and should outlive this object. |
| 62 PaymentRequest(const web::PaymentRequest& web_payment_request, | 64 PaymentRequest(const web::PaymentRequest& web_payment_request, |
| 63 ios::ChromeBrowserState* browser_state_, | 65 ios::ChromeBrowserState* browser_state_, |
| 64 autofill::PersonalDataManager* personal_data_manager, | 66 autofill::PersonalDataManager* personal_data_manager, |
| 65 id<PaymentRequestUIDelegate> payment_request_ui_delegate); | 67 id<PaymentRequestUIDelegate> payment_request_ui_delegate); |
| 66 ~PaymentRequest() override; | 68 ~PaymentRequest() override; |
| 67 | 69 |
| 68 // PaymentRequestBaseDelegate: | 70 // PaymentRequestBaseDelegate: |
| 69 autofill::PersonalDataManager* GetPersonalDataManager() override; | 71 autofill::PersonalDataManager* GetPersonalDataManager() override; |
| 70 const std::string& GetApplicationLocale() const override; | 72 const std::string& GetApplicationLocale() const override; |
| 71 bool IsIncognito() const override; | 73 bool IsIncognito() const override; |
| 72 bool IsSslCertificateValid() override; | 74 bool IsSslCertificateValid() override; |
| 73 const GURL& GetLastCommittedURL() const override; | 75 const GURL& GetLastCommittedURL() const override; |
| 74 void DoFullCardRequest( | 76 void DoFullCardRequest( |
| 75 const autofill::CreditCard& credit_card, | 77 const autofill::CreditCard& credit_card, |
| 76 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> | 78 base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate> |
| 77 result_delegate) override; | 79 result_delegate) override; |
| 78 payments::AddressNormalizer* GetAddressNormalizer() override; | 80 AddressNormalizer* GetAddressNormalizer() override; |
| 79 autofill::RegionDataLoader* GetRegionDataLoader() override; | 81 autofill::RegionDataLoader* GetRegionDataLoader() override; |
| 80 ukm::UkmRecorder* GetUkmRecorder() override; | 82 ukm::UkmRecorder* GetUkmRecorder() override; |
| 81 std::string GetAuthenticatedEmail() const override; | 83 std::string GetAuthenticatedEmail() const override; |
| 82 PrefService* GetPrefService() override; | 84 PrefService* GetPrefService() override; |
| 83 | 85 |
| 84 // Returns the web::PaymentRequest that was used to build this PaymentRequest. | 86 // Returns the web::PaymentRequest that was used to build this PaymentRequest. |
| 85 const web::PaymentRequest& web_payment_request() const { | 87 const web::PaymentRequest& web_payment_request() const { |
| 86 return web_payment_request_; | 88 return web_payment_request_; |
| 87 } | 89 } |
| 88 | 90 |
| 89 // Returns the payment details from |web_payment_request_|. | 91 // Returns the payment details from |web_payment_request_|. |
| 90 const web::PaymentDetails& payment_details() const { | 92 const web::PaymentDetails& payment_details() const { |
| 91 return web_payment_request_.details; | 93 return web_payment_request_.details; |
| 92 } | 94 } |
| 93 | 95 |
| 94 // Updates the payment details of the |web_payment_request_|. It also updates | 96 // Updates the payment details of the |web_payment_request_|. It also updates |
| 95 // the cached references to the shipping options in |web_payment_request_| as | 97 // the cached references to the shipping options in |web_payment_request_| as |
| 96 // well as the reference to the selected shipping option. | 98 // well as the reference to the selected shipping option. |
| 97 void UpdatePaymentDetails(const web::PaymentDetails& details); | 99 void UpdatePaymentDetails(const web::PaymentDetails& details); |
| 98 | 100 |
| 99 // PaymentOptionsProvider: | 101 // PaymentOptionsProvider: |
| 100 bool request_shipping() const override; | 102 bool request_shipping() const override; |
| 101 bool request_payer_name() const override; | 103 bool request_payer_name() const override; |
| 102 bool request_payer_phone() const override; | 104 bool request_payer_phone() const override; |
| 103 bool request_payer_email() const override; | 105 bool request_payer_email() const override; |
| 104 payments::PaymentShippingType shipping_type() const override; | 106 PaymentShippingType shipping_type() const override; |
| 105 | 107 |
| 106 // Returns the payments::CurrencyFormatter instance for this PaymentRequest. | 108 // Returns the payments::CurrencyFormatter instance for this PaymentRequest. |
| 107 // Note: Having multiple currencies per PaymentRequest flow is not supported; | 109 // Note: Having multiple currencies per PaymentRequest flow is not supported; |
| 108 // hence the CurrencyFormatter is cached here. | 110 // hence the CurrencyFormatter is cached here. |
| 109 payments::CurrencyFormatter* GetOrCreateCurrencyFormatter(); | 111 CurrencyFormatter* GetOrCreateCurrencyFormatter(); |
| 110 | 112 |
| 111 // Adds |profile| to the list of cached profiles, updates the list of | 113 // Adds |profile| to the list of cached profiles, updates the list of |
| 112 // available shipping and contact profiles, and returns a reference to the | 114 // available shipping and contact profiles, and returns a reference to the |
| 113 // cached copy of |profile|. | 115 // cached copy of |profile|. |
| 114 virtual autofill::AutofillProfile* AddAutofillProfile( | 116 virtual autofill::AutofillProfile* AddAutofillProfile( |
| 115 const autofill::AutofillProfile& profile); | 117 const autofill::AutofillProfile& profile); |
| 116 | 118 |
| 117 // Returns the available autofill profiles for this user to be used as | 119 // Returns the available autofill profiles for this user to be used as |
| 118 // shipping profiles. | 120 // shipping profiles. |
| 119 const std::vector<autofill::AutofillProfile*>& shipping_profiles() const { | 121 const std::vector<autofill::AutofillProfile*>& shipping_profiles() const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 return stringified_method_data_; | 165 return stringified_method_data_; |
| 164 } | 166 } |
| 165 | 167 |
| 166 const std::set<autofill::CreditCard::CardType>& supported_card_types_set() | 168 const std::set<autofill::CreditCard::CardType>& supported_card_types_set() |
| 167 const { | 169 const { |
| 168 return supported_card_types_set_; | 170 return supported_card_types_set_; |
| 169 } | 171 } |
| 170 | 172 |
| 171 // Creates and adds an AutofillPaymentInstrument, which makes a copy of | 173 // Creates and adds an AutofillPaymentInstrument, which makes a copy of |
| 172 // |credit_card|. | 174 // |credit_card|. |
| 173 virtual payments::AutofillPaymentInstrument* AddAutofillPaymentInstrument( | 175 virtual AutofillPaymentInstrument* AddAutofillPaymentInstrument( |
| 174 const autofill::CreditCard& credit_card); | 176 const autofill::CreditCard& credit_card); |
| 175 | 177 |
| 176 // Returns the available payment methods for this user that match a supported | 178 // Returns the available payment methods for this user that match a supported |
| 177 // type specified in |web_payment_request_|. | 179 // type specified in |web_payment_request_|. |
| 178 const std::vector<payments::PaymentInstrument*>& payment_methods() const { | 180 const std::vector<PaymentInstrument*>& payment_methods() const { |
| 179 return payment_methods_; | 181 return payment_methods_; |
| 180 } | 182 } |
| 181 | 183 |
| 182 // Returns the currently selected payment method for this PaymentRequest flow | 184 // Returns the currently selected payment method for this PaymentRequest flow |
| 183 // if there is one. Returns nullptr if there is no selected payment method. | 185 // if there is one. Returns nullptr if there is no selected payment method. |
| 184 payments::PaymentInstrument* selected_payment_method() const { | 186 PaymentInstrument* selected_payment_method() const { |
| 185 return selected_payment_method_; | 187 return selected_payment_method_; |
| 186 } | 188 } |
| 187 | 189 |
| 188 // Sets the currently selected payment method for this PaymentRequest flow. | 190 // Sets the currently selected payment method for this PaymentRequest flow. |
| 189 void set_selected_payment_method( | 191 void set_selected_payment_method(PaymentInstrument* payment_method) { |
| 190 payments::PaymentInstrument* payment_method) { | |
| 191 selected_payment_method_ = payment_method; | 192 selected_payment_method_ = payment_method; |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Returns the available shipping options from |web_payment_request_|. | 195 // Returns the available shipping options from |web_payment_request_|. |
| 195 const std::vector<web::PaymentShippingOption*>& shipping_options() const { | 196 const std::vector<web::PaymentShippingOption*>& shipping_options() const { |
| 196 return shipping_options_; | 197 return shipping_options_; |
| 197 } | 198 } |
| 198 | 199 |
| 199 // Returns the selected shipping option from |web_payment_request_| if there | 200 // Returns the selected shipping option from |web_payment_request_| if there |
| 200 // is one. Returns nullptr otherwise. | 201 // is one. Returns nullptr otherwise. |
| 201 web::PaymentShippingOption* selected_shipping_option() const { | 202 web::PaymentShippingOption* selected_shipping_option() const { |
| 202 return selected_shipping_option_; | 203 return selected_shipping_option_; |
| 203 } | 204 } |
| 204 | 205 |
| 205 virtual payments::PaymentsProfileComparator* profile_comparator(); | 206 virtual PaymentsProfileComparator* profile_comparator(); |
| 206 | 207 |
| 207 // Returns whether the current PaymentRequest can be used to make a payment. | 208 // Returns whether the current PaymentRequest can be used to make a payment. |
| 208 bool CanMakePayment() const; | 209 bool CanMakePayment() const; |
| 209 | 210 |
| 210 // Record the use of the data models that were used in the Payment Request. | 211 // Record the use of the data models that were used in the Payment Request. |
| 211 void RecordUseStats(); | 212 void RecordUseStats(); |
| 212 | 213 |
| 213 protected: | 214 protected: |
| 214 // Fetches the autofill profiles for this user from the PersonalDataManager, | 215 // Fetches the autofill profiles for this user from the PersonalDataManager, |
| 215 // and stores copies of them, owned by this PaymentRequest, in profile_cache_. | 216 // and stores copies of them, owned by this PaymentRequest, in profile_cache_. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 243 ios::ChromeBrowserState* browser_state_; | 244 ios::ChromeBrowserState* browser_state_; |
| 244 | 245 |
| 245 // Never null and outlives this object. | 246 // Never null and outlives this object. |
| 246 autofill::PersonalDataManager* personal_data_manager_; | 247 autofill::PersonalDataManager* personal_data_manager_; |
| 247 | 248 |
| 248 // The PaymentRequestUIDelegate as provided by the UI object that originally | 249 // The PaymentRequestUIDelegate as provided by the UI object that originally |
| 249 // created this PaymentRequest object. | 250 // created this PaymentRequest object. |
| 250 __weak id<PaymentRequestUIDelegate> payment_request_ui_delegate_; | 251 __weak id<PaymentRequestUIDelegate> payment_request_ui_delegate_; |
| 251 | 252 |
| 252 // The address normalizer to use for the duration of the Payment Request. | 253 // The address normalizer to use for the duration of the Payment Request. |
| 253 payments::AddressNormalizerImpl* address_normalizer_; | 254 AddressNormalizerImpl* address_normalizer_; |
| 254 | 255 |
| 255 // The currency formatter instance for this PaymentRequest flow. | 256 // The currency formatter instance for this PaymentRequest flow. |
| 256 std::unique_ptr<payments::CurrencyFormatter> currency_formatter_; | 257 std::unique_ptr<CurrencyFormatter> currency_formatter_; |
| 257 | 258 |
| 258 // Profiles returned by the Data Manager may change due to (e.g.) sync events, | 259 // Profiles returned by the Data Manager may change due to (e.g.) sync events, |
| 259 // meaning PaymentRequest may outlive them. Therefore, profiles are fetched | 260 // meaning PaymentRequest may outlive them. Therefore, profiles are fetched |
| 260 // once and their copies are cached here. Whenever profiles are requested a | 261 // once and their copies are cached here. Whenever profiles are requested a |
| 261 // vector of pointers to these copies are returned. | 262 // vector of pointers to these copies are returned. |
| 262 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; | 263 std::vector<std::unique_ptr<autofill::AutofillProfile>> profile_cache_; |
| 263 | 264 |
| 264 std::vector<autofill::AutofillProfile*> shipping_profiles_; | 265 std::vector<autofill::AutofillProfile*> shipping_profiles_; |
| 265 autofill::AutofillProfile* selected_shipping_profile_; | 266 autofill::AutofillProfile* selected_shipping_profile_; |
| 266 | 267 |
| 267 std::vector<autofill::AutofillProfile*> contact_profiles_; | 268 std::vector<autofill::AutofillProfile*> contact_profiles_; |
| 268 autofill::AutofillProfile* selected_contact_profile_; | 269 autofill::AutofillProfile* selected_contact_profile_; |
| 269 | 270 |
| 270 // Some payment methods, such as credit cards returned by the Data Manager, | 271 // Some payment methods, such as credit cards returned by the Data Manager, |
| 271 // may change due to (e.g.) sync events, meaning PaymentRequest may outlive | 272 // may change due to (e.g.) sync events, meaning PaymentRequest may outlive |
| 272 // them. Therefore, payment methods are fetched once and their copies are | 273 // them. Therefore, payment methods are fetched once and their copies are |
| 273 // cached here. Whenever payment methods are requested a vector of pointers to | 274 // cached here. Whenever payment methods are requested a vector of pointers to |
| 274 // these copies are returned. | 275 // these copies are returned. |
| 275 std::vector<std::unique_ptr<payments::PaymentInstrument>> | 276 std::vector<std::unique_ptr<PaymentInstrument>> payment_method_cache_; |
| 276 payment_method_cache_; | |
| 277 | 277 |
| 278 std::vector<payments::PaymentInstrument*> payment_methods_; | 278 std::vector<PaymentInstrument*> payment_methods_; |
| 279 payments::PaymentInstrument* selected_payment_method_; | 279 PaymentInstrument* selected_payment_method_; |
| 280 | 280 |
| 281 // A vector of supported basic card networks. This encompasses everything that | 281 // A vector of supported basic card networks. This encompasses everything that |
| 282 // the merchant supports and should be used for support checks. | 282 // the merchant supports and should be used for support checks. |
| 283 std::vector<std::string> supported_card_networks_; | 283 std::vector<std::string> supported_card_networks_; |
| 284 // A subset of |supported_card_networks_| which is only the networks that have | 284 // A subset of |supported_card_networks_| which is only the networks that have |
| 285 // been specified as part of the "basic-card" supported method. Callers should | 285 // been specified as part of the "basic-card" supported method. Callers should |
| 286 // use |supported_card_networks_| for merchant support checks. | 286 // use |supported_card_networks_| for merchant support checks. |
| 287 std::set<std::string> basic_card_specified_networks_; | 287 std::set<std::string> basic_card_specified_networks_; |
| 288 | 288 |
| 289 // A mapping of the payment method names to the corresponding JSON-stringified | 289 // A mapping of the payment method names to the corresponding JSON-stringified |
| 290 // payment method specific data. | 290 // payment method specific data. |
| 291 std::map<std::string, std::set<std::string>> stringified_method_data_; | 291 std::map<std::string, std::set<std::string>> stringified_method_data_; |
| 292 | 292 |
| 293 // The set of supported card types (e.g., credit, debit, prepaid). | 293 // The set of supported card types (e.g., credit, debit, prepaid). |
| 294 std::set<autofill::CreditCard::CardType> supported_card_types_set_; | 294 std::set<autofill::CreditCard::CardType> supported_card_types_set_; |
| 295 | 295 |
| 296 // A vector of pointers to the shipping options in |web_payment_request_|. | 296 // A vector of pointers to the shipping options in |web_payment_request_|. |
| 297 std::vector<web::PaymentShippingOption*> shipping_options_; | 297 std::vector<web::PaymentShippingOption*> shipping_options_; |
| 298 web::PaymentShippingOption* selected_shipping_option_; | 298 web::PaymentShippingOption* selected_shipping_option_; |
| 299 | 299 |
| 300 payments::PaymentsProfileComparator profile_comparator_; | 300 PaymentsProfileComparator profile_comparator_; |
| 301 | 301 |
| 302 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); | 302 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
| 303 }; | 303 }; |
| 304 | 304 |
| 305 } // namespace payments |
| 306 |
| 305 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ | 307 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ |
| OLD | NEW |