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 #import "ios/chrome/browser/payments/credit_card_edit_mediator.h" | 5 #import "ios/chrome/browser/payments/credit_card_edit_mediator.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_data_util.h" | 8 #include "components/autofill/core/browser/autofill_data_util.h" |
9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
10 #include "components/autofill/core/browser/credit_card.h" | 10 #include "components/autofill/core/browser/credit_card.h" |
11 #include "components/autofill/core/browser/personal_data_manager.h" | 11 #include "components/autofill/core/browser/personal_data_manager.h" |
12 #import "components/autofill/ios/browser/credit_card_util.h" | 12 #import "components/autofill/ios/browser/credit_card_util.h" |
13 #include "components/strings/grit/components_strings.h" | 13 #include "components/strings/grit/components_strings.h" |
14 #include "ios/chrome/browser/application_context.h" | 14 #include "ios/chrome/browser/application_context.h" |
| 15 #import "ios/chrome/browser/payments/cells/accepted_payment_methods_item.h" |
15 #import "ios/chrome/browser/payments/cells/payment_method_item.h" | 16 #import "ios/chrome/browser/payments/cells/payment_method_item.h" |
16 #include "ios/chrome/browser/payments/payment_request.h" | 17 #include "ios/chrome/browser/payments/payment_request.h" |
17 #import "ios/chrome/browser/payments/payment_request_editor_field.h" | 18 #import "ios/chrome/browser/payments/payment_request_editor_field.h" |
18 #import "ios/chrome/browser/payments/payment_request_util.h" | 19 #import "ios/chrome/browser/payments/payment_request_util.h" |
19 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 20 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
20 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" | 21 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" |
21 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 22 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
25 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
26 #endif | 27 #endif |
27 | 28 |
28 namespace { | 29 namespace { |
29 using ::AutofillUITypeFromAutofillType; | 30 using ::AutofillUITypeFromAutofillType; |
| 31 using ::autofill::data_util::GetCardTypeForBasicCardPaymentType; |
| 32 using ::autofill::data_util::GetPaymentRequestData; |
30 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; | 33 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; |
31 | 34 |
32 const CGFloat kCardTypeIconDimension = 25.0; | 35 const CGFloat kCardTypeIconDimension = 25.0; |
33 } // namespace | 36 } // namespace |
34 | 37 |
35 @interface CreditCardEditViewControllerMediator () | 38 @interface CreditCardEditViewControllerMediator () |
36 | 39 |
37 // The PaymentRequest object owning an instance of web::PaymentRequest as | 40 // The PaymentRequest object owning an instance of web::PaymentRequest as |
38 // provided by the page invoking the Payment Request API. This is a weak | 41 // provided by the page invoking the Payment Request API. This is a weak |
39 // pointer and should outlive this class. | 42 // pointer and should outlive this class. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 base::SysUTF16ToNSString(_creditCard->TypeAndLastFourDigits()); | 77 base::SysUTF16ToNSString(_creditCard->TypeAndLastFourDigits()); |
75 cardSummaryItem.methodDetail = base::SysUTF16ToNSString( | 78 cardSummaryItem.methodDetail = base::SysUTF16ToNSString( |
76 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); | 79 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); |
77 const int cardTypeIconID = | 80 const int cardTypeIconID = |
78 autofill::data_util::GetPaymentRequestData(_creditCard->type()) | 81 autofill::data_util::GetPaymentRequestData(_creditCard->type()) |
79 .icon_resource_id; | 82 .icon_resource_id; |
80 cardSummaryItem.methodTypeIcon = NativeImage(cardTypeIconID); | 83 cardSummaryItem.methodTypeIcon = NativeImage(cardTypeIconID); |
81 return cardSummaryItem; | 84 return cardSummaryItem; |
82 } | 85 } |
83 | 86 |
| 87 - (CollectionViewItem*)acceptedPaymentMethodsItem { |
| 88 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard)) |
| 89 return nil; |
| 90 |
| 91 NSMutableArray* cardTypeIcons = [NSMutableArray array]; |
| 92 for (const auto& supportedNetwork : |
| 93 _paymentRequest->supported_card_networks()) { |
| 94 const std::string cardType = |
| 95 GetCardTypeForBasicCardPaymentType(supportedNetwork); |
| 96 int resourceID = GetPaymentRequestData(cardType).icon_resource_id; |
| 97 UIImage* cardTypeIcon = |
| 98 ResizeImage(NativeImage(resourceID), |
| 99 CGSizeMake(kCardTypeIconDimension, kCardTypeIconDimension), |
| 100 ProjectionMode::kAspectFillNoClipping); |
| 101 [cardTypeIcons addObject:cardTypeIcon]; |
| 102 } |
| 103 |
| 104 AcceptedPaymentMethodsItem* acceptedMethodsItem = |
| 105 [[AcceptedPaymentMethodsItem alloc] init]; |
| 106 acceptedMethodsItem.message = |
| 107 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); |
| 108 acceptedMethodsItem.methodTypeIcons = cardTypeIcons; |
| 109 return acceptedMethodsItem; |
| 110 } |
| 111 |
84 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { | 112 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { |
85 DCHECK(profileGUID); | 113 DCHECK(profileGUID); |
86 autofill::AutofillProfile* profile = | 114 autofill::AutofillProfile* profile = |
87 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 115 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
88 base::SysNSStringToUTF8(profileGUID), | 116 base::SysNSStringToUTF8(profileGUID), |
89 _paymentRequest->billing_profiles()); | 117 _paymentRequest->billing_profiles()); |
90 DCHECK(profile); | 118 DCHECK(profile); |
91 return GetBillingAddressLabelFromAutofillProfile(*profile); | 119 return GetBillingAddressLabelFromAutofillProfile(*profile); |
92 } | 120 } |
93 | 121 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 [[EditorField alloc] | 186 [[EditorField alloc] |
159 initWithAutofillUIType:AutofillUITypeFromAutofillType( | 187 initWithAutofillUIType:AutofillUITypeFromAutofillType( |
160 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) | 188 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) |
161 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) | 189 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) |
162 value:creditCardExpYear | 190 value:creditCardExpYear |
163 required:YES] | 191 required:YES] |
164 ]; | 192 ]; |
165 } | 193 } |
166 | 194 |
167 @end | 195 @end |
OLD | NEW |