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/ui/payments/credit_card_edit_mediator.h" | 5 #import "ios/chrome/browser/ui/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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 21 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
22 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 22 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 | 24 |
25 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
26 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
27 #endif | 27 #endif |
28 | 28 |
29 namespace { | 29 namespace { |
30 using ::AutofillUITypeFromAutofillType; | 30 using ::AutofillUITypeFromAutofillType; |
31 using ::autofill::data_util::GetCardTypeForBasicCardPaymentType; | 31 using ::autofill::data_util::GetIssuerNetworkForBasicCardIssuerNetwork; |
32 using ::autofill::data_util::GetPaymentRequestData; | 32 using ::autofill::data_util::GetPaymentRequestData; |
33 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; | 33 using ::payment_request_util::GetBillingAddressLabelFromAutofillProfile; |
34 | 34 |
35 const CGFloat kCardTypeIconDimension = 20.0; | 35 const CGFloat kCardIssuerNetworkIconDimension = 20.0; |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 @interface CreditCardEditViewControllerMediator () | 38 @interface CreditCardEditViewControllerMediator () |
39 | 39 |
40 // The PaymentRequest object owning an instance of web::PaymentRequest as | 40 // The PaymentRequest object owning an instance of web::PaymentRequest as |
41 // 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 |
42 // pointer and should outlive this class. | 42 // pointer and should outlive this class. |
43 @property(nonatomic, assign) PaymentRequest* paymentRequest; | 43 @property(nonatomic, assign) PaymentRequest* paymentRequest; |
44 | 44 |
45 // The credit card to be edited, if any. This pointer is not owned by this class | 45 // The credit card to be edited, if any. This pointer is not owned by this class |
(...skipping 23 matching lines...) Expand all Loading... |
69 return self; | 69 return self; |
70 } | 70 } |
71 | 71 |
72 - (CollectionViewItem*)serverCardSummaryItem { | 72 - (CollectionViewItem*)serverCardSummaryItem { |
73 // Return nil if creating or editing a local card. | 73 // Return nil if creating or editing a local card. |
74 if (!_creditCard || autofill::IsCreditCardLocal(*_creditCard)) | 74 if (!_creditCard || autofill::IsCreditCardLocal(*_creditCard)) |
75 return nil; | 75 return nil; |
76 | 76 |
77 PaymentMethodItem* cardSummaryItem = [[PaymentMethodItem alloc] init]; | 77 PaymentMethodItem* cardSummaryItem = [[PaymentMethodItem alloc] init]; |
78 cardSummaryItem.methodID = | 78 cardSummaryItem.methodID = |
79 base::SysUTF16ToNSString(_creditCard->TypeAndLastFourDigits()); | 79 base::SysUTF16ToNSString(_creditCard->NetworkAndLastFourDigits()); |
80 cardSummaryItem.methodDetail = base::SysUTF16ToNSString( | 80 cardSummaryItem.methodDetail = base::SysUTF16ToNSString( |
81 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); | 81 _creditCard->GetRawInfo(autofill::CREDIT_CARD_NAME_FULL)); |
82 const int cardTypeIconID = | 82 const int issuerNetworkIconID = |
83 autofill::data_util::GetPaymentRequestData(_creditCard->type()) | 83 autofill::data_util::GetPaymentRequestData(_creditCard->network()) |
84 .icon_resource_id; | 84 .icon_resource_id; |
85 cardSummaryItem.methodTypeIcon = NativeImage(cardTypeIconID); | 85 cardSummaryItem.methodTypeIcon = NativeImage(issuerNetworkIconID); |
86 return cardSummaryItem; | 86 return cardSummaryItem; |
87 } | 87 } |
88 | 88 |
89 - (CollectionViewItem*)acceptedPaymentMethodsItem { | 89 - (CollectionViewItem*)acceptedPaymentMethodsItem { |
90 // Return nil if a server card is being edited. | 90 // Return nil if a server card is being edited. |
91 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard)) | 91 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard)) |
92 return nil; | 92 return nil; |
93 | 93 |
94 NSMutableArray* cardTypeIcons = [NSMutableArray array]; | 94 NSMutableArray* issuerNetworkIcons = [NSMutableArray array]; |
95 for (const auto& supportedNetwork : | 95 for (const auto& supportedNetwork : |
96 _paymentRequest->supported_card_networks()) { | 96 _paymentRequest->supported_card_networks()) { |
97 const std::string cardType = | 97 const std::string issuerNetwork = |
98 GetCardTypeForBasicCardPaymentType(supportedNetwork); | 98 GetIssuerNetworkForBasicCardIssuerNetwork(supportedNetwork); |
99 const autofill::data_util::PaymentRequestData& cardData = | 99 const autofill::data_util::PaymentRequestData& cardData = |
100 GetPaymentRequestData(cardType); | 100 GetPaymentRequestData(issuerNetwork); |
101 UIImage* cardTypeIcon = | 101 UIImage* issuerNetworkIcon = |
102 ResizeImage(NativeImage(cardData.icon_resource_id), | 102 ResizeImage(NativeImage(cardData.icon_resource_id), |
103 CGSizeMake(kCardTypeIconDimension, kCardTypeIconDimension), | 103 CGSizeMake(kCardIssuerNetworkIconDimension, |
| 104 kCardIssuerNetworkIconDimension), |
104 ProjectionMode::kAspectFillNoClipping); | 105 ProjectionMode::kAspectFillNoClipping); |
105 cardTypeIcon.accessibilityLabel = | 106 issuerNetworkIcon.accessibilityLabel = |
106 l10n_util::GetNSString(cardData.a11y_label_resource_id); | 107 l10n_util::GetNSString(cardData.a11y_label_resource_id); |
107 [cardTypeIcons addObject:cardTypeIcon]; | 108 [issuerNetworkIcons addObject:issuerNetworkIcon]; |
108 } | 109 } |
109 | 110 |
110 AcceptedPaymentMethodsItem* acceptedMethodsItem = | 111 AcceptedPaymentMethodsItem* acceptedMethodsItem = |
111 [[AcceptedPaymentMethodsItem alloc] init]; | 112 [[AcceptedPaymentMethodsItem alloc] init]; |
112 acceptedMethodsItem.message = | 113 acceptedMethodsItem.message = |
113 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); | 114 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); |
114 acceptedMethodsItem.methodTypeIcons = cardTypeIcons; | 115 acceptedMethodsItem.methodTypeIcons = issuerNetworkIcons; |
115 return acceptedMethodsItem; | 116 return acceptedMethodsItem; |
116 } | 117 } |
117 | 118 |
118 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { | 119 - (NSString*)billingAddressLabelForProfileWithGUID:(NSString*)profileGUID { |
119 DCHECK(profileGUID); | 120 DCHECK(profileGUID); |
120 autofill::AutofillProfile* profile = | 121 autofill::AutofillProfile* profile = |
121 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( | 122 autofill::PersonalDataManager::GetProfileFromProfilesByGUID( |
122 base::SysNSStringToUTF8(profileGUID), | 123 base::SysNSStringToUTF8(profileGUID), |
123 _paymentRequest->billing_profiles()); | 124 _paymentRequest->billing_profiles()); |
124 DCHECK(profile); | 125 DCHECK(profile); |
125 return GetBillingAddressLabelFromAutofillProfile(*profile); | 126 return GetBillingAddressLabelFromAutofillProfile(*profile); |
126 } | 127 } |
127 | 128 |
128 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber { | 129 - (UIImage*)cardTypeIconFromCardNumber:(NSString*)cardNumber { |
129 const char* cardType = autofill::CreditCard::GetCreditCardType( | 130 const char* issuerNetwork = autofill::CreditCard::GetCardNetwork( |
130 base::SysNSStringToUTF16(cardNumber)); | 131 base::SysNSStringToUTF16(cardNumber)); |
131 // This should not happen in Payment Request. | 132 // This should not happen in Payment Request. |
132 if (cardType == autofill::kGenericCard) | 133 if (issuerNetwork == autofill::kGenericCard) |
133 return nil; | 134 return nil; |
134 | 135 |
135 // Resize and return the card type icon. | 136 // Resize and return the card issuer network icon. |
136 int resourceID = | 137 int resourceID = autofill::data_util::GetPaymentRequestData(issuerNetwork) |
137 autofill::data_util::GetPaymentRequestData(cardType).icon_resource_id; | 138 .icon_resource_id; |
138 CGFloat dimension = kCardTypeIconDimension; | 139 CGFloat dimension = kCardIssuerNetworkIconDimension; |
139 return ResizeImage(NativeImage(resourceID), CGSizeMake(dimension, dimension), | 140 return ResizeImage(NativeImage(resourceID), CGSizeMake(dimension, dimension), |
140 ProjectionMode::kAspectFillNoClipping); | 141 ProjectionMode::kAspectFillNoClipping); |
141 } | 142 } |
142 | 143 |
143 - (NSArray<EditorField*>*)editorFields { | 144 - (NSArray<EditorField*>*)editorFields { |
144 return _editorFields; | 145 return _editorFields; |
145 } | 146 } |
146 | 147 |
147 #pragma mark - Helper methods | 148 #pragma mark - Helper methods |
148 | 149 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 [[EditorField alloc] | 193 [[EditorField alloc] |
193 initWithAutofillUIType:AutofillUITypeFromAutofillType( | 194 initWithAutofillUIType:AutofillUITypeFromAutofillType( |
194 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) | 195 autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR) |
195 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) | 196 label:l10n_util::GetNSString(IDS_PAYMENTS_EXP_YEAR) |
196 value:creditCardExpYear | 197 value:creditCardExpYear |
197 required:YES] | 198 required:YES] |
198 ]; | 199 ]; |
199 } | 200 } |
200 | 201 |
201 @end | 202 @end |
OLD | NEW |