Skip to content

Commit

Permalink
Reorder deletion in charge succeed function
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Dec 17, 2021
1 parent 583e5a8 commit c5dd737
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/api/v1/donate.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,15 @@ func handlePaymentSucceeded(c echo.Context, event *stripe.WebhookEvent, payment
}

func handleChargeSucceeded(c echo.Context, event *stripe.WebhookEvent, charge *upstreamstripe.Charge) error {
// Attempt to remove from table before any errors can occur
database.DB.Exec("DELETE FROM payment_intents WHERE stripe_payment_id = $1", charge.PaymentIntent.ID)

// Distribute charge amount between connected accounts
// We do this on charge succeeded instead of payment succeeded so we don't have to sort through successful and failed charges
err := stripe.DistributeDonation(charge)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Error distributing charge").SetInternal(err)
}

database.DB.Exec("DELETE FROM payment_intents WHERE stripe_payment_id = $1", charge.PaymentIntent.ID)

return c.NoContent(http.StatusOK)
}

Expand Down

0 comments on commit c5dd737

Please sign in to comment.