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

[NT-422] Payment source refactor #895

Merged
merged 14 commits into from
Oct 21, 2019
Merged

[NT-422] Payment source refactor #895

merged 14 commits into from
Oct 21, 2019

Conversation

Scollaco
Copy link
Contributor

πŸ“² What

  • Creates PaymentSource to be used on the manage pledge context.

πŸ€” Why

  • We were reusing the GraphUserCreditCard model, but due some differences between the payloads returned by v1 and graphQL, we've decided to create a new model to avoid work arounds.

πŸ›  How

  • Creating PaymentSource and making it Argo decodable.
  • Removing unnecessary properties of GraphUserCreditCard model
  • Creating ManagePledgePaymentMethodViewModel
  • Updating, fixing and adding tests

πŸ‘€ See

  • No differences should be noticed.

βœ… Acceptance criteria

  • No differences should be noticed on ManagePledgeViewController or ManagePledgePaymentMethodView

public let expirationDate: String?
public let id: String?
public let lastFour: String?
public let paymentType: PaymentType?
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 should be non-optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was following the description of this ticket

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 the ticket says it should be non-optional? πŸ€”
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OMG! paymentType is non-optional, but type is! Got lost between types πŸ˜…

import Prelude
import ReactiveExtensions
import ReactiveSwift
import UIKit
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 get rid of the UIKit import here and just return the imageName as a string? I think we generally try to keep our VMs decoupled from UIKit.


public protocol ManagePledgePaymentMethodViewModelOutputs {
/// Emits the card's image.
var cardImage: Signal<UIImage?, Never> { get }
Copy link
Contributor

Choose a reason for hiding this comment

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

Here this could be cardImageName: Signal<String?, Never>


self.cardNumberAccessibilityLabel = self.paymentSourceSignal
.map {
[$0.type?.description, Strings.Card_ending_in_last_four(last_four: $0.lastFour ?? .init())]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to set this up such that if type and lastFour are nil, we don't send anything back in the output? It doesn't seem like we'd ever want a situation where the label reads " , ending in " πŸ€”

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I will change that

.map { Strings.Ending_in_last_four(last_four: $0) }

self.expirationDateText = self.paymentSourceSignal
.map { String($0.expirationDate?.dropLast(3) ?? "") }
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, I think we probably shouldn't have the signal output when the expirationDate is nil:

self.expirationDateText = self.paymentSourceSignal
  .map { $0.expirationDate }
  .skipNil()
  .map { String($0.dropLast(3)) }
... etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I missed that one. Good catch!

@ksr-ci-bot
Copy link

ksr-ci-bot commented Oct 16, 2019

1 Warning
⚠️ Big PR

Generated by 🚫 Danger

@@ -68,12 +91,12 @@ extension Backing: Argo.Decodable {
on that environment. This is a workaround to allow us to test on Staging and should be deleted once the
data is being returned normally.
*/
private func tryDecodePaymentSource(_ json: JSON?) -> Decoded<GraphUserCreditCard.CreditCard?> {
private func tryDecodePaymentSource(_ json: JSON?) -> Decoded<Backing.PaymentSource?> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do. I tried removing it, but same issue still happens on Staging.

@@ -91,8 +114,27 @@ extension Backing: EncodableType {
}
}

extension Backing.PaymentSource: Argo.Decodable {
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 we could have this only conform to Swift's Decodable and do a similar function like before to return an Argo.Decodable success or failure?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought, perhaps this PR is not the place to start doing that, but I think that can be an approach to help us to start moving away from Argo.

Copy link
Contributor

@ifbarrera ifbarrera left a comment

Choose a reason for hiding this comment

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

Couple questions/comments.

public static func decode(_ json: JSON) -> Decoded<Backing.PaymentSource?> {
return curry(Backing.PaymentSource.init)
<^> json <|? "expiration_date"
<*> (json <|? "id" <|> (json <| "id" >>- intToString))
Copy link
Contributor

Choose a reason for hiding this comment

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

CJ merged the change to return a String instead of an Int so you should be able to remove this now! πŸŽ‰


public protocol ManagePledgePaymentMethodViewModelOutputs {
/// Emits the card's image.
var cardImage: Signal<String, Never> { get }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe cardImageName would be more accurate here?

self.vm.inputs.configureWith(value: Backing.PaymentSource.applePay)

self.cardImage.assertValue("icon--apple-pay")
self.cardNumberTextShortStyle.assertLastValue("Ending in 1111")
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we missing an assertion here for the accessibility label? And actually on second thought, do we want to update the accessibility label to indicate that the card is associated with Apple Pay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding the accessibility label, it's a good idea, but I think this ends up being out of scope for this PR.

Copy link
Contributor

@ifbarrera ifbarrera left a comment

Choose a reason for hiding this comment

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

Thanks for making this change! πŸ™Œ

@Scollaco Scollaco merged commit 26aad34 into master Oct 21, 2019
@Scollaco Scollaco deleted the payment-source-refactor branch October 21, 2019 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants