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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 if (error_message) { | 58 if (error_message) { |
59 *error_message = l10n_util::GetStringUTF16( | 59 *error_message = l10n_util::GetStringUTF16( |
60 IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER); | 60 IDS_PAYMENTS_VALIDATION_ALREADY_USED_CREDIT_CARD_NUMBER); |
61 } | 61 } |
62 return false; | 62 return false; |
63 } | 63 } |
64 | 64 |
65 } // namespace | 65 } // namespace |
66 | 66 |
67 @interface CreditCardEditCoordinator () { | 67 @interface CreditCardEditCoordinator () { |
68 CreditCardEditViewController* _viewController; | 68 PaymentRequestEditViewController* _viewController; |
69 | 69 |
70 CreditCardEditViewControllerMediator* _mediator; | 70 CreditCardEditViewControllerMediator* _mediator; |
71 } | 71 } |
72 | 72 |
73 @end | 73 @end |
74 | 74 |
75 @implementation CreditCardEditCoordinator | 75 @implementation CreditCardEditCoordinator |
76 | 76 |
77 @synthesize creditCard = _creditCard; | 77 @synthesize creditCard = _creditCard; |
78 @synthesize paymentRequest = _paymentRequest; | 78 @synthesize paymentRequest = _paymentRequest; |
79 @synthesize delegate = _delegate; | 79 @synthesize delegate = _delegate; |
80 | 80 |
81 - (void)start { | 81 - (void)start { |
82 _viewController = [[CreditCardEditViewController alloc] init]; | 82 _viewController = [[PaymentRequestEditViewController alloc] init]; |
83 // TODO(crbug.com/602666): Title varies depending on the missing fields. | 83 // TODO(crbug.com/602666): Title varies depending on the missing fields. |
84 NSString* title = _creditCard | 84 NSString* title = _creditCard |
85 ? l10n_util::GetNSString(IDS_PAYMENTS_EDIT_CARD) | 85 ? l10n_util::GetNSString(IDS_PAYMENTS_EDIT_CARD) |
86 : l10n_util::GetNSString(IDS_PAYMENTS_ADD_CARD_LABEL); | 86 : l10n_util::GetNSString(IDS_PAYMENTS_ADD_CARD_LABEL); |
87 [_viewController setTitle:title]; | 87 [_viewController setTitle:title]; |
88 [_viewController setDelegate:self]; | 88 [_viewController setDelegate:self]; |
89 [_viewController setValidatorDelegate:self]; | 89 [_viewController setValidatorDelegate:self]; |
90 _mediator = [[CreditCardEditViewControllerMediator alloc] | 90 _mediator = [[CreditCardEditViewControllerMediator alloc] |
91 initWithPaymentRequest:_paymentRequest | 91 initWithPaymentRequest:_paymentRequest |
92 creditCard:_creditCard]; | 92 creditCard:_creditCard]; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 &errorMessage); | 125 &errorMessage); |
126 } | 126 } |
127 return !errorMessage.empty() ? base::SysUTF16ToNSString(errorMessage) : nil; | 127 return !errorMessage.empty() ? base::SysUTF16ToNSString(errorMessage) : nil; |
128 } else if (field.isRequired) { | 128 } else if (field.isRequired) { |
129 return l10n_util::GetNSString( | 129 return l10n_util::GetNSString( |
130 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 130 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
131 } | 131 } |
132 return nil; | 132 return nil; |
133 } | 133 } |
134 | 134 |
135 #pragma mark - CreditCardEditViewControllerDelegate | 135 #pragma mark - PaymentRequestEditViewControllerDelegate |
136 | 136 |
137 - (void)paymentRequestEditViewController: | 137 - (void)paymentRequestEditViewController: |
138 (PaymentRequestEditViewController*)controller | 138 (PaymentRequestEditViewController*)controller |
139 didSelectField:(EditorField*)field { | 139 didSelectField:(EditorField*)field { |
140 if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { | 140 if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { |
141 // TODO(crbug.com/602666): Display a list of billing addresses. | 141 // TODO(crbug.com/602666): Display a list of billing addresses. |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 - (void)creditCardEditViewController:(CreditCardEditViewController*)controller | 145 - (void)paymentRequestEditViewController: |
146 didFinishEditingFields:(NSArray<EditorField*>*)fields | 146 (PaymentRequestEditViewController*)controller |
147 saveCreditCard:(BOOL)saveCreditCard { | 147 didFinishEditingFields:(NSArray<EditorField*>*)fields { |
| 148 BOOL saveCreditCard = NO; |
148 // Create an empty credit card. If a credit card is being edited, copy over | 149 // Create an empty credit card. If a credit card is being edited, copy over |
149 // the information. | 150 // the information. |
150 autofill::CreditCard creditCard = | 151 autofill::CreditCard creditCard = |
151 _creditCard ? *_creditCard | 152 _creditCard ? *_creditCard |
152 : autofill::CreditCard(base::GenerateGUID(), | 153 : autofill::CreditCard(base::GenerateGUID(), |
153 autofill::kSettingsOrigin); | 154 autofill::kSettingsOrigin); |
154 | 155 |
155 for (EditorField* field in fields) { | 156 for (EditorField* field in fields) { |
156 if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { | 157 if (field.autofillUIType == AutofillUITypeCreditCardSaveToChrome) { |
| 158 saveCreditCard = [field.value boolValue]; |
| 159 } else if (field.autofillUIType == AutofillUITypeCreditCardBillingAddress) { |
157 creditCard.set_billing_address_id(base::SysNSStringToUTF8(field.value)); | 160 creditCard.set_billing_address_id(base::SysNSStringToUTF8(field.value)); |
158 } else { | 161 } else { |
159 creditCard.SetRawInfo( | 162 creditCard.SetRawInfo( |
160 AutofillTypeFromAutofillUIType(field.autofillUIType), | 163 AutofillTypeFromAutofillUIType(field.autofillUIType), |
161 base::SysNSStringToUTF16(field.value)); | 164 base::SysNSStringToUTF16(field.value)); |
162 } | 165 } |
163 } | 166 } |
164 | 167 |
165 if (!_creditCard) { | 168 if (!_creditCard) { |
166 if (saveCreditCard) | 169 if (saveCreditCard) |
(...skipping 14 matching lines...) Expand all Loading... |
181 // Update server credit card's billing address. | 184 // Update server credit card's billing address. |
182 _paymentRequest->GetPersonalDataManager()->UpdateServerCardMetadata( | 185 _paymentRequest->GetPersonalDataManager()->UpdateServerCardMetadata( |
183 creditCard); | 186 creditCard); |
184 } | 187 } |
185 } | 188 } |
186 | 189 |
187 [_delegate creditCardEditCoordinator:self | 190 [_delegate creditCardEditCoordinator:self |
188 didFinishEditingCreditCard:_creditCard]; | 191 didFinishEditingCreditCard:_creditCard]; |
189 } | 192 } |
190 | 193 |
191 - (void)creditCardEditViewControllerDidCancel: | 194 - (void)paymentRequestEditViewControllerDidCancel: |
192 (CreditCardEditViewController*)controller { | 195 (PaymentRequestEditViewController*)controller { |
193 [_delegate creditCardEditCoordinatorDidCancel:self]; | 196 [_delegate creditCardEditCoordinatorDidCancel:self]; |
194 } | 197 } |
195 | 198 |
196 @end | 199 @end |
OLD | NEW |