Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
disable standalone ZIP screen, add billing ZIP panel to credit card d…
Browse files Browse the repository at this point in the history
…etails
  • Loading branch information
acjay authored and Alan Johnson committed Oct 12, 2015
1 parent 40b2265 commit 9429f04
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Kiosk/App/AppSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ class AppSetup {

var needsZipCode: Bool {
// If we're swiping with the card reaer, we don't need to collect a zip code.
return disableCardReader
return false
}
}
41 changes: 36 additions & 5 deletions Kiosk/Bid Fulfillment/ManualCreditCardInputViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ class ManualCreditCardInputViewController: UIViewController, RegistrationSubCont
@IBOutlet weak var expirationMonthTextField: TextField!
@IBOutlet weak var expirationYearTextField: TextField!
@IBOutlet weak var securitycodeTextField: TextField!
@IBOutlet weak var billingZipTextField: TextField!

@IBOutlet weak var cardNumberWrapperView: UIView!
@IBOutlet weak var expirationDateWrapperView: UIView!
@IBOutlet weak var expirationDateErrorLabel: UILabel!
@IBOutlet weak var securityCodeWrapperView: UIView!
@IBOutlet weak var securityCodeErrorLabel: UILabel!
@IBOutlet weak var billingZipWrapperView: UIView!
@IBOutlet weak var billingZipErrorLabel: UILabel!

@IBOutlet weak var cardConfirmButton: ActionButton!
@IBOutlet weak var dateConfirmButton: ActionButton!
@IBOutlet weak var securityCodeConfirmButton: ActionButton!
@IBOutlet weak var billingZipConfirmButton: ActionButton!

lazy var keys = EidolonKeys()

Expand All @@ -32,18 +34,19 @@ class ManualCreditCardInputViewController: UIViewController, RegistrationSubCont
super.viewDidLoad()
expirationDateWrapperView.hidden = true
securityCodeWrapperView.hidden = true
billingZipWrapperView.hidden = true

// We show the enter credit card number, then the date switching the views around
RAC(viewModel, "cardFullDigits") <~ cardNumberTextField.rac_textSignal()
RAC(viewModel, "expirationYear") <~ expirationYearTextField.rac_textSignal()
RAC(viewModel, "expirationMonth") <~ expirationMonthTextField.rac_textSignal()
RAC(viewModel, "securityCode") <~ securitycodeTextField.rac_textSignal()
RAC(viewModel, "billingZip") <~ billingZipTextField.rac_textSignal()

RAC(cardConfirmButton, "enabled") <~ viewModel.creditCardNumberIsValidSignal

securityCodeConfirmButton.rac_command = viewModel.registerButtonCommand()

RAC(securityCodeErrorLabel, "hidden") <~ securityCodeConfirmButton.rac_command.errors.take(1).mapReplace(false).startWith(true)
billingZipConfirmButton.rac_command = viewModel.registerButtonCommand()
RAC(billingZipErrorLabel, "hidden") <~ billingZipConfirmButton.rac_command.errors.take(1).mapReplace(false).startWith(true)

viewModel.moveToYearSignal.take(1).subscribeNext { [weak self] _ -> Void in
self?.expirationYearTextField.becomeFirstResponder()
Expand All @@ -61,6 +64,7 @@ class ManualCreditCardInputViewController: UIViewController, RegistrationSubCont
cardNumberWrapperView.hidden = true
expirationDateWrapperView.hidden = false
securityCodeWrapperView.hidden = true
billingZipWrapperView.hidden = true

expirationDateWrapperView.frame = CGRectMake(0, 0, CGRectGetWidth(expirationDateWrapperView.frame), CGRectGetHeight(expirationDateWrapperView.frame))

Expand All @@ -71,16 +75,29 @@ class ManualCreditCardInputViewController: UIViewController, RegistrationSubCont
cardNumberWrapperView.hidden = true
expirationDateWrapperView.hidden = true
securityCodeWrapperView.hidden = false
billingZipWrapperView.hidden = true

securityCodeWrapperView.frame = CGRectMake(0, 0, CGRectGetWidth(securityCodeWrapperView.frame), CGRectGetHeight(securityCodeWrapperView.frame))

securitycodeTextField.becomeFirstResponder()
}

