| 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" |
| 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/payments/core/payment_request_data_util.h" |
| 13 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
| 14 #include "ios/chrome/browser/application_context.h" | 15 #include "ios/chrome/browser/application_context.h" |
| 15 #include "ios/chrome/browser/payments/payment_request.h" | 16 #include "ios/chrome/browser/payments/payment_request.h" |
| 16 #import "ios/chrome/browser/payments/payment_request_util.h" | 17 #import "ios/chrome/browser/payments/payment_request_util.h" |
| 17 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" | 18 #import "ios/chrome/browser/ui/autofill/autofill_ui_type.h" |
| 18 #import "ios/chrome/browser/ui/payments/cells/accepted_payment_methods_item.h" | 19 #import "ios/chrome/browser/ui/payments/cells/accepted_payment_methods_item.h" |
| 19 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" | 20 #import "ios/chrome/browser/ui/payments/cells/payment_method_item.h" |
| 20 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" | 21 #import "ios/chrome/browser/ui/payments/payment_request_edit_consumer.h" |
| 21 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 22 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 22 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 23 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); | 147 l10n_util::GetNSString(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL); |
| 147 acceptedMethodsItem.methodTypeIcons = issuerNetworkIcons; | 148 acceptedMethodsItem.methodTypeIcons = issuerNetworkIcons; |
| 148 return acceptedMethodsItem; | 149 return acceptedMethodsItem; |
| 149 } | 150 } |
| 150 | 151 |
| 151 - (BOOL)shouldHideBackgroundForHeaderItem { | 152 - (BOOL)shouldHideBackgroundForHeaderItem { |
| 152 // YES if the header item displays the accepted payment method type icons. | 153 // YES if the header item displays the accepted payment method type icons. |
| 153 return !_creditCard || autofill::IsCreditCardLocal(*_creditCard); | 154 return !_creditCard || autofill::IsCreditCardLocal(*_creditCard); |
| 154 } | 155 } |
| 155 | 156 |
| 157 - (void)formatValueForEditorField:(EditorField*)field { |
| 158 if (field.autofillUIType == AutofillUITypeCreditCardNumber) { |
| 159 field.value = base::SysUTF16ToNSString( |
| 160 payments::data_util::FormatCardNumberForDisplay( |
| 161 base::SysNSStringToUTF16(field.value))); |
| 162 } |
| 163 } |
| 164 |
| 156 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { | 165 - (UIImage*)iconIdentifyingEditorField:(EditorField*)field { |
| 157 // Early return if the field is not the credit card number field. | 166 // Early return if the field is not the credit card number field. |
| 158 if (field.autofillUIType != AutofillUITypeCreditCardNumber) | 167 if (field.autofillUIType != AutofillUITypeCreditCardNumber) |
| 159 return nil; | 168 return nil; |
| 160 | 169 |
| 161 const char* issuerNetwork = autofill::CreditCard::GetCardNetwork( | 170 const char* issuerNetwork = autofill::CreditCard::GetCardNetwork( |
| 162 base::SysNSStringToUTF16(field.value)); | 171 base::SysNSStringToUTF16(field.value)); |
| 163 // This should not happen in Payment Request. | 172 // This should not happen in Payment Request. |
| 164 if (issuerNetwork == autofill::kGenericCard) | 173 if (issuerNetwork == autofill::kGenericCard) |
| 165 return nil; | 174 return nil; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 ? GetBillingAddressLabelFromAutofillProfile(*self.billingProfile) | 255 ? GetBillingAddressLabelFromAutofillProfile(*self.billingProfile) |
| 247 : nil; | 256 : nil; |
| 248 | 257 |
| 249 // Early return if editing a server card. For server cards, only the billing | 258 // Early return if editing a server card. For server cards, only the billing |
| 250 // address can be edited. | 259 // address can be edited. |
| 251 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard)) | 260 if (_creditCard && !autofill::IsCreditCardLocal(*_creditCard)) |
| 252 return @[ billingAddressField ]; | 261 return @[ billingAddressField ]; |
| 253 | 262 |
| 254 // Credit Card number field. | 263 // Credit Card number field. |
| 255 NSString* creditCardNumber = | 264 NSString* creditCardNumber = |
| 256 _creditCard ? base::SysUTF16ToNSString(_creditCard->number()) : nil; | 265 _creditCard ? base::SysUTF16ToNSString( |
| 266 payments::data_util::FormatCardNumberForDisplay( |
| 267 _creditCard->number())) |
| 268 : nil; |
| 257 fieldKey = [NSNumber numberWithInt:AutofillUITypeCreditCardNumber]; | 269 fieldKey = [NSNumber numberWithInt:AutofillUITypeCreditCardNumber]; |
| 258 EditorField* creditCardNumberField = self.fieldsMap[fieldKey]; | 270 EditorField* creditCardNumberField = self.fieldsMap[fieldKey]; |
| 259 if (!creditCardNumberField) { | 271 if (!creditCardNumberField) { |
| 260 creditCardNumberField = [[EditorField alloc] | 272 creditCardNumberField = [[EditorField alloc] |
| 261 initWithAutofillUIType:AutofillUITypeCreditCardNumber | 273 initWithAutofillUIType:AutofillUITypeCreditCardNumber |
| 262 fieldType:EditorFieldTypeTextField | 274 fieldType:EditorFieldTypeTextField |
| 263 label:l10n_util::GetNSString(IDS_PAYMENTS_CARD_NUMBER) | 275 label:l10n_util::GetNSString(IDS_PAYMENTS_CARD_NUMBER) |
| 264 value:creditCardNumber | 276 value:creditCardNumber |
| 265 required:YES]; | 277 required:YES]; |
| 266 [self.fieldsMap setObject:creditCardNumberField forKey:fieldKey]; | 278 [self.fieldsMap setObject:creditCardNumberField forKey:fieldKey]; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 value:@"YES" | 359 value:@"YES" |
| 348 required:YES]; | 360 required:YES]; |
| 349 [self.fieldsMap setObject:saveToChromeField forKey:fieldKey]; | 361 [self.fieldsMap setObject:saveToChromeField forKey:fieldKey]; |
| 350 } | 362 } |
| 351 [fields addObject:saveToChromeField]; | 363 [fields addObject:saveToChromeField]; |
| 352 | 364 |
| 353 return fields; | 365 return fields; |
| 354 } | 366 } |
| 355 | 367 |
| 356 @end | 368 @end |
| OLD | NEW |