Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/payments/payment_request_manager.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_manager.h" |
| 6 | 6 |
| 7 #include "base/ios/block_types.h" | 7 #include "base/ios/block_types.h" |
| 8 #include "base/ios/ios_util.h" | 8 #include "base/ios/ios_util.h" |
| 9 #import "base/mac/bind_objc_block.h" | 9 #import "base/mac/bind_objc_block.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #import "base/values.h" | 15 #import "base/values.h" |
| 16 #include "components/autofill/core/browser/autofill_country.h" | |
| 16 #include "components/autofill/core/browser/autofill_data_util.h" | 17 #include "components/autofill/core/browser/autofill_data_util.h" |
| 17 #include "components/autofill/core/browser/autofill_manager.h" | 18 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/browser/credit_card.h" | 19 #include "components/autofill/core/browser/credit_card.h" |
| 19 #include "components/autofill/core/browser/personal_data_manager.h" | 20 #include "components/autofill/core/browser/personal_data_manager.h" |
| 20 #include "components/autofill/ios/browser/autofill_driver_ios.h" | 21 #include "components/autofill/ios/browser/autofill_driver_ios.h" |
| 22 #include "components/payments/core/address_normalization_manager.h" | |
| 23 #include "components/payments/core/address_normalizer_impl.h" | |
| 21 #include "components/payments/core/payment_address.h" | 24 #include "components/payments/core/payment_address.h" |
| 22 #include "components/payments/core/payment_request_data_util.h" | 25 #include "components/payments/core/payment_request_data_util.h" |
| 23 #include "ios/chrome/browser/application_context.h" | 26 #include "ios/chrome/browser/application_context.h" |
| 24 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 27 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
| 28 #include "ios/chrome/browser/autofill/validation_rules_storage_factory.h" | |
| 25 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 29 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 26 #include "ios/chrome/browser/payments/payment_request.h" | 30 #include "ios/chrome/browser/payments/payment_request.h" |
| 27 #include "ios/chrome/browser/procedural_block_types.h" | 31 #include "ios/chrome/browser/procedural_block_types.h" |
| 28 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 32 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 29 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 33 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 30 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" | 34 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 31 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" | 35 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" |
| 32 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" | 36 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" |
| 33 #include "ios/web/public/favicon_status.h" | 37 #include "ios/web/public/favicon_status.h" |
| 34 #include "ios/web/public/navigation_item.h" | 38 #include "ios/web/public/navigation_item.h" |
| 35 #include "ios/web/public/navigation_manager.h" | 39 #include "ios/web/public/navigation_manager.h" |
| 36 #include "ios/web/public/payments/payment_request.h" | 40 #include "ios/web/public/payments/payment_request.h" |
| 37 #include "ios/web/public/ssl_status.h" | 41 #include "ios/web/public/ssl_status.h" |
| 38 #import "ios/web/public/url_scheme_util.h" | 42 #import "ios/web/public/url_scheme_util.h" |
| 39 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 43 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 40 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" | 44 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" |
| 41 #include "ios/web/public/web_state/url_verification_constants.h" | 45 #include "ios/web/public/web_state/url_verification_constants.h" |
| 42 #include "ios/web/public/web_state/web_state.h" | 46 #include "ios/web/public/web_state/web_state.h" |
| 43 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 47 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
| 48 #include "third_party/libaddressinput/chromium/chrome_metadata_source.h" | |
| 49 #include "third_party/libaddressinput/chromium/chrome_storage_impl.h" | |
| 44 | 50 |
| 45 #if !defined(__has_feature) || !__has_feature(objc_arc) | 51 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 46 #error "This file requires ARC support." | 52 #error "This file requires ARC support." |
| 47 #endif | 53 #endif |
| 48 | 54 |
| 49 namespace { | 55 namespace { |
| 50 | 56 |
| 51 // Command prefix for injected JavaScript. | 57 // Command prefix for injected JavaScript. |
| 52 const char kCommandPrefix[] = "paymentRequest"; | 58 const char kCommandPrefix[] = "paymentRequest"; |
| 53 | 59 |
| 54 // Time interval between attempts to unblock the webview's JS event queue. | 60 // Time interval between attempts to unblock the webview's JS event queue. |
| 55 const NSTimeInterval kNoopInterval = 0.1; | 61 const NSTimeInterval kNoopInterval = 0.1; |
| 56 | 62 |
| 57 // Time interval before closing the UI if the page has not yet called | 63 // Time interval before closing the UI if the page has not yet called |
| 58 // PaymentResponse.complete(). | 64 // PaymentResponse.complete(). |
| 59 const NSTimeInterval kTimeoutInterval = 60.0; | 65 const NSTimeInterval kTimeoutInterval = 60.0; |
| 60 | 66 |
| 61 NSString* kAbortMessage = @"The payment request was aborted."; | 67 NSString* kAbortMessage = @"The payment request was aborted."; |
| 62 NSString* kCancelMessage = @"The payment request was canceled."; | 68 NSString* kCancelMessage = @"The payment request was canceled."; |
| 63 | 69 |
| 70 struct FullCard { | |
| 71 autofill::CreditCard creditCard; | |
| 72 base::string16 verificationCode; | |
| 73 autofill::AutofillProfile billingAddress; | |
| 74 }; | |
| 75 | |
| 64 } // namespace | 76 } // namespace |
| 65 | 77 |
| 66 @interface PaymentRequestManager ()<CRWWebStateObserver, | 78 @interface PaymentRequestManager ()<CRWWebStateObserver, |
| 67 PaymentRequestCoordinatorDelegate> { | 79 PaymentRequestCoordinatorDelegate> { |
| 68 // View controller used to present the PaymentRequest view controller. | 80 // View controller used to present the PaymentRequest view controller. |
| 69 __weak UIViewController* _baseViewController; | 81 __weak UIViewController* _baseViewController; |
| 70 | 82 |
| 71 // PersonalDataManager used to manage user credit cards and addresses. | 83 // PersonalDataManager used to manage user credit cards and addresses. |
| 72 autofill::PersonalDataManager* _personalDataManager; | 84 autofill::PersonalDataManager* _personalDataManager; |
| 73 | 85 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 97 // Timer used to periodically unblock the webview's JS event queue. | 109 // Timer used to periodically unblock the webview's JS event queue. |
| 98 NSTimer* _unblockEventQueueTimer; | 110 NSTimer* _unblockEventQueueTimer; |
| 99 | 111 |
| 100 // Timer used to complete the Payment Request flow and close the UI if the | 112 // Timer used to complete the Payment Request flow and close the UI if the |
| 101 // page does not call PaymentResponse.complete() in a timely fashion. | 113 // page does not call PaymentResponse.complete() in a timely fashion. |
| 102 NSTimer* _paymentResponseTimeoutTimer; | 114 NSTimer* _paymentResponseTimeoutTimer; |
| 103 | 115 |
| 104 // Timer used to cancel the Payment Request flow and close the UI if the | 116 // Timer used to cancel the Payment Request flow and close the UI if the |
| 105 // page does not settle the pending update promise in a timely fashion. | 117 // page does not settle the pending update promise in a timely fashion. |
| 106 NSTimer* _updateEventTimeoutTimer; | 118 NSTimer* _updateEventTimeoutTimer; |
| 119 | |
| 120 // AddressNormalizationManager used to normalize the various addresses (e.g. | |
| 121 // shipping, contact, billing). | |
| 122 std::unique_ptr<payments::AddressNormalizationManager> | |
| 123 _addressNormalizationManager; | |
| 124 | |
| 125 // Storage for the full card. | |
| 126 FullCard _fullCard; | |
| 107 } | 127 } |
| 108 | 128 |
| 109 // Object that manages JavaScript injection into the web view. | 129 // Object that manages JavaScript injection into the web view. |
| 110 @property(nonatomic, weak) JSPaymentRequestManager* paymentRequestJsManager; | 130 @property(nonatomic, weak) JSPaymentRequestManager* paymentRequestJsManager; |
| 111 | 131 |
| 112 // Synchronous method executed by -asynchronouslyEnablePaymentRequest: | 132 // Synchronous method executed by -asynchronouslyEnablePaymentRequest: |
| 113 - (void)doEnablePaymentRequest:(BOOL)enabled; | 133 - (void)doEnablePaymentRequest:(BOOL)enabled; |
| 114 | 134 |
| 115 // Terminates the pending request with an error message and dismisses the UI. | 135 // Terminates the pending request with an error message and dismisses the UI. |
| 116 // Invokes the callback once the request has been terminated. | 136 // Invokes the callback once the request has been terminated. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 128 // Handles invocations of PaymentRequest.abort(). Returns YES if the invocation | 148 // Handles invocations of PaymentRequest.abort(). Returns YES if the invocation |
| 129 // was successful. | 149 // was successful. |
| 130 - (BOOL)handleRequestAbort:(const base::DictionaryValue&)message; | 150 - (BOOL)handleRequestAbort:(const base::DictionaryValue&)message; |
| 131 | 151 |
| 132 // Handles invocations of PaymentRequest.canMakePayment(). Returns YES if the | 152 // Handles invocations of PaymentRequest.canMakePayment(). Returns YES if the |
| 133 // invocation was successful. | 153 // invocation was successful. |
| 134 - (BOOL)handleCanMakePayment:(const base::DictionaryValue&)message; | 154 - (BOOL)handleCanMakePayment:(const base::DictionaryValue&)message; |
| 135 | 155 |
| 136 // Called by |_updateEventTimeoutTimer|, displays an error message. Upon | 156 // Called by |_updateEventTimeoutTimer|, displays an error message. Upon |
| 137 // dismissal of the error message, cancels the Payment Request as if it was | 157 // dismissal of the error message, cancels the Payment Request as if it was |
| 138 // performend by the user. | 158 // performed by the user. |
| 139 - (BOOL)displayErrorThenCancelRequest; | 159 - (BOOL)displayErrorThenCancelRequest; |
| 140 | 160 |
| 141 // Called by |_paymentResponseTimeoutTimer|, invokes handleResponseComplete: | 161 // Called by |_paymentResponseTimeoutTimer|, invokes handleResponseComplete: |
| 142 // as if PaymentResponse.complete() was invoked with the default "unknown" | 162 // as if PaymentResponse.complete() was invoked with the default "unknown" |
| 143 // argument. | 163 // argument. |
| 144 - (BOOL)doResponseComplete; | 164 - (BOOL)doResponseComplete; |
| 145 | 165 |
| 146 // Handles invocations of PaymentResponse.complete(). Returns YES if the | 166 // Handles invocations of PaymentResponse.complete(). Returns YES if the |
| 147 // invocation was successful. | 167 // invocation was successful. |
| 148 - (BOOL)handleResponseComplete:(const base::DictionaryValue&)message; | 168 - (BOOL)handleResponseComplete:(const base::DictionaryValue&)message; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 162 // called with no arguments. | 182 // called with no arguments. |
| 163 - (void)setPaymentResponseTimeoutTimer; | 183 - (void)setPaymentResponseTimeoutTimer; |
| 164 | 184 |
| 165 // Establishes a timer that dismisses the Payment Request UI when it times out. | 185 // Establishes a timer that dismisses the Payment Request UI when it times out. |
| 166 // Per the spec, implementations may choose to consider a timeout for the | 186 // Per the spec, implementations may choose to consider a timeout for the |
| 167 // promise provided with the PaymentRequestUpdateEvent.updateWith() call. If the | 187 // promise provided with the PaymentRequestUpdateEvent.updateWith() call. If the |
| 168 // promise doesn't get settled in a reasonable amount of time, it is as if it | 188 // promise doesn't get settled in a reasonable amount of time, it is as if it |
| 169 // was rejected. | 189 // was rejected. |
| 170 - (void)setUpdateEventTimeoutTimer; | 190 - (void)setUpdateEventTimeoutTimer; |
| 171 | 191 |
| 192 // Called when the relevant addresses from a Payment Request have been | |
| 193 // normalized. Resolves the request promise with a PaymentResponse. | |
| 194 - (void)paymentRequestAddressNormalizationDidComplete; | |
| 195 | |
| 172 @end | 196 @end |
| 173 | 197 |
| 174 @implementation PaymentRequestManager | 198 @implementation PaymentRequestManager |
| 175 | 199 |
| 176 @synthesize enabled = _enabled; | 200 @synthesize enabled = _enabled; |
| 177 @synthesize webState = _webState; | 201 @synthesize webState = _webState; |
| 178 @synthesize browserState = _browserState; | 202 @synthesize browserState = _browserState; |
| 179 @synthesize paymentRequestJsManager = _paymentRequestJsManager; | 203 @synthesize paymentRequestJsManager = _paymentRequestJsManager; |
| 180 | 204 |
| 181 - (instancetype)initWithBaseViewController:(UIViewController*)viewController | 205 - (instancetype)initWithBaseViewController:(UIViewController*)viewController |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 } | 339 } |
| 316 if (command == "paymentRequest.responseComplete") { | 340 if (command == "paymentRequest.responseComplete") { |
| 317 return [self handleResponseComplete:JSONCommand]; | 341 return [self handleResponseComplete:JSONCommand]; |
| 318 } | 342 } |
| 319 if (command == "paymentRequest.updatePaymentDetails") { | 343 if (command == "paymentRequest.updatePaymentDetails") { |
| 320 return [self handleUpdatePaymentDetails:JSONCommand]; | 344 return [self handleUpdatePaymentDetails:JSONCommand]; |
| 321 } | 345 } |
| 322 return NO; | 346 return NO; |
| 323 } | 347 } |
| 324 | 348 |
| 349 - (void)startAddressNormalizer { | |
| 350 autofill::PersonalDataManager* personalDataManager = | |
| 351 _paymentRequest->GetPersonalDataManager(); | |
| 352 | |
| 353 std::unique_ptr<i18n::addressinput::Source> addressNormalizerSource = | |
| 354 base::MakeUnique<autofill::ChromeMetadataSource>( | |
| 355 I18N_ADDRESS_VALIDATION_DATA_URL, | |
| 356 personalDataManager->GetURLRequestContextGetter()); | |
| 357 | |
| 358 std::unique_ptr<i18n::addressinput::Storage> addressNormalizerStorage = | |
| 359 autofill::ValidationRulesStorageFactory::CreateStorage(); | |
| 360 | |
| 361 std::unique_ptr<payments::AddressNormalizer> addressNormalizer = | |
| 362 base::MakeUnique<payments::AddressNormalizerImpl>( | |
| 363 std::move(addressNormalizerSource), | |
| 364 std::move(addressNormalizerStorage)); | |
| 365 | |
| 366 // Kickoff the process of loading the rules (which is asynchronous) for each | |
| 367 // profile's country, to get faster address normalization later. | |
| 368 for (const autofill::AutofillProfile* profile : | |
| 369 personalDataManager->GetProfilesToSuggest()) { | |
| 370 std::string countryCode = | |
| 371 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | |
| 372 if (autofill::data_util::IsValidCountryCode(countryCode)) { | |
| 373 addressNormalizer->LoadRulesForRegion(countryCode); | |
| 374 } | |
| 375 } | |
| 376 | |
| 377 const std::string default_country_code = | |
| 378 autofill::AutofillCountry::CountryCodeForLocale( | |
| 379 GetApplicationContext()->GetApplicationLocale()); | |
| 380 | |
| 381 _addressNormalizationManager = | |
| 382 base::MakeUnique<payments::AddressNormalizationManager>( | |
| 383 std::move(addressNormalizer), default_country_code); | |
| 384 } | |
| 385 | |
| 325 // Ensures that |_paymentRequest| is set to the correct value for |message|. | 386 // Ensures that |_paymentRequest| is set to the correct value for |message|. |
| 326 // Returns YES if |_paymentRequest| was already set to the right value, or if it | 387 // Returns YES if |_paymentRequest| was already set to the right value, or if it |
| 327 // was updated to match |message|. | 388 // was updated to match |message|. |
| 328 - (BOOL)createPaymentRequestFromMessage:(const base::DictionaryValue&)message { | 389 - (BOOL)createPaymentRequestFromMessage:(const base::DictionaryValue&)message { |
| 329 const base::DictionaryValue* paymentRequestData; | 390 const base::DictionaryValue* paymentRequestData; |
| 330 web::PaymentRequest webPaymentRequest; | 391 web::PaymentRequest webPaymentRequest; |
| 331 if (!message.GetDictionary("payment_request", &paymentRequestData)) { | 392 if (!message.GetDictionary("payment_request", &paymentRequestData)) { |
| 332 DLOG(ERROR) << "JS message parameter 'payment_request' is missing"; | 393 DLOG(ERROR) << "JS message parameter 'payment_request' is missing"; |
| 333 return NO; | 394 return NO; |
| 334 } | 395 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 352 - (BOOL)handleRequestShow:(const base::DictionaryValue&)message { | 413 - (BOOL)handleRequestShow:(const base::DictionaryValue&)message { |
| 353 // TODO(crbug.com/602666): check that there's not already a pending request. | 414 // TODO(crbug.com/602666): check that there's not already a pending request. |
| 354 // TODO(crbug.com/602666): compare our supported payment types (i.e. autofill | 415 // TODO(crbug.com/602666): compare our supported payment types (i.e. autofill |
| 355 // credit card types) against the merchant supported types and return NO | 416 // credit card types) against the merchant supported types and return NO |
| 356 // if the intersection is empty. | 417 // if the intersection is empty. |
| 357 | 418 |
| 358 if (![self createPaymentRequestFromMessage:message]) { | 419 if (![self createPaymentRequestFromMessage:message]) { |
| 359 return NO; | 420 return NO; |
| 360 } | 421 } |
| 361 | 422 |
| 423 [self startAddressNormalizer]; | |
| 424 | |
| 362 UIImage* pageFavicon = nil; | 425 UIImage* pageFavicon = nil; |
| 363 web::NavigationItem* navigationItem = | 426 web::NavigationItem* navigationItem = |
| 364 [self webState]->GetNavigationManager()->GetVisibleItem(); | 427 [self webState]->GetNavigationManager()->GetVisibleItem(); |
| 365 if (navigationItem && !navigationItem->GetFavicon().image.IsEmpty()) | 428 if (navigationItem && !navigationItem->GetFavicon().image.IsEmpty()) |
| 366 pageFavicon = navigationItem->GetFavicon().image.ToUIImage(); | 429 pageFavicon = navigationItem->GetFavicon().image.ToUIImage(); |
| 367 NSString* pageTitle = base::SysUTF16ToNSString([self webState]->GetTitle()); | 430 NSString* pageTitle = base::SysUTF16ToNSString([self webState]->GetTitle()); |
| 368 NSString* pageHost = | 431 NSString* pageHost = |
| 369 base::SysUTF8ToNSString([self webState]->GetLastCommittedURL().host()); | 432 base::SysUTF8ToNSString([self webState]->GetLastCommittedURL().host()); |
| 370 autofill::AutofillManager* autofillManager = | 433 autofill::AutofillManager* autofillManager = |
| 371 autofill::AutofillDriverIOS::FromWebState(_webState)->autofill_manager(); | 434 autofill::AutofillDriverIOS::FromWebState(_webState)->autofill_manager(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 562 [mainWindow chromeExecuteCommand:command]; | 625 [mainWindow chromeExecuteCommand:command]; |
| 563 }; | 626 }; |
| 564 | 627 |
| 565 [self terminateRequestWithErrorMessage:kCancelMessage callback:callback]; | 628 [self terminateRequestWithErrorMessage:kCancelMessage callback:callback]; |
| 566 } | 629 } |
| 567 | 630 |
| 568 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 631 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
| 569 didCompletePaymentRequest:(PaymentRequest*)paymentRequest | 632 didCompletePaymentRequest:(PaymentRequest*)paymentRequest |
| 570 card:(const autofill::CreditCard&)card | 633 card:(const autofill::CreditCard&)card |
| 571 verificationCode:(const base::string16&)verificationCode { | 634 verificationCode:(const base::string16&)verificationCode { |
| 572 web::PaymentResponse paymentResponse; | 635 DCHECK_EQ(_paymentRequest.get(), paymentRequest); |
|
Moe
2017/05/17 18:12:38
nit: I prefer if |paymentRequest| wasn't part of t
macourteau
2017/05/17 19:15:16
Done.
| |
| 573 | 636 |
| 574 // If the merchant specified the card network as part of the "basic-card" | 637 _fullCard.creditCard = card; |
| 575 // payment method, return "basic-card" as the method_name. Otherwise, return | 638 _fullCard.verificationCode = verificationCode; |
| 576 // the name of the network directly. | |
| 577 std::string issuer_network = | |
| 578 autofill::data_util::GetPaymentRequestData(card.network()) | |
| 579 .basic_card_issuer_network; | |
| 580 paymentResponse.method_name = | |
| 581 paymentRequest->basic_card_specified_networks().find(issuer_network) != | |
| 582 paymentRequest->basic_card_specified_networks().end() | |
| 583 ? base::ASCIIToUTF16("basic-card") | |
| 584 : base::ASCIIToUTF16(issuer_network); | |
| 585 | |
| 586 // Get the billing address | |
| 587 autofill::AutofillProfile billingAddress; | |
| 588 | 639 |
| 589 // TODO(crbug.com/714768): Make sure the billing address is set and valid | 640 // TODO(crbug.com/714768): Make sure the billing address is set and valid |
| 590 // before getting here. Once the bug is addressed, there will be no need to | 641 // before getting here. Once the bug is addressed, there will be no need to |
| 591 // copy the address, *billing_address_ptr can be used to get the basic card | 642 // copy the address, *billing_address_ptr can be used to get the basic card |
| 592 // response. | 643 // response. |
| 593 if (!card.billing_address_id().empty()) { | 644 if (!card.billing_address_id().empty()) { |
| 594 autofill::AutofillProfile* billingAddressPtr = | 645 autofill::AutofillProfile* billingAddressPtr = |
| 595 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 646 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
| 596 card.billing_address_id(), paymentRequest->billing_profiles()); | 647 card.billing_address_id(), paymentRequest->billing_profiles()); |
| 597 if (billingAddressPtr) | 648 if (billingAddressPtr) { |
| 598 billingAddress = *billingAddressPtr; | 649 _fullCard.billingAddress = *billingAddressPtr; |
| 650 _addressNormalizationManager->StartNormalizingAddress( | |
| 651 &_fullCard.billingAddress); | |
| 652 } | |
| 599 } | 653 } |
| 600 | 654 |
| 655 if (_paymentRequest->request_shipping()) { | |
| 656 _addressNormalizationManager->StartNormalizingAddress( | |
| 657 _paymentRequest->selected_shipping_profile()); | |
| 658 } | |
| 659 | |
| 660 _addressNormalizationManager->StartNormalizingAddress( | |
| 661 _paymentRequest->selected_contact_profile()); | |
| 662 | |
| 663 __weak PaymentRequestManager* weakSelf = self; | |
| 664 _addressNormalizationManager->FinalizeWithCompletionCallback( | |
| 665 base::BindBlockArc(^(const payments::AddressNormalizationManager&) { | |
| 666 [weakSelf paymentRequestAddressNormalizationDidComplete]; | |
| 667 })); | |
| 668 } | |
| 669 | |
| 670 - (void)paymentRequestAddressNormalizationDidComplete { | |
| 671 web::PaymentResponse paymentResponse; | |
| 672 | |
| 673 // If the merchant specified the card network as part of the "basic-card" | |
| 674 // payment method, return "basic-card" as the method_name. Otherwise, return | |
| 675 // the name of the network directly. | |
| 676 std::string issuer_network = | |
| 677 autofill::data_util::GetPaymentRequestData(_fullCard.creditCard.network()) | |
| 678 .basic_card_issuer_network; | |
| 679 paymentResponse.method_name = | |
| 680 _paymentRequest->basic_card_specified_networks().find(issuer_network) != | |
| 681 _paymentRequest->basic_card_specified_networks().end() | |
| 682 ? base::ASCIIToUTF16("basic-card") | |
| 683 : base::ASCIIToUTF16(issuer_network); | |
| 684 | |
| 601 paymentResponse.details = | 685 paymentResponse.details = |
| 602 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( | 686 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( |
| 603 card, verificationCode, billingAddress, | 687 _fullCard.creditCard, _fullCard.verificationCode, |
| 688 _fullCard.billingAddress, | |
| 604 GetApplicationContext()->GetApplicationLocale()); | 689 GetApplicationContext()->GetApplicationLocale()); |
| 605 | 690 |
| 606 if (paymentRequest->request_shipping()) { | 691 if (_paymentRequest->request_shipping()) { |
| 607 autofill::AutofillProfile* shippingAddress = | 692 autofill::AutofillProfile* shippingAddress = |
| 608 paymentRequest->selected_shipping_profile(); | 693 _paymentRequest->selected_shipping_profile(); |
| 609 // TODO(crbug.com/602666): User should get here only if they have selected | 694 // TODO(crbug.com/602666): User should get here only if they have selected |
| 610 // a shipping address. | 695 // a shipping address. |
| 611 DCHECK(shippingAddress); | 696 DCHECK(shippingAddress); |
| 612 paymentResponse.shipping_address = | 697 paymentResponse.shipping_address = |
| 613 payments::data_util::GetPaymentAddressFromAutofillProfile( | 698 payments::data_util::GetPaymentAddressFromAutofillProfile( |
| 614 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); | 699 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); |
| 615 | 700 |
| 616 web::PaymentShippingOption* shippingOption = | 701 web::PaymentShippingOption* shippingOption = |
| 617 paymentRequest->selected_shipping_option(); | 702 _paymentRequest->selected_shipping_option(); |
| 618 DCHECK(shippingOption); | 703 DCHECK(shippingOption); |
| 619 paymentResponse.shipping_option = shippingOption->id; | 704 paymentResponse.shipping_option = shippingOption->id; |
| 620 } | 705 } |
| 621 | 706 |
| 622 if (paymentRequest->request_payer_name()) { | 707 if (_paymentRequest->request_payer_name()) { |
| 623 autofill::AutofillProfile* contactInfo = | 708 autofill::AutofillProfile* contactInfo = |
| 624 paymentRequest->selected_contact_profile(); | 709 _paymentRequest->selected_contact_profile(); |
| 625 // TODO(crbug.com/602666): User should get here only if they have selected | 710 // TODO(crbug.com/602666): User should get here only if they have selected |
| 626 // a contact info. | 711 // a contact info. |
| 627 DCHECK(contactInfo); | 712 DCHECK(contactInfo); |
| 628 paymentResponse.payer_name = | 713 paymentResponse.payer_name = |
| 629 contactInfo->GetInfo(autofill::AutofillType(autofill::NAME_FULL), | 714 contactInfo->GetInfo(autofill::AutofillType(autofill::NAME_FULL), |
| 630 GetApplicationContext()->GetApplicationLocale()); | 715 GetApplicationContext()->GetApplicationLocale()); |
| 631 } | 716 } |
| 632 | 717 |
| 633 if (paymentRequest->request_payer_email()) { | 718 if (_paymentRequest->request_payer_email()) { |
| 634 autofill::AutofillProfile* contactInfo = | 719 autofill::AutofillProfile* contactInfo = |
| 635 paymentRequest->selected_contact_profile(); | 720 _paymentRequest->selected_contact_profile(); |
| 636 // TODO(crbug.com/602666): User should get here only if they have selected | 721 // TODO(crbug.com/602666): User should get here only if they have selected |
| 637 // a contact info. | 722 // a contact info. |
| 638 DCHECK(contactInfo); | 723 DCHECK(contactInfo); |
| 639 paymentResponse.payer_email = | 724 paymentResponse.payer_email = |
| 640 contactInfo->GetRawInfo(autofill::EMAIL_ADDRESS); | 725 contactInfo->GetRawInfo(autofill::EMAIL_ADDRESS); |
| 641 } | 726 } |
| 642 | 727 |
| 643 if (paymentRequest->request_payer_phone()) { | 728 if (_paymentRequest->request_payer_phone()) { |
| 644 autofill::AutofillProfile* contactInfo = | 729 autofill::AutofillProfile* contactInfo = |
| 645 paymentRequest->selected_contact_profile(); | 730 _paymentRequest->selected_contact_profile(); |
| 646 // TODO(crbug.com/602666): User should get here only if they have selected | 731 // TODO(crbug.com/602666): User should get here only if they have selected |
| 647 // a contact info. | 732 // a contact info. |
| 648 DCHECK(contactInfo); | 733 DCHECK(contactInfo); |
| 649 paymentResponse.payer_phone = | 734 paymentResponse.payer_phone = |
| 650 contactInfo->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); | 735 contactInfo->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); |
| 651 } | 736 } |
| 652 | 737 |
| 653 [_paymentRequestJsManager | 738 [_paymentRequestJsManager |
| 654 resolveRequestPromiseWithPaymentResponse:paymentResponse | 739 resolveRequestPromiseWithPaymentResponse:paymentResponse |
| 655 completionHandler:nil]; | 740 completionHandler:nil]; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 676 #pragma mark - CRWWebStateObserver methods | 761 #pragma mark - CRWWebStateObserver methods |
| 677 | 762 |
| 678 - (void)webState:(web::WebState*)webState | 763 - (void)webState:(web::WebState*)webState |
| 679 didCommitNavigationWithDetails: | 764 didCommitNavigationWithDetails: |
| 680 (const web::LoadCommittedDetails&)load_details { | 765 (const web::LoadCommittedDetails&)load_details { |
| 681 [self dismissUI]; | 766 [self dismissUI]; |
| 682 [self enableCurrentWebState]; | 767 [self enableCurrentWebState]; |
| 683 } | 768 } |
| 684 | 769 |
| 685 @end | 770 @end |
| OLD | NEW |