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/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
13 #import "base/values.h" | 15 #import "base/values.h" |
| 16 #include "components/autofill/core/browser/autofill_data_util.h" |
14 #include "components/autofill/core/browser/autofill_manager.h" | 17 #include "components/autofill/core/browser/autofill_manager.h" |
| 18 #include "components/autofill/core/browser/credit_card.h" |
15 #include "components/autofill/core/browser/personal_data_manager.h" | 19 #include "components/autofill/core/browser/personal_data_manager.h" |
16 #include "components/autofill/ios/browser/autofill_driver_ios.h" | 20 #include "components/autofill/ios/browser/autofill_driver_ios.h" |
17 #include "components/payments/core/payment_address.h" | 21 #include "components/payments/core/payment_address.h" |
| 22 #include "components/payments/core/payment_request_data_util.h" |
| 23 #include "ios/chrome/browser/application_context.h" |
18 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" | 24 #include "ios/chrome/browser/autofill/personal_data_manager_factory.h" |
19 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 25 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
20 #include "ios/chrome/browser/payments/payment_request.h" | 26 #include "ios/chrome/browser/payments/payment_request.h" |
21 #include "ios/chrome/browser/procedural_block_types.h" | 27 #include "ios/chrome/browser/procedural_block_types.h" |
22 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 28 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
23 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 29 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
24 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" | 30 #import "ios/chrome/browser/ui/commands/ios_command_ids.h" |
25 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" | 31 #import "ios/chrome/browser/ui/payments/js_payment_request_manager.h" |
26 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" | 32 #import "ios/chrome/browser/ui/payments/payment_request_coordinator.h" |
27 #include "ios/web/public/favicon_status.h" | 33 #include "ios/web/public/favicon_status.h" |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 DCHECK(mainWindow); | 559 DCHECK(mainWindow); |
554 GenericChromeCommand* command = | 560 GenericChromeCommand* command = |
555 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_AUTOFILL_SETTINGS]; | 561 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_AUTOFILL_SETTINGS]; |
556 [mainWindow chromeExecuteCommand:command]; | 562 [mainWindow chromeExecuteCommand:command]; |
557 }; | 563 }; |
558 | 564 |
559 [self terminateRequestWithErrorMessage:kCancelMessage callback:callback]; | 565 [self terminateRequestWithErrorMessage:kCancelMessage callback:callback]; |
560 } | 566 } |
561 | 567 |
562 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 568 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
563 didConfirmWithPaymentResponse:(web::PaymentResponse)paymentResponse { | 569 didCompletePaymentRequest:(PaymentRequest*)paymentRequest |
| 570 card:(const autofill::CreditCard&)card |
| 571 verificationCode:(const base::string16&)verificationCode { |
| 572 web::PaymentResponse paymentResponse; |
| 573 |
| 574 // If the merchant specified the card network as part of the "basic-card" |
| 575 // payment method, return "basic-card" as the method_name. Otherwise, return |
| 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 |
| 589 // 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 |
| 591 // copy the address, *billing_address_ptr can be used to get the basic card |
| 592 // response. |
| 593 if (!card.billing_address_id().empty()) { |
| 594 autofill::AutofillProfile* billingAddressPtr = |
| 595 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
| 596 card.billing_address_id(), paymentRequest->billing_profiles()); |
| 597 if (billingAddressPtr) |
| 598 billingAddress = *billingAddressPtr; |
| 599 } |
| 600 |
| 601 paymentResponse.details = |
| 602 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( |
| 603 card, verificationCode, billingAddress, |
| 604 GetApplicationContext()->GetApplicationLocale()); |
| 605 |
| 606 if (paymentRequest->request_shipping()) { |
| 607 autofill::AutofillProfile* shippingAddress = |
| 608 paymentRequest->selected_shipping_profile(); |
| 609 // TODO(crbug.com/602666): User should get here only if they have selected |
| 610 // a shipping address. |
| 611 DCHECK(shippingAddress); |
| 612 paymentResponse.shipping_address = |
| 613 payments::data_util::GetPaymentAddressFromAutofillProfile( |
| 614 *shippingAddress, GetApplicationContext()->GetApplicationLocale()); |
| 615 |
| 616 web::PaymentShippingOption* shippingOption = |
| 617 paymentRequest->selected_shipping_option(); |
| 618 DCHECK(shippingOption); |
| 619 paymentResponse.shipping_option = shippingOption->id; |
| 620 } |
| 621 |
| 622 if (paymentRequest->request_payer_name()) { |
| 623 autofill::AutofillProfile* contactInfo = |
| 624 paymentRequest->selected_contact_profile(); |
| 625 // TODO(crbug.com/602666): User should get here only if they have selected |
| 626 // a contact info. |
| 627 DCHECK(contactInfo); |
| 628 paymentResponse.payer_name = |
| 629 contactInfo->GetInfo(autofill::AutofillType(autofill::NAME_FULL), |
| 630 GetApplicationContext()->GetApplicationLocale()); |
| 631 } |
| 632 |
| 633 if (paymentRequest->request_payer_email()) { |
| 634 autofill::AutofillProfile* contactInfo = |
| 635 paymentRequest->selected_contact_profile(); |
| 636 // TODO(crbug.com/602666): User should get here only if they have selected |
| 637 // a contact info. |
| 638 DCHECK(contactInfo); |
| 639 paymentResponse.payer_email = |
| 640 contactInfo->GetRawInfo(autofill::EMAIL_ADDRESS); |
| 641 } |
| 642 |
| 643 if (paymentRequest->request_payer_phone()) { |
| 644 autofill::AutofillProfile* contactInfo = |
| 645 paymentRequest->selected_contact_profile(); |
| 646 // TODO(crbug.com/602666): User should get here only if they have selected |
| 647 // a contact info. |
| 648 DCHECK(contactInfo); |
| 649 paymentResponse.payer_phone = |
| 650 contactInfo->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER); |
| 651 } |
| 652 |
564 [_paymentRequestJsManager | 653 [_paymentRequestJsManager |
565 resolveRequestPromiseWithPaymentResponse:paymentResponse | 654 resolveRequestPromiseWithPaymentResponse:paymentResponse |
566 completionHandler:nil]; | 655 completionHandler:nil]; |
567 [self setUnblockEventQueueTimer]; | 656 [self setUnblockEventQueueTimer]; |
568 [self setPaymentResponseTimeoutTimer]; | 657 [self setPaymentResponseTimeoutTimer]; |
569 } | 658 } |
570 | 659 |
571 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator | 660 - (void)paymentRequestCoordinator:(PaymentRequestCoordinator*)coordinator |
572 didSelectShippingAddress:(payments::PaymentAddress)shippingAddress { | 661 didSelectShippingAddress:(payments::PaymentAddress)shippingAddress { |
573 [_paymentRequestJsManager updateShippingAddress:shippingAddress | 662 [_paymentRequestJsManager updateShippingAddress:shippingAddress |
(...skipping 13 matching lines...) Expand all Loading... |
587 #pragma mark - CRWWebStateObserver methods | 676 #pragma mark - CRWWebStateObserver methods |
588 | 677 |
589 - (void)webState:(web::WebState*)webState | 678 - (void)webState:(web::WebState*)webState |
590 didCommitNavigationWithDetails: | 679 didCommitNavigationWithDetails: |
591 (const web::LoadCommittedDetails&)load_details { | 680 (const web::LoadCommittedDetails&)load_details { |
592 [self dismissUI]; | 681 [self dismissUI]; |
593 [self enableCurrentWebState]; | 682 [self enableCurrentWebState]; |
594 } | 683 } |
595 | 684 |
596 @end | 685 @end |
OLD | NEW |