Commit 549612ea authored by Tanisha Mandre's avatar Tanisha Mandre Committed by Commit Bot

Add 'Add Payment Method' button to the Settings menu.

Add flag for add new payment method feature.

The button will navigate the user to a screen where the user can input credit card details, either manually or by using the camera. This callback function has not yet been implemented and will be implemented in a follow up CL.

Bug: 983987
Change-Id: I53b612cd03618eb787ec03fe56ca6e4e197c7a6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699806
Commit-Queue: Tanisha Mandre <tanishamandre@google.com>
Reviewed-by: default avatarEric Noyau <noyau@chromium.org>
Reviewed-by: default avatarJavier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678227}
parent 7e3dba32
...@@ -891,6 +891,9 @@ locale. The strings in this file are specific to iOS. ...@@ -891,6 +891,9 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_MANAGED_SWITCH_TITLE" desc="The title of the Switch from a managed account dialog. [40em]"> <message name="IDS_IOS_MANAGED_SWITCH_TITLE" desc="The title of the Switch from a managed account dialog. [40em]">
Sign out of managed account Sign out of managed account
</message> </message>
<message name="IDS_IOS_MANUAL_FALLBACK_ADD_PAYMENT_METHOD" desc="The title for the button in the manual fallback UI that takes the user to the add new credit card screen through settings. In this screen, the user can input their card details and save them.">
Add Payment Method...
</message>
<message name="IDS_IOS_MANUAL_FALLBACK_MANAGE_PASSWORDS" desc="The title for the button in the manual fallback UI that takes the user to the passwords settings. In this screen they see all the passwords and can erase them. Note it is different from IDS_IOS_MANUAL_FALLBACK_USE_OTHER_PASSWORD_WITH_DOTS [30em]"> <message name="IDS_IOS_MANUAL_FALLBACK_MANAGE_PASSWORDS" desc="The title for the button in the manual fallback UI that takes the user to the passwords settings. In this screen they see all the passwords and can erase them. Note it is different from IDS_IOS_MANUAL_FALLBACK_USE_OTHER_PASSWORD_WITH_DOTS [30em]">
Manage Passwords... Manage Passwords...
</message> </message>
......
...@@ -50,6 +50,7 @@ source_set("flags") { ...@@ -50,6 +50,7 @@ source_set("flags") {
"//ios/chrome/browser/ui/dialogs:feature_flags", "//ios/chrome/browser/ui/dialogs:feature_flags",
"//ios/chrome/browser/ui/fullscreen:feature_flags", "//ios/chrome/browser/ui/fullscreen:feature_flags",
"//ios/chrome/browser/ui/infobars:feature_flags", "//ios/chrome/browser/ui/infobars:feature_flags",
"//ios/chrome/browser/ui/settings/autofill:feature_flags",
"//ios/chrome/browser/ui/toolbar/public:feature_flags", "//ios/chrome/browser/ui/toolbar/public:feature_flags",
"//ios/chrome/browser/ui/toolbar_container:feature_flags", "//ios/chrome/browser/ui/toolbar_container:feature_flags",
"//ios/chrome/browser/web:feature_flags", "//ios/chrome/browser/web:feature_flags",
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#import "ios/chrome/browser/ui/dialogs/dialog_features.h" #import "ios/chrome/browser/ui/dialogs/dialog_features.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_features.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#include "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/toolbar/public/features.h" #import "ios/chrome/browser/ui/toolbar/public/features.h"
#import "ios/chrome/browser/ui/toolbar_container/toolbar_container_features.h" #import "ios/chrome/browser/ui/toolbar_container/toolbar_container_features.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h" #include "ios/chrome/browser/ui/ui_feature_flags.h"
...@@ -577,6 +578,10 @@ const flags_ui::FeatureEntry kFeatureEntries[] = { ...@@ -577,6 +578,10 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
flag_descriptions::kEnableAutofillSaveCardShowNoThanksDescription, flag_descriptions::kEnableAutofillSaveCardShowNoThanksDescription,
flags_ui::kOsIos, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(autofill::features::kAutofillSaveCardShowNoThanks)}, FEATURE_VALUE_TYPE(autofill::features::kAutofillSaveCardShowNoThanks)},
{"settings-add-payment-method",
flag_descriptions::kSettingsAddPaymentMethodName,
flag_descriptions::kSettingsAddPaymentMethodDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(kSettingsAddPaymentMethod)},
}; };
// Add all switches from experimental flags to |command_line|. // Add all switches from experimental flags to |command_line|.
......
...@@ -371,6 +371,12 @@ const char kSendUmaOverAnyNetwork[] = ...@@ -371,6 +371,12 @@ const char kSendUmaOverAnyNetwork[] =
const char kSendUmaOverAnyNetworkDescription[] = const char kSendUmaOverAnyNetworkDescription[] =
"When enabled, will send UMA data over either WiFi or cellular by default."; "When enabled, will send UMA data over either WiFi or cellular by default.";
const char kSettingsAddPaymentMethodName[] =
"Enable the add payment method button";
const char kSettingsAddPaymentMethodDescription[] =
"Allow a user to add a new credit card to payment methods from the "
"settings menu.";
const char kSettingsRefreshName[] = "Enable the UI Refresh for Settings"; const char kSettingsRefreshName[] = "Enable the UI Refresh for Settings";
const char kSettingsRefreshDescription[] = const char kSettingsRefreshDescription[] =
"Change the UI appearance of the settings to have something in phase with " "Change the UI appearance of the settings to have something in phase with "
......
...@@ -313,6 +313,10 @@ extern const char kSendTabToSelfShowSendingUIDescription[]; ...@@ -313,6 +313,10 @@ extern const char kSendTabToSelfShowSendingUIDescription[];
extern const char kSendUmaOverAnyNetwork[]; extern const char kSendUmaOverAnyNetwork[];
extern const char kSendUmaOverAnyNetworkDescription[]; extern const char kSendUmaOverAnyNetworkDescription[];
// Title and description for the flag to add a new credit card.
extern const char kSettingsAddPaymentMethodName[];
extern const char kSettingsAddPaymentMethodDescription[];
// Title and description for the flag to toggle the flag for the settings UI // Title and description for the flag to toggle the flag for the settings UI
// Refresh. // Refresh.
extern const char kSettingsRefreshName[]; extern const char kSettingsRefreshName[];
......
...@@ -18,6 +18,7 @@ source_set("autofill") { ...@@ -18,6 +18,7 @@ source_set("autofill") {
"autofill_profile_table_view_controller.mm", "autofill_profile_table_view_controller.mm",
] ]
deps = [ deps = [
":feature_flags",
"//components/autofill/core/browser", "//components/autofill/core/browser",
"//components/autofill/core/common", "//components/autofill/core/common",
"//components/autofill/ios/browser", "//components/autofill/ios/browser",
...@@ -38,10 +39,22 @@ source_set("autofill") { ...@@ -38,10 +39,22 @@ source_set("autofill") {
"//ios/chrome/browser/ui/table_view", "//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view/cells", "//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/ui/util", "//ios/chrome/browser/ui/util",
"//ios/chrome/common/colors",
"//ui/base", "//ui/base",
] ]
} }
source_set("feature_flags") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"features.h",
"features.mm",
]
deps = [
"//base",
]
}
source_set("unit_tests") { source_set("unit_tests") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
testonly = true testonly = true
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_credit_card_edit_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h" #import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h"
#import "ios/chrome/browser/ui/settings/autofill/features.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#include "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #include "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
#include "ios/chrome/browser/ui/ui_feature_flags.h" #include "ios/chrome/browser/ui/ui_feature_flags.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -72,10 +74,15 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -72,10 +74,15 @@ typedef NS_ENUM(NSInteger, ItemType) {
// stop the observer callback from acting on user-initiated changes. // stop the observer callback from acting on user-initiated changes.
@property(nonatomic, readwrite, assign) BOOL deletionInProgress; @property(nonatomic, readwrite, assign) BOOL deletionInProgress;
// Button to add a new credit card.
@property(nonatomic, strong) UIBarButtonItem* addPaymentMethodButton;
@end @end
@implementation AutofillCreditCardTableViewController @implementation AutofillCreditCardTableViewController
#pragma mark - ViewController Life Cycle.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
DCHECK(browserState); DCHECK(browserState);
UITableViewStyle style = base::FeatureList::IsEnabled(kSettingsRefresh) UITableViewStyle style = base::FeatureList::IsEnabled(kSettingsRefresh)
...@@ -101,12 +108,28 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -101,12 +108,28 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - UIViewController #pragma mark - UIViewController
- (NSArray<UIBarButtonItem*>*)toolbarItems {
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) {
UIBarButtonItem* flexibleSpace = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
return @[
self.deleteButton,
flexibleSpace,
self.addPaymentMethodButton,
];
}
return [super toolbarItems];
}
- (void)viewDidLoad { - (void)viewDidLoad {
[super viewDidLoad]; [super viewDidLoad];
self.tableView.allowsMultipleSelectionDuringEditing = YES; self.tableView.allowsMultipleSelectionDuringEditing = YES;
self.tableView.accessibilityIdentifier = kAutofillCreditCardTableViewId; self.tableView.accessibilityIdentifier = kAutofillCreditCardTableViewId;
base::RecordAction(base::UserMetricsAction("AutofillCreditCardsViewed")); base::RecordAction(base::UserMetricsAction("AutofillCreditCardsViewed"));
[self.deleteButton setEnabled:NO];
[self updateUIForEditState]; [self updateUIForEditState];
[self loadModel]; [self loadModel];
} }
...@@ -116,10 +139,25 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -116,10 +139,25 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (editing) { if (editing) {
[self setSwitchItemEnabled:NO itemType:ItemTypeAutofillCardSwitch]; [self setSwitchItemEnabled:NO itemType:ItemTypeAutofillCardSwitch];
} else { } else {
[self.deleteButton setEnabled:NO];
[self setSwitchItemEnabled:YES itemType:ItemTypeAutofillCardSwitch]; [self setSwitchItemEnabled:YES itemType:ItemTypeAutofillCardSwitch];
} }
} }
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) {
self.navigationController.toolbarHidden = NO;
}
}
- (BOOL)shouldHideToolbar {
if (base::FeatureList::IsEnabled(kSettingsAddPaymentMethod)) {
return NO;
}
return [super shouldHideToolbar];
}
#pragma mark - ChromeTableViewController #pragma mark - ChromeTableViewController
- (void)loadModel { - (void)loadModel {
...@@ -289,6 +327,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -289,6 +327,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
// edit mode, selection is handled by the superclass. When not in edit mode // edit mode, selection is handled by the superclass. When not in edit mode
// selection presents the editing controller for the selected entry. // selection presents the editing controller for the selected entry.
if (self.editing) { if (self.editing) {
[self.deleteButton setEnabled:YES];
return; return;
} }
...@@ -308,6 +347,16 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -308,6 +347,16 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self.navigationController pushViewController:controller animated:YES]; [self.navigationController pushViewController:controller animated:YES];
} }
- (void)tableView:(UITableView*)tableView
didDeselectRowAtIndexPath:(NSIndexPath*)indexPath {
[super tableView:tableView didDeselectRowAtIndexPath:indexPath];
if (!self.tableView.editing)
return;
if (self.tableView.indexPathsForSelectedRows.count == 0)
[self.deleteButton setEnabled:NO];
}
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
- (BOOL)tableView:(UITableView*)tableView - (BOOL)tableView:(UITableView*)tableView
...@@ -409,4 +458,16 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -409,4 +458,16 @@ typedef NS_ENUM(NSInteger, ItemType) {
_browserState->GetPrefs(), isEnabled); _browserState->GetPrefs(), isEnabled);
} }
- (UIBarButtonItem*)addPaymentMethodButton {
if (!_addPaymentMethodButton) {
_addPaymentMethodButton = [[UIBarButtonItem alloc]
initWithTitle:l10n_util::GetNSString(
IDS_IOS_MANUAL_FALLBACK_ADD_PAYMENT_METHOD)
style:UIBarButtonItemStylePlain
target:self
action:nil];
}
return _addPaymentMethodButton;
}
@end @end
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_FEATURES_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_FEATURES_H_
#import <Foundation/Foundation.h>
#include "base/feature_list.h"
// Add new credit card feature.
extern const base::Feature kSettingsAddPaymentMethod;
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_AUTOFILL_FEATURES_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/autofill/features.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const base::Feature kSettingsAddPaymentMethod{
"SettingsAddPaymentMethod", base::FEATURE_DISABLED_BY_DEFAULT};
...@@ -21,6 +21,9 @@ extern NSString* const kSettingsToolbarDeleteButtonId; ...@@ -21,6 +21,9 @@ extern NSString* const kSettingsToolbarDeleteButtonId;
: ChromeTableViewController <SettingsRootViewControlling, : ChromeTableViewController <SettingsRootViewControlling,
TableViewLinkHeaderFooterItemDelegate> TableViewLinkHeaderFooterItemDelegate>
// Delete button for the toolbar.
@property(nonatomic, strong, readonly) UIBarButtonItem* deleteButton;
// Whether this table view controller should hide the "Done" button (the right // Whether this table view controller should hide the "Done" button (the right
// navigation bar button). Default is NO. // navigation bar button). Default is NO.
@property(nonatomic, assign) BOOL shouldHideDoneButton; @property(nonatomic, assign) BOOL shouldHideDoneButton;
...@@ -42,6 +45,9 @@ extern NSString* const kSettingsToolbarDeleteButtonId; ...@@ -42,6 +45,9 @@ extern NSString* const kSettingsToolbarDeleteButtonId;
// following methods to customize the behavior. // following methods to customize the behavior.
@interface SettingsRootTableViewController (Subclassing) @interface SettingsRootTableViewController (Subclassing)
// Returns YES. Subclasses should overload this if a toolbar is required.
- (BOOL)shouldHideToolbar;
// Returns NO. Subclasses should overload this if an edit button is required. // Returns NO. Subclasses should overload this if an edit button is required.
- (BOOL)shouldShowEditButton; - (BOOL)shouldShowEditButton;
......
...@@ -73,7 +73,8 @@ NSString* const kSettingsToolbarDeleteButtonId = ...@@ -73,7 +73,8 @@ NSString* const kSettingsToolbarDeleteButtonId =
return; return;
} }
[self.navigationController setToolbarHidden:YES animated:YES]; [self.navigationController setToolbarHidden:self.shouldHideToolbar
animated:YES];
if (self.shouldShowEditButton) { if (self.shouldShowEditButton) {
self.navigationItem.rightBarButtonItem = [self createEditButton]; self.navigationItem.rightBarButtonItem = [self createEditButton];
} else { } else {
...@@ -151,7 +152,8 @@ NSString* const kSettingsToolbarDeleteButtonId = ...@@ -151,7 +152,8 @@ NSString* const kSettingsToolbarDeleteButtonId =
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated]; [super setEditing:editing animated:animated];
if (!editing) if (!editing)
[self.navigationController setToolbarHidden:YES animated:YES]; [self.navigationController setToolbarHidden:self.shouldHideToolbar
animated:YES];
} }
- (void)viewDidLayoutSubviews { - (void)viewDidLayoutSubviews {
...@@ -181,7 +183,8 @@ NSString* const kSettingsToolbarDeleteButtonId = ...@@ -181,7 +183,8 @@ NSString* const kSettingsToolbarDeleteButtonId =
return; return;
if (self.tableView.indexPathsForSelectedRows.count == 0) if (self.tableView.indexPathsForSelectedRows.count == 0)
[self.navigationController setToolbarHidden:YES animated:YES]; [self.navigationController setToolbarHidden:self.shouldHideToolbar
animated:YES];
} }
- (CGFloat)tableView:(UITableView*)tableView - (CGFloat)tableView:(UITableView*)tableView
...@@ -247,6 +250,10 @@ NSString* const kSettingsToolbarDeleteButtonId = ...@@ -247,6 +250,10 @@ NSString* const kSettingsToolbarDeleteButtonId =
#pragma mark - Subclassing #pragma mark - Subclassing
- (BOOL)shouldHideToolbar {
return YES;
}
- (BOOL)shouldShowEditButton { - (BOOL)shouldShowEditButton {
return NO; return NO;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment