Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stripe element add new card #473

Merged
merged 14 commits into from
Nov 14, 2018
Merged
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Locales/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,4 @@
"updates_count_updates.zero" = "%{updates_count} updates";
"via_custom" = "via custom";
"via_external" = "via external";
"via_kickstarter" = "via Kickstarter";
"via_kickstarter" = "via Kickstarter";
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Locales/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,4 @@
"updates_count_updates.zero" = "%{updates_count} Updates";
"via_custom" = "Benutzerdefiniert";
"via_external" = "Extern";
"via_kickstarter" = "über Kickstarter";
"via_kickstarter" = "über Kickstarter";
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Locales/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,4 @@
"updates_count_updates.zero" = "%{updates_count} actualizaciones";
"via_custom" = "a través de personalizados";
"via_external" = "a través de externos";
"via_kickstarter" = "a través de Kickstarter";
"via_kickstarter" = "a través de Kickstarter";
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Locales/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,4 @@
"updates_count_updates.zero" = "%{updates_count} actus";
"via_custom" = "sites référents personnalisés";
"via_external" = "sites référents externes";
"via_kickstarter" = "Kickstarter";
"via_kickstarter" = "Kickstarter";
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Locales/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,4 @@
"updates_count_updates.zero" = "%{updates_count} 件のアップデート";
"via_custom" = "リファラー経由";
"via_external" = "外部を経由";
"via_kickstarter" = "kickstarterを経由";
"via_kickstarter" = "kickstarterを経由";
69 changes: 69 additions & 0 deletions Kickstarter-iOS/Views/Controllers/AddNewCardViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import KsApi
import Library
import Prelude
import ReactiveSwift
import Stripe
import UIKit

internal final class AddNewCardViewController: UIViewController, STPPaymentCardTextFieldDelegate {

private weak var saveButtonView: LoadingBarButtonItemView!
@IBOutlet private weak var cardholderNameLabel: UILabel!
@IBOutlet private weak var cardholderNameTextField: UITextField!
@IBOutlet private weak var paymentField: STPPaymentCardTextField!

internal static func instantiate() -> AddNewCardViewController {
return Storyboard.Settings.instantiate(AddNewCardViewController.self)
}

override func viewDidLoad() {
super.viewDidLoad()

let cancelButton = UIBarButtonItem(title: Strings.Cancel(),
style: .plain,
target: self,
action: #selector(cancelButtonTapped))
cancelButton.tintColor = .ksr_green_700
self.navigationItem.leftBarButtonItem = cancelButton

self.saveButtonView = LoadingBarButtonItemView.instantiate()
self.saveButtonView.setTitle(title: Strings.Save())
self.saveButtonView.addTarget(self, action: #selector(saveButtonTapped))
let navigationBarButton = UIBarButtonItem(customView: self.saveButtonView)
self.navigationItem.setRightBarButton(navigationBarButton, animated: false)

self.paymentField.delegate = self
}

override func bindStyles() {
super.bindStyles()

_ = self
|> settingsViewControllerStyle

_ = self.cardholderNameLabel
|> \.text %~ { _ in Strings.Cardholder_name() }
|> \.textColor .~ .ksr_text_dark_grey_900
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use settingsTitleLabelStyle so it's consistent with our other form fields in Settings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to use settingsSectionLabelStyle because we want the text color to be .ksr_text_dark_grey_900


_ = self.cardholderNameTextField
|> formFieldStyle
|> \.textAlignment .~ .right
|> \.attributedPlaceholder .~
NSAttributedString(string: Strings.Name(),
attributes: [NSAttributedString.Key.foregroundColor: UIColor.lightGray])

_ = self.paymentField
|> \.borderColor .~ nil
|> \.font .~ .ksr_body()
|> \.cursorColor .~ .ksr_green_700
|> \.textColor .~ .ksr_text_dark_grey_500
}

@objc fileprivate func cancelButtonTapped() {
self.dismiss(animated: true, completion: nil)
}

@objc fileprivate func saveButtonTapped() {
self.dismiss(animated: true, completion: nil)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Prelude
@testable import Kickstarter_Framework
@testable import KsApi
@testable import Library

final class AddNewCardViewControllerTests: TestCase {
override func setUp() {
super.setUp()
AppEnvironment.pushEnvironment(mainBundle: Bundle.framework)
UIView.setAnimationsEnabled(false)
}

func testAddNewCard() {
combos(Language.allLanguages, Device.allCases).forEach { language, device in
withEnvironment(language: language) {
let controller = AddNewCardViewController.instantiate()
let (parent, _) = traitControllers(device: device, orientation: .portrait, child: controller)

FBSnapshotVerifyView(parent.view, identifier: "lang_\(language)_device_\(device)")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ final class SettingsAccountViewController: UIViewController {
self?.tableView.reloadData()
}

self.viewModel.outputs.goToAddCard
.observeForControllerAction()
.observeValues { [weak self] in
self?.goToAddCard()
}

self.viewModel.outputs.presentCurrencyPicker
.observeForUI()
.observeValues { [weak self] in
Expand Down Expand Up @@ -83,6 +89,14 @@ final class SettingsAccountViewController: UIViewController {
|> settingsTableViewStyle
}

func goToAddCard() {
let vc = AddNewCardViewController.instantiate()
let nav = UINavigationController(rootViewController: vc)
nav.modalPresentationStyle = .formSheet

self.present(nav, animated: true, completion: nil)
}

private func showCurrencyPickerCell() {
self.tableView.beginUpdates()
self.tableView.insertRows(at: [self.dataSource.insertCurrencyPickerRow()], with: .top)
Expand Down