fix: preserve payment sessions during certain Stripe errors for webhook reconciliation (#11798)

* fix: preserve payment sessions during certain Stripe errors for webhook reconciliation

fix: add retry mechanism for errors that might be fixed after retry

fix: authorizePaymentSession method will update payment_session.status regardless regardless of wether or not the authorization is successful

* Refactor: improve handling structure and syntax

-Move HandledErrorType definition to the top of stripe-base

- Use timers/promises for setTimeout

- Removed data in HandledErrorType when retry is true

* refactor: improve error handling flow and logic

- Simplify return statement in initiatePayment to handle null cases

- Remove redundant if-check in handleStripeError and rely on switch

- Reorder conditional checks in executeWithRetry for clearer flow

- Update executeWithRetry to check for retry=false condition first

* clean up

* fix: improve payment error handling and traceability

- Return structured error state for StripeAPIError instead of null

- Throw error when retries are exhausted and no payment intent exists

- Update type definitions to support error state tracking

* fix formatting and naming
This commit is contained in:
Saryazdi-Saman
2025-03-13 09:46:31 -04:00
committed by GitHub
parent 28b0d08591
commit e05491c24f
2 changed files with 102 additions and 14 deletions

View File

@@ -504,6 +504,11 @@ export default class PaymentModuleService
status !== PaymentSessionStatus.AUTHORIZED &&
status !== PaymentSessionStatus.CAPTURED
) {
await this.paymentSessionService_.update({
id: session.id,
status,
data,
}, sharedContext);
throw new MedusaError(
MedusaError.Types.NOT_ALLOWED,
`Session: ${session.id} was not authorized with the provider.`