Skip to content

Commit

Permalink
allow non-terminal state for PaymentSheet (#4438)
Browse files Browse the repository at this point in the history
* allow non-terminal state for PaymentSheet

* update test name

* update error message

* update test
  • Loading branch information
ccen-stripe authored Dec 9, 2021
1 parent c75cef9 commit 94a1657
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,25 @@ internal class StripeIntentValidator @Inject constructor() {
}
stripeIntent is PaymentIntent &&
(
(stripeIntent.status != StripeIntent.Status.RequiresPaymentMethod) &&
(stripeIntent.status != StripeIntent.Status.RequiresAction)
(stripeIntent.status == StripeIntent.Status.Canceled) ||
(stripeIntent.status == StripeIntent.Status.Succeeded) ||
(stripeIntent.status == StripeIntent.Status.RequiresCapture)
) -> {
error(
"""
A PaymentIntent with status='requires_payment_method' or 'requires_action` is required.
The current PaymentIntent has status '${stripeIntent.status}'.
PaymentSheet cannot set up a PaymentIntent in status '${stripeIntent.status}'.
See https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status.
""".trimIndent()
)
}
stripeIntent is SetupIntent &&
(
(stripeIntent.status != StripeIntent.Status.RequiresPaymentMethod) &&
(stripeIntent.status != StripeIntent.Status.RequiresAction)
(stripeIntent.status == StripeIntent.Status.Canceled) ||
(stripeIntent.status == StripeIntent.Status.Succeeded)
) -> {
error(
"""
A SetupIntent with status='requires_payment_method' or 'requires_action` is required.
The current SetupIntent has status '${stripeIntent.status}'.
PaymentSheet cannot set up a SetupIntent in status '${stripeIntent.status}'.
See https://stripe.com/docs/api/setup_intents/object#setup_intent_object-status
""".trimIndent()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,7 @@ internal class PaymentSheetViewModelTest {
viewModel.maybeFetchStripeIntent()
assertThat((result as? PaymentSheetResult.Failed)?.error?.message)
.isEqualTo(
"A PaymentIntent with status='requires_payment_method' or 'requires_action` is required.\n" +
"The current PaymentIntent has status 'succeeded'.\n" +
"PaymentSheet cannot set up a PaymentIntent in status 'succeeded'.\n" +
"See https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status."
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class StripeIntentValidatorTest {
}

@Test
fun `requireValid() processing is not valid`() {
fun `requireValid() Succeeded is not valid`() {
assertFails {
validator.requireValid(
PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD.copy(
status = StripeIntent.Status.Processing
status = StripeIntent.Status.Succeeded
)
)
}
Expand Down Expand Up @@ -71,4 +71,22 @@ class StripeIntentValidatorTest {
SetupIntentFixtures.SI_NEXT_ACTION_REDIRECT
)
}

@Test
fun `PaymentIntent requireValid() allows status = RequiresConfirmation`() {
validator.requireValid(
PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD.copy(
status = StripeIntent.Status.RequiresConfirmation
)
)
}

@Test
fun `PaymentIntent requireValid() allows status = Processing`() {
validator.requireValid(
PaymentIntentFixtures.PI_REQUIRES_PAYMENT_METHOD.copy(
status = StripeIntent.Status.Processing
)
)
}
}

0 comments on commit 94a1657

Please sign in to comment.