@IBAction func securityCodeConfirmTapped(sender: AnyObject) {
cardNumberWrapperView.hidden = true
expirationDateWrapperView.hidden = true
securityCodeWrapperView.hidden = true
billingZipWrapperView.hidden = false

billingZipWrapperView.frame = CGRectMake(0, 0, CGRectGetWidth(billingZipWrapperView.frame), CGRectGetHeight(billingZipWrapperView.frame))

billingZipTextField.becomeFirstResponder()
}

@IBAction func backToCardNumber(sender: AnyObject) {
cardNumberWrapperView.hidden = false
expirationDateWrapperView.hidden = true
securityCodeWrapperView.hidden = true
billingZipWrapperView.hidden = true

cardNumberTextField.becomeFirstResponder()
}
Expand All @@ -89,10 +106,20 @@ class ManualCreditCardInputViewController: UIViewController, RegistrationSubCont
cardNumberWrapperView.hidden = true
expirationDateWrapperView.hidden = false
securityCodeWrapperView.hidden = true
billingZipWrapperView.hidden = true

expirationMonthTextField.becomeFirstResponder()
}

@IBAction func backToSecurityCode(sender: AnyObject) {
cardNumberWrapperView.hidden = true
expirationDateWrapperView.hidden = true
securityCodeWrapperView.hidden = false
billingZipWrapperView.hidden = true

securitycodeTextField.becomeFirstResponder()
}

class func instantiateFromStoryboard(storyboard: UIStoryboard) -> ManualCreditCardInputViewController {
return storyboard.viewControllerWithID(.ManualCardDetailsInput) as! ManualCreditCardInputViewController
}
Expand All @@ -113,6 +140,10 @@ private extension ManualCreditCardInputViewController {
securitycodeTextField.text = "123"
securitycodeTextField.sendActionsForControlEvents(.AllEditingEvents)
securityCodeConfirmButton.sendActionsForControlEvents(.TouchUpInside)

billingZipTextField.text = "10001"
billingZipTextField.sendActionsForControlEvents(.AllEditingEvents)
billingZipTextField.sendActionsForControlEvents(.TouchUpInside)
}

@IBAction func dev_creditCardOKTapped(sender: AnyObject) {
Expand Down
10 changes: 7 additions & 3 deletions Kiosk/Bid Fulfillment/ManualCreditCardInputViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ManualCreditCardInputViewModel: NSObject {
dynamic var expirationMonth = ""
dynamic var expirationYear = ""
dynamic var securityCode = ""
dynamic var billingZip = ""

private(set) var bidDetails: BidDetails!
private(set) var finishedSubject: RACSubject?
Expand Down Expand Up @@ -39,6 +40,10 @@ class ManualCreditCardInputViewModel: NSObject {
return RACObserve(self, "securityCode").map(isStringLengthIn(3..<5))
}

var billingZipIsValidSignal: RACSignal {
return RACObserve(self, "billingZip").map(isStringLengthIn(4..<8))
}

var moveToYearSignal: RACSignal {
return RACObserve(self, "expirationMonth").filter { (value) -> Bool in
return (value as! String).characters.count == 2
Expand All @@ -47,7 +52,7 @@ class ManualCreditCardInputViewModel: NSObject {

func registerButtonCommand() -> RACCommand {
let newUser = bidDetails.newUser
let enabled = RACSignal.combineLatest([creditCardNumberIsValidSignal, expiryDatesAreValidSignal, securityCodeIsValidSignal]).and()
let enabled = RACSignal.combineLatest([creditCardNumberIsValidSignal, expiryDatesAreValidSignal, securityCodeIsValidSignal, billingZipIsValidSignal]).and()
return RACCommand(enabled: enabled) { [weak self] _ in
(self?.registerCardSignal(newUser) ?? RACSignal.empty())?.doCompleted { () -> Void in
self?.finishedSubject?.sendCompleted()
Expand All @@ -69,9 +74,8 @@ class ManualCreditCardInputViewModel: NSObject {
private func registerCardSignal(newUser: NewUser) -> RACSignal {
let month = expirationMonth.toUIntWithDefault(0)
let year = expirationYear.toUIntWithDefault(0)
let postalCode = newUser.zipCode ?? ""

return stripeManager.registerCard(cardFullDigits, month: month, year: year, securityCode: securityCode, postalCode: postalCode).doNext() { (object) in
return stripeManager.registerCard(cardFullDigits, month: month, year: year, securityCode: securityCode, postalCode: billingZip).doNext() { (object) in
let token = object as! STPToken

newUser.creditCardName = token.card.name
Expand Down
Loading

0 comments on commit 9429f04

Please sign in to comment.