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

MBL-1123: Refactor PaymentSourceSelected to be an enum #1990

Merged

Conversation

amy-at-kickstarter
Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter commented Mar 20, 2024

📲 What

Refactor PaymentSourceSelected to be an enum, instead of a struct.

🤔 Why

For MBL-1123, I'm adding another type of payment source to PledgeViewModel. We start to create PaymentIntent secrets, which are a separate kind of client secret from our existing SetupIntent secrets.

Before, the different between payment types was modeled by storing the payment source ID and a boolean, which flagged whether or not the string was a stripe token or a Kickstarter ID.

After, this is modeled as an enum, so that it should be much clearer what kind of payment source we're passing around the codebase. As a bonus, this actually deleted a few lines of redundant code, since it makes the plumbing a little simpler.

When I finish this ticket, we'll have an enum like this:

public enum PaymentSourceSelected: Equatable {
  case paymentSourceId(String)
  case setupIntentClientSecret(String)
  case paymentIntentClientSecret(String)
}

@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-selected branch from d4e0064 to 67bb693 Compare March 20, 2024 19:17
@amy-at-kickstarter amy-at-kickstarter changed the title Feat/adyer/mbl 1123/refactor payment source selected MBL-1123: Refactor PaymentSourceSelected to be an enum Mar 20, 2024
@@ -0,0 +1,25 @@
import Foundation
public enum PaymentSourceSelected: Equatable {
case paymentSourceId(String)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggestions for better names welcome - as far as I know, this is an ID that comes from GraphQL and represents a particular payment methods stored in our own DB.

)
PaymentSourceSelected.paymentSourceId(UserCreditCards.visa.id),
PaymentSourceSelected
.setupIntentClientSecret("seti_1LVlHO4VvJ2PtfhK43R6p7FI_secret_MEDiGbxfYVnHGsQy8v8TbZJTQhlNKLZ")
])
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good example of how these are different now.

@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-selected branch from 67bb693 to 9572634 Compare March 20, 2024 19:28
@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review March 20, 2024 19:30
@amy-at-kickstarter amy-at-kickstarter requested review from a team, ifosli and scottkicks and removed request for a team March 20, 2024 19:30
@amy-at-kickstarter amy-at-kickstarter self-assigned this Mar 20, 2024
Copy link
Contributor

@scottkicks scottkicks left a comment

Choose a reason for hiding this comment

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

These changes look good. Great cleanup. I suggest running through our normal pledge flow to make sure we're all good there before merging. Even though tests are passing and this is more of a cleanup, changing our checkout code makes me paranoid

Comment on lines 6 to 23
public var paymentSourceId: String? {
if case let .paymentSourceId(value) = self {
return value
} else {
return nil
}
}

public var setupIntentClientSecret: String? {
if case let .setupIntentClientSecret(value) = self {
return value
} else {
return nil
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

any particular reason you didn't want to use switch statements here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, not really. Just tried it out and it's a little neater looking, so I'll swap these.

Comment on lines -263 to +264
paymentSourceId: selectedPaymentSheetPaymentMethodCardId,
isSetupIntentClientSecret: true
)
return PaymentSourceSelected.setupIntentClientSecret(selectedPaymentSheetPaymentMethodCardId)
case let (.some(selectedPaymentMethodCardId), .none):
return PaymentSourceSelected(
paymentSourceId: selectedPaymentMethodCardId,
isSetupIntentClientSecret: false
)
return PaymentSourceSelected.paymentSourceId(selectedPaymentMethodCardId)
Copy link
Contributor

Choose a reason for hiding this comment

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

so much clearer!

@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-selected branch from 9572634 to fefa917 Compare March 21, 2024 14:25
@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-selected branch from fefa917 to 5bb1591 Compare March 21, 2024 14:58
@amy-at-kickstarter
Copy link
Contributor Author

Ran two manual tests on staging - I made a pledge with an existing card, and another pledge that was adding a new card.

@amy-at-kickstarter amy-at-kickstarter merged commit cb0fb9b into main Mar 21, 2024
5 checks passed
@amy-at-kickstarter amy-at-kickstarter deleted the feat/adyer/MBL-1123/refactor-payment-source-selected branch March 21, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants