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-1271]Stripe's confirmPayment #2003

Merged
merged 8 commits into from
Mar 27, 2024

Conversation

scottkicks
Copy link
Contributor

@scottkicks scottkicks commented Mar 26, 2024

📲 What

Calls Stripe.confirmPayment after validating checkout

🤔 Why

We need to confirm payment using the new payment intent with Stripe so that we can charge these cards immediately

🛠 How

When validation is successful for both a new card and an existing card, call this method!

There's a key difference for existing cards:

  • We need to set the payment param's paymentMethodId property to be the stripeCardId that's on the stored card.
  • When a pre-existing card (one that was created with a setup intent) is used in late pledges, we use the backend to create a payment intent and use the returned intent to validate and then confirm payment with Stripe. The issue there is that the new payment intent isn't associated with any payment method in Stripe yet so Stripe.confirmPayment will throw an error. Setting the paymentMethodId will associate it!

🪲

  • There's just one issue I noticed last minute in this PR where the outputs for validating new cards and existing cards occasionally trigger at the same time. Have a feeling this is a simple cross of signals, but if someone could take a look when they review that would be really helpful!

✅ Acceptance criteria

  • When stripe confirms successfuly the charge show up in Stripe
Screenshot 2024-03-26 at 5 45 07 PM

@scottkicks scottkicks self-assigned this Mar 26, 2024
@scottkicks scottkicks marked this pull request as ready for review March 26, 2024 23:07
@scottkicks scottkicks requested review from a team, ifosli and amy-at-kickstarter and removed request for a team March 26, 2024 23:09
@amy-at-kickstarter amy-at-kickstarter force-pushed the scott/pcp/stripe-confirm-payment branch 2 times, most recently from 3308052 to a5399ab Compare March 27, 2024 18:27

self.present(navigationController, animated: true)
}

private func confirmPayment(with validation: PaymentSourceValidation) {
guard validation.requiresConfirmation else {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably be done in a highly clever was in the view model, but I felt that this was going to be the easiest to follow. This way, new and existing cards go through the same input/output flow, all the time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I like this


let newPaymentIntentEvent = initialData
let newPaymentIntentForExistingCards = initialData
Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter Mar 27, 2024

Choose a reason for hiding this comment

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

Renaming for clarity. This does not emit the payment intent for every card; it only emits it when an existing card is selected.

.map { $0.clientSecret }

// Runs validation for pre-existing cards that were created with setup intents originally but require payment intents for late pledges.
let validateCheckoutExistingCard = Signal
.combineLatest(checkoutId, selectedExistingCard, paymentIntentClientSecret, storedCardsValues)
.combineLatest(checkoutId, selectedCard, paymentIntentClientSecretForExistingCards, storedCardsValues)
Copy link
Contributor

Choose a reason for hiding this comment

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

@ifosli Did I potentially just undo your bug fix from earlier?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you're good - the important part is that we're looking for the most recently selected card in this line and that the filter to check if it's a new or existing card happens after (in line 213-215).


self.present(navigationController, animated: true)
}

private func confirmPayment(with validation: PaymentSourceValidation) {
guard validation.requiresConfirmation else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I like this

.map { $0.clientSecret }

// Runs validation for pre-existing cards that were created with setup intents originally but require payment intents for late pledges.
let validateCheckoutExistingCard = Signal
.combineLatest(checkoutId, selectedExistingCard, paymentIntentClientSecret, storedCardsValues)
.combineLatest(checkoutId, selectedCard, paymentIntentClientSecretForExistingCards, storedCardsValues)
Copy link
Contributor

Choose a reason for hiding this comment

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

No, you're good - the important part is that we're looking for the most recently selected card in this line and that the filter to check if it's a new or existing card happens after (in line 213-215).

Library/ViewModels/PostCampaignCheckoutViewModel.swift Outdated Show resolved Hide resolved
@amy-at-kickstarter amy-at-kickstarter merged commit f16bae7 into main Mar 27, 2024
5 checks passed
@amy-at-kickstarter amy-at-kickstarter deleted the scott/pcp/stripe-confirm-payment branch March 27, 2024 21:26
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.

3 participants