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 PledgePaymentMethodsViewModel to use PaymentSourceSelected #1992

Merged

Conversation

amy-at-kickstarter
Copy link
Contributor

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

📲 What

Refactor PledgePaymentMethodsViewModel to use PaymentSourceSelected, instead of managing separate values for a selectedSetupIntent and a selectedCreditCard.

🤔 Why

For MBL-1123, I need to pass the final selected value (whether it's from a SetupIntent, a PaymentIntent or an existing CreditCard) back to the delegate of the PledgePaymentMethodsViewController. This refactor makes that significantly easier - we'll be able to keep the declarative nature of the screen, but be explicit about what kind of payment method is selected.

The alternative would be to keep some kind of state in the PledgePaymentMethodsViewController that indicated whether or not it should use a SetupIntent or a PaymentIntent, and that felt messy in a different way.

@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-pt-2 branch 2 times, most recently from 787544d to 3ed8616 Compare March 21, 2024 18:54
@amy-at-kickstarter amy-at-kickstarter force-pushed the feat/adyer/MBL-1123/refactor-payment-source-pt-2 branch from 3ed8616 to 67460e2 Compare March 21, 2024 19:57
@amy-at-kickstarter amy-at-kickstarter changed the title Feat/adyer/mbl 1123/refactor payment source pt 2 MBL-1123: Refactor PledgePaymentMethodsViewModel to use PayentSourceSelected Mar 21, 2024
@amy-at-kickstarter amy-at-kickstarter changed the title MBL-1123: Refactor PledgePaymentMethodsViewModel to use PayentSourceSelected MBL-1123: Refactor PledgePaymentMethodsViewModel to use PaymentSourceSelected Mar 21, 2024
@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review March 21, 2024 20:02
return nil
}
}
.map { $0.selectedPaymentMethod }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All this refactoring was to get this simplification!

@@ -49,11 +49,12 @@ final class PledgePaymentMethodsViewModelTests: TestCase {
.observe(self.reloadPaymentMethodsProjectCountry.observer)
self.vm.outputs.reloadPaymentMethods.map { $0.1 }
.observe(self.reloadPaymentSheetPaymentMethodsCards.observer)
self.vm.outputs.reloadPaymentMethods.map { $0.2 }.observe(self.reloadPaymentMethodsSelectedCard.observer)
self.vm.outputs.reloadPaymentMethods.map { $0.3 }
self.vm.outputs.reloadPaymentMethods.map { data in data.selectedPaymentMethod?.paymentSourceId }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of re-writing these tests to use the new-and-better output, just shimming the refactored code into the old test. We can make these tests prettier later, if we want.

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.

LGTM 👍

@amy-at-kickstarter amy-at-kickstarter merged commit 8882b98 into main Mar 21, 2024
5 checks passed
@amy-at-kickstarter amy-at-kickstarter deleted the feat/adyer/MBL-1123/refactor-payment-source-pt-2 branch March 21, 2024 20:38
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