| 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_coordinator.h" | 5 #import "ios/chrome/browser/ui/payments/credit_card_edit_coordinator.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/browser/autofill_type.h" | 11 #include "components/autofill/core/browser/autofill_type.h" |
| 12 #include "components/autofill/core/browser/credit_card.h" | 12 #include "components/autofill/core/browser/credit_card.h" |
| 13 #include "components/autofill/core/browser/personal_data_manager.h" | 13 #include "components/autofill/core/browser/personal_data_manager.h" |
| 14 #include "components/autofill/core/browser/validation.h" | 14 #include "components/autofill/core/browser/validation.h" |
| 15 #include "components/autofill/core/common/autofill_clock.h" | 15 #include "components/autofill/core/common/autofill_clock.h" |
| 16 #include "components/autofill/core/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
| 17 #import "components/autofill/ios/browser/credit_card_util.h" | 17 #import "components/autofill/ios/browser/credit_card_util.h" |
| 18 #include "components/payments/core/autofill_payment_instrument.h" | 18 #include "components/payments/core/autofill_payment_instrument.h" |
| 19 #include "components/payments/core/payment_instrument.h" | 19 #include "components/payments/core/payment_instrument.h" |
| 20 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 21 #include "ios/chrome/browser/application_context.h" | |
| 22 #include "ios/chrome/browser/payments/payment_request.h" | 21 #include "ios/chrome/browser/payments/payment_request.h" |
| 23 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" | 22 #import "ios/chrome/browser/ui/autofill/autofill_ui_type_util.h" |
| 24 #import "ios/chrome/browser/ui/payments/credit_card_edit_mediator.h" | 23 #import "ios/chrome/browser/ui/payments/credit_card_edit_mediator.h" |
| 25 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" | 24 #import "ios/chrome/browser/ui/payments/payment_request_editor_field.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 | 26 |
| 28 #if !defined(__has_feature) || !__has_feature(objc_arc) | 27 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 29 #error "This file requires ARC support." | 28 #error "This file requires ARC support." |
| 30 #endif | 29 #endif |
| 31 | 30 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 autofill::kSettingsOrigin); | 215 autofill::kSettingsOrigin); |
| 217 | 216 |
| 218 for (EditorField* field in fields) { | 217 for (EditorField* field in fields) { |
| 219 if (field.autofillUIType == AutofillUITypeCreditCardExpDate) { | 218 if (field.autofillUIType == AutofillUITypeCreditCardExpDate) { |
| 220 NSArray<NSString*>* fieldComponents = | 219 NSArray<NSString*>* fieldComponents = |
| 221 [field.value componentsSeparatedByString:@" / "]; | 220 [field.value componentsSeparatedByString:@" / "]; |
| 222 NSString* expMonth = fieldComponents[0]; | 221 NSString* expMonth = fieldComponents[0]; |
| 223 creditCard.SetInfo( | 222 creditCard.SetInfo( |
| 224 autofill::AutofillType(autofill::CREDIT_CARD_EXP_MONTH), | 223 autofill::AutofillType(autofill::CREDIT_CARD_EXP_MONTH), |
| 225 base::SysNSStringToUTF16(expMonth), | 224 base::SysNSStringToUTF16(expMonth), |
| 226 GetApplicationContext()->GetApplicationLocale()); | 225 _paymentRequest->GetApplicationLocale()); |
| 227 NSString* expYear = fieldComponents[1]; | 226 NSString* expYear = fieldComponents[1]; |
| 228 creditCard.SetInfo( | 227 creditCard.SetInfo( |
| 229 autofill::AutofillType(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR), | 228 autofill::AutofillType(autofill::CREDIT_CARD_EXP_4_DIGIT_YEAR), |
| 230 base::SysNSStringToUTF16(expYear), | 229 base::SysNSStringToUTF16(expYear), |
| 231 GetApplicationContext()->GetApplicationLocale()); | 230 _paymentRequest->GetApplicationLocale()); |
| 232 } else if (field.autofillUIType == AutofillUITypeCreditCardSaveToChrome) { | 231 } else if (field.autofillUIType == AutofillUITypeCreditCardSaveToChrome) { |
| 233 saveCreditCard = [field.value boolValue]; | 232 saveCreditCard = [field.value boolValue]; |
| 234 } else if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { | 233 } else if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { |
| 235 creditCard.set_billing_address_id(base::SysNSStringToUTF8(field.value)); | 234 creditCard.set_billing_address_id(base::SysNSStringToUTF8(field.value)); |
| 236 } else { | 235 } else { |
| 237 creditCard.SetInfo(autofill::AutofillType(AutofillTypeFromAutofillUIType( | 236 creditCard.SetInfo(autofill::AutofillType(AutofillTypeFromAutofillUIType( |
| 238 field.autofillUIType)), | 237 field.autofillUIType)), |
| 239 base::SysNSStringToUTF16(field.value), | 238 base::SysNSStringToUTF16(field.value), |
| 240 GetApplicationContext()->GetApplicationLocale()); | 239 _paymentRequest->GetApplicationLocale()); |
| 241 } | 240 } |
| 242 } | 241 } |
| 243 | 242 |
| 244 if (!_creditCard) { | 243 if (!_creditCard) { |
| 245 if (saveCreditCard) | 244 if (saveCreditCard) |
| 246 _paymentRequest->GetPersonalDataManager()->AddCreditCard(creditCard); | 245 _paymentRequest->GetPersonalDataManager()->AddCreditCard(creditCard); |
| 247 | 246 |
| 248 // Add the credit card to the list of payment methods in |_paymentRequest|. | 247 // Add the credit card to the list of payment methods in |_paymentRequest|. |
| 249 _paymentMethod = _paymentRequest->AddAutofillPaymentInstrument(creditCard); | 248 _paymentMethod = _paymentRequest->AddAutofillPaymentInstrument(creditCard); |
| 250 } else { | 249 } else { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 [self.addressEditCoordinator stop]; | 308 [self.addressEditCoordinator stop]; |
| 310 self.addressEditCoordinator = nil; | 309 self.addressEditCoordinator = nil; |
| 311 } | 310 } |
| 312 | 311 |
| 313 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { | 312 - (void)addressEditCoordinatorDidCancel:(AddressEditCoordinator*)coordinator { |
| 314 [self.addressEditCoordinator stop]; | 313 [self.addressEditCoordinator stop]; |
| 315 self.addressEditCoordinator = nil; | 314 self.addressEditCoordinator = nil; |
| 316 } | 315 } |
| 317 | 316 |
| 318 @end | 317 @end |
| OLD | NEW |