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

Add credit card implementation #503

Merged
merged 25 commits into from Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e3cd226
Email undeliverable/unverified (#478)
ifbarrera Nov 12, 2018
e9a1005
Use correct function to log events in crash logs (#481)
justinswart Nov 14, 2018
44ff603
Merge remote-tracking branch 'oss/feature-payment-methods' into add-c…
cdolm92 Nov 14, 2018
cc49f7c
changed ui colors for textfield text and font size of text label
cdolm92 Nov 14, 2018
01083af
vm and work on enabling save
cdolm92 Nov 15, 2018
1859e8c
wip- get stripe token
cdolm92 Nov 20, 2018
6f9dd6f
wip- payment source mutation
cdolm92 Nov 26, 2018
b066666
wip- keyboard response
cdolm92 Nov 27, 2018
8e98ec6
wip- getting a stripe error here
cdolm92 Nov 27, 2018
3237915
wip- error fix w/ publishable key, error banner showing
cdolm92 Nov 28, 2018
06cafc2
wip- saving with error and keyboard functionality
cdolm92 Nov 29, 2018
654102a
wip- updating card immediately
cdolm92 Nov 29, 2018
98d07de
wip
cdolm92 Nov 29, 2018
a6144aa
Merge remote-tracking branch 'oss/feature-payment-methods' into add-c…
cdolm92 Nov 29, 2018
fb3b702
wip - ACs met
cdolm92 Nov 29, 2018
0a221f0
wip - refactor in view model, made IDs testable, begane VM tests
cdolm92 Nov 30, 2018
aff4384
wip -refactor on vm/vmtest
cdolm92 Nov 30, 2018
56a0df0
wip -refactor deleted comments on vmt
cdolm92 Nov 30, 2018
1759300
wip -snapshot tests
cdolm92 Nov 30, 2018
a1dbe87
swiftlint fixes
cdolm92 Nov 30, 2018
40ecf69
renaming/refactor, corrected paymentmethodstests
cdolm92 Dec 3, 2018
84a4253
pr feedback
cdolm92 Dec 4, 2018
8883d58
swiftlint fixes
cdolm92 Dec 4, 2018
66030fd
changed function name
cdolm92 Dec 4, 2018
9cd3977
indentation
cdolm92 Dec 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -123,7 +123,7 @@ internal final class AddNewCardViewController: UIViewController, STPPaymentCardT
self.viewModel.outputs.paymentDetails
.observeForUI()
.observeValues { [weak self] cardholderName, cardNumber, expMonth, expYear, cvc in
self?.stripeToken(cardholderName: cardholderName,
self?.createStripeToken(cardholderName: cardholderName,
Copy link
Contributor

Choose a reason for hiding this comment

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

Alignment is off here

cardNumber: cardNumber,
expirationMonth: expMonth,
expirationYear: expYear,
Expand Down Expand Up @@ -163,15 +163,15 @@ internal final class AddNewCardViewController: UIViewController, STPPaymentCardT
}

@objc func cardholderNameTextFieldChanged(_ textField: UITextField) {
self.viewModel.inputs.cardholderNameChanged(textField.text ?? "")
self.viewModel.inputs.cardholderNameChanged(textField.text)
}

@objc func cardholderNameTextFieldReturn(_ textField: UITextField
) {
self.viewModel.inputs.cardholderNameTextFieldReturn()
}

func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {
internal func paymentCardTextFieldDidChange(_ textField: STPPaymentCardTextField) {

guard let cardnumber = textField.cardNumber, let cvc = textField.cvc else {
return
Expand All @@ -185,7 +185,7 @@ internal final class AddNewCardViewController: UIViewController, STPPaymentCardT
self.viewModel.inputs.paymentInfo(valid: textField.isValid)
}

func stripeToken(cardholderName: String,
private func createStripeToken(cardholderName: String,
cardNumber: String,
expirationMonth: Int,
expirationYear: Int,
Expand Down
14 changes: 6 additions & 8 deletions Library/ViewModels/AddNewCardViewModel.swift
Expand Up @@ -6,7 +6,7 @@ import Result
import Stripe

public protocol AddNewCardViewModelInputs {
func cardholderNameChanged(_ cardholderName: String)
func cardholderNameChanged(_ cardholderName: String?)
func cardholderNameTextFieldReturn()
func creditCardChanged(cardNumber: String, expMonth: Int, expYear: Int, cvc: String)
func paymentInfo(valid: Bool)
Expand Down Expand Up @@ -37,7 +37,7 @@ public final class AddNewCardViewModel: AddNewCardViewModelType, AddNewCardViewM
AddNewCardViewModelOutputs {

public init() {
let cardholderName = self.cardholderNameChangedProperty.signal
let cardholderName = self.cardholderNameChangedProperty.signal.skipNil()
let creditCardDetails = self.creditCardChangedProperty.signal.skipNil()

self.cardholderNameBecomeFirstResponder = self.viewDidLoadProperty.signal
Expand All @@ -53,12 +53,10 @@ AddNewCardViewModelOutputs {
.map { cardholderName, creditCardDetails in
(cardholderName, creditCardDetails.0, creditCardDetails.1, creditCardDetails.2, creditCardDetails.3) }

let tryAddCardAction = self.saveButtonTappedProperty.signal

self.paymentDetails = paymentInput
.takeWhen(self.saveButtonTappedProperty.signal)

self.dismissKeyboard = tryAddCardAction
self.dismissKeyboard = self.saveButtonTappedProperty.signal

self.setStripePublishableKey = self.saveButtonIsEnabled
.filter(isTrue)
Expand Down Expand Up @@ -90,14 +88,14 @@ AddNewCardViewModelOutputs {
)

self.activityIndicatorShouldShow = Signal.merge(
tryAddCardAction.signal.mapConst(true),
self.saveButtonTappedProperty.signal.mapConst(true),
self.addNewCardSuccess.mapConst(false),
self.addNewCardFailure.mapConst(false)
)
}

private let cardholderNameChangedProperty = MutableProperty("")
public func cardholderNameChanged(_ cardholderName: String) {
private let cardholderNameChangedProperty = MutableProperty<String?>(nil)
public func cardholderNameChanged(_ cardholderName: String?) {
self.cardholderNameChangedProperty.value = cardholderName
}

Expand Down
18 changes: 16 additions & 2 deletions Library/ViewModels/AddNewCardViewModelTests.swift
Expand Up @@ -119,8 +119,8 @@ internal final class AddNewCardViewModelTests: TestCase {
func testBecomeFirstResponderAndSaveEnabled() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this test could be broken up in 2 pieces: one for becomeFirstResponder part and the other for saveEnabled

self.cardholderNameBecomeFirstResponder.assertDidNotEmitValue()
self.paymentDetailsBecomeFirstResponder.assertDidNotEmitValue()
self.saveButtonIsEnabled.assertDidNotEmitValue()
self.activityIndicatorShouldShow.assertDidNotEmitValue()
self.saveButtonIsEnabled.assertDidNotEmitValue()

self.vm.inputs.viewDidLoad()

Expand Down Expand Up @@ -149,7 +149,21 @@ internal final class AddNewCardViewModelTests: TestCase {
self.saveButtonIsEnabled.assertValues([false, false, true], "Enabled when form is valid.")
}

func testSetPublishableKey_CardInfoInValid() {
func testSaveButtonEnabled() {
self.saveButtonIsEnabled.assertDidNotEmitValue()
self.vm.inputs.viewDidLoad()

self.vm.inputs.cardholderNameChanged("")
self.vm.inputs.paymentInfo(valid: false)
self.saveButtonIsEnabled.assertValues([false], "Disabled form is incomplete")

self.vm.inputs.cardholderNameChanged("Native Squad")
self.vm.inputs.paymentInfo(valid: true)

self.saveButtonIsEnabled.assertValues([false, false, true], "Enabled when form is valid.")
}

func testSetPublishableKey_CardInfoInvalid() {
withEnvironment(config: .template |> Config.lens.stripePublishableKey .~ "stripePublishableKey") {
self.vm.inputs.viewDidLoad()

Expand Down