| 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> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "components/autofill/core/browser/credit_card.h" | 16 #include "components/autofill/core/browser/credit_card.h" |
| 17 #include "components/payments/core/journey_logger.h" |
| 17 #include "components/payments/core/payment_options_provider.h" | 18 #include "components/payments/core/payment_options_provider.h" |
| 18 #include "components/payments/core/payment_request_base_delegate.h" | 19 #include "components/payments/core/payment_request_base_delegate.h" |
| 19 #include "components/payments/core/payments_profile_comparator.h" | 20 #include "components/payments/core/payments_profile_comparator.h" |
| 20 #include "ios/web/public/payments/payment_request.h" | 21 #include "ios/web/public/payments/payment_request.h" |
| 21 | 22 |
| 22 namespace autofill { | 23 namespace autofill { |
| 23 class AutofillProfile; | 24 class AutofillProfile; |
| 24 class PersonalDataManager; | 25 class PersonalDataManager; |
| 25 class RegionDataLoader; | 26 class RegionDataLoader; |
| 26 } // namespace autofill | 27 } // namespace autofill |
| 27 | 28 |
| 28 namespace payments { | 29 namespace payments { |
| 29 class AddressNormalizer; | 30 class AddressNormalizer; |
| 30 class AddressNormalizerImpl; | 31 class AddressNormalizerImpl; |
| 31 class CurrencyFormatter; | 32 class CurrencyFormatter; |
| 32 class PaymentInstrument; | 33 class PaymentInstrument; |
| 33 class AutofillPaymentInstrument; | 34 class AutofillPaymentInstrument; |
| 34 } // namespace payments | 35 } // namespace payments |
| 35 | 36 |
| 36 namespace ios { | 37 namespace ios { |
| 37 class ChromeBrowserState; | 38 class ChromeBrowserState; |
| 38 } // namepsace ios | 39 } // namepsace ios |
| 39 | 40 |
| 41 namespace web { |
| 42 class WebState; |
| 43 } // namespace web |
| 44 |
| 40 // A protocol implementd by any UI classes that the PaymentRequest object | 45 // A protocol implementd by any UI classes that the PaymentRequest object |
| 41 // needs to communicate with in order to perform certain actions such as | 46 // needs to communicate with in order to perform certain actions such as |
| 42 // initiating UI to request full card details for payment. | 47 // initiating UI to request full card details for payment. |
| 43 @protocol PaymentRequestUIDelegate<NSObject> | 48 @protocol PaymentRequestUIDelegate<NSObject> |
| 44 | 49 |
| 45 - (void) | 50 - (void) |
| 46 requestFullCreditCard:(const autofill::CreditCard&)creditCard | 51 requestFullCreditCard:(const autofill::CreditCard&)creditCard |
| 47 resultDelegate: | 52 resultDelegate: |
| 48 (base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>) | 53 (base::WeakPtr<autofill::payments::FullCardRequest::ResultDelegate>) |
| 49 resultDelegate; | 54 resultDelegate; |
| 50 | 55 |
| 51 @end | 56 @end |
| 52 | 57 |
| 53 namespace payments { | 58 namespace payments { |
| 54 | 59 |
| 55 // Has a copy of web::PaymentRequest as provided by the page invoking the | 60 // Has a copy of web::PaymentRequest as provided by the page invoking the |
| 56 // PaymentRequest API. Also caches credit cards and addresses provided by the | 61 // PaymentRequest API. Also caches credit cards and addresses provided by the |
| 57 // |personal_data_manager| and manages shared resources and user selections for | 62 // |personal_data_manager| and manages shared resources and user selections for |
| 58 // the current PaymentRequest flow. It must be initialized with a non-null | 63 // the current PaymentRequest flow. It must be initialized with non-null |
| 59 // instance of |personal_data_manager| that outlives this class. | 64 // instances of |browser_state|, |web_state|, and |personal_data_manager| that |
| 65 // outlive this class. |
| 60 class PaymentRequest : public PaymentOptionsProvider, | 66 class PaymentRequest : public PaymentOptionsProvider, |
| 61 public PaymentRequestBaseDelegate { | 67 public PaymentRequestBaseDelegate { |
| 62 public: | 68 public: |
| 63 // |personal_data_manager| should not be null and should outlive this object. | 69 // |personal_data_manager| should not be null and should outlive this object. |
| 64 PaymentRequest(const web::PaymentRequest& web_payment_request, | 70 PaymentRequest(const web::PaymentRequest& web_payment_request, |
| 65 ios::ChromeBrowserState* browser_state_, | 71 ios::ChromeBrowserState* browser_state, |
| 72 web::WebState* web_state, |
| 66 autofill::PersonalDataManager* personal_data_manager, | 73 autofill::PersonalDataManager* personal_data_manager, |
| 67 id<PaymentRequestUIDelegate> payment_request_ui_delegate); | 74 id<PaymentRequestUIDelegate> payment_request_ui_delegate); |
| 68 ~PaymentRequest() override; | 75 ~PaymentRequest() override; |
| 69 | 76 |
| 70 // PaymentRequestBaseDelegate: | 77 // PaymentRequestBaseDelegate: |
| 71 autofill::PersonalDataManager* GetPersonalDataManager() override; | 78 autofill::PersonalDataManager* GetPersonalDataManager() override; |
| 72 const std::string& GetApplicationLocale() const override; | 79 const std::string& GetApplicationLocale() const override; |
| 73 bool IsIncognito() const override; | 80 bool IsIncognito() const override; |
| 74 bool IsSslCertificateValid() override; | 81 bool IsSslCertificateValid() override; |
| 75 const GURL& GetLastCommittedURL() const override; | 82 const GURL& GetLastCommittedURL() const override; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 86 // Returns the web::PaymentRequest that was used to build this PaymentRequest. | 93 // Returns the web::PaymentRequest that was used to build this PaymentRequest. |
| 87 const web::PaymentRequest& web_payment_request() const { | 94 const web::PaymentRequest& web_payment_request() const { |
| 88 return web_payment_request_; | 95 return web_payment_request_; |
| 89 } | 96 } |
| 90 | 97 |
| 91 // Returns the payment details from |web_payment_request_|. | 98 // Returns the payment details from |web_payment_request_|. |
| 92 const web::PaymentDetails& payment_details() const { | 99 const web::PaymentDetails& payment_details() const { |
| 93 return web_payment_request_.details; | 100 return web_payment_request_.details; |
| 94 } | 101 } |
| 95 | 102 |
| 103 // Returns the JourneyLogger for this instance. |
| 104 const JourneyLogger& journey_logger() const { return journey_logger_; } |
| 105 |
| 96 // Updates the payment details of the |web_payment_request_|. It also updates | 106 // Updates the payment details of the |web_payment_request_|. It also updates |
| 97 // the cached references to the shipping options in |web_payment_request_| as | 107 // the cached references to the shipping options in |web_payment_request_| as |
| 98 // well as the reference to the selected shipping option. | 108 // well as the reference to the selected shipping option. |
| 99 void UpdatePaymentDetails(const web::PaymentDetails& details); | 109 void UpdatePaymentDetails(const web::PaymentDetails& details); |
| 100 | 110 |
| 101 // PaymentOptionsProvider: | 111 // PaymentOptionsProvider: |
| 102 bool request_shipping() const override; | 112 bool request_shipping() const override; |
| 103 bool request_payer_name() const override; | 113 bool request_payer_name() const override; |
| 104 bool request_payer_phone() const override; | 114 bool request_payer_phone() const override; |
| 105 bool request_payer_email() const override; | 115 bool request_payer_email() const override; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void SetSelectedShippingOption(); | 247 void SetSelectedShippingOption(); |
| 238 | 248 |
| 239 // The web::PaymentRequest object as provided by the page invoking the Payment | 249 // The web::PaymentRequest object as provided by the page invoking the Payment |
| 240 // Request API, owned by this object. | 250 // Request API, owned by this object. |
| 241 web::PaymentRequest web_payment_request_; | 251 web::PaymentRequest web_payment_request_; |
| 242 | 252 |
| 243 // Never null and outlives this object. | 253 // Never null and outlives this object. |
| 244 ios::ChromeBrowserState* browser_state_; | 254 ios::ChromeBrowserState* browser_state_; |
| 245 | 255 |
| 246 // Never null and outlives this object. | 256 // Never null and outlives this object. |
| 257 web::WebState* web_state_; |
| 258 |
| 259 // Never null and outlives this object. |
| 247 autofill::PersonalDataManager* personal_data_manager_; | 260 autofill::PersonalDataManager* personal_data_manager_; |
| 248 | 261 |
| 249 // The PaymentRequestUIDelegate as provided by the UI object that originally | 262 // The PaymentRequestUIDelegate as provided by the UI object that originally |
| 250 // created this PaymentRequest object. | 263 // created this PaymentRequest object. |
| 251 __weak id<PaymentRequestUIDelegate> payment_request_ui_delegate_; | 264 __weak id<PaymentRequestUIDelegate> payment_request_ui_delegate_; |
| 252 | 265 |
| 253 // The address normalizer to use for the duration of the Payment Request. | 266 // The address normalizer to use for the duration of the Payment Request. |
| 254 AddressNormalizerImpl* address_normalizer_; | 267 AddressNormalizerImpl* address_normalizer_; |
| 255 | 268 |
| 256 // The currency formatter instance for this PaymentRequest flow. | 269 // The currency formatter instance for this PaymentRequest flow. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 305 |
| 293 // The set of supported card types (e.g., credit, debit, prepaid). | 306 // The set of supported card types (e.g., credit, debit, prepaid). |
| 294 std::set<autofill::CreditCard::CardType> supported_card_types_set_; | 307 std::set<autofill::CreditCard::CardType> supported_card_types_set_; |
| 295 | 308 |
| 296 // A vector of pointers to the shipping options in |web_payment_request_|. | 309 // A vector of pointers to the shipping options in |web_payment_request_|. |
| 297 std::vector<web::PaymentShippingOption*> shipping_options_; | 310 std::vector<web::PaymentShippingOption*> shipping_options_; |
| 298 web::PaymentShippingOption* selected_shipping_option_; | 311 web::PaymentShippingOption* selected_shipping_option_; |
| 299 | 312 |
| 300 PaymentsProfileComparator profile_comparator_; | 313 PaymentsProfileComparator profile_comparator_; |
| 301 | 314 |
| 315 // Keeps track of different stats during the lifetime of this object. |
| 316 JourneyLogger journey_logger_; |
| 317 |
| 302 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); | 318 DISALLOW_COPY_AND_ASSIGN(PaymentRequest); |
| 303 }; | 319 }; |
| 304 | 320 |
| 305 } // namespace payments | 321 } // namespace payments |
| 306 | 322 |
| 307 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ | 323 #endif // IOS_CHROME_BROWSER_PAYMENTS_PAYMENT_REQUEST_H_ |
| OLD | NEW |