Skip to content

Add stripe_recurrence_charges - #1481

Merged
caseyhelbling merged 4 commits into
supporter_level_goalfrom
clh/stripe-recurrence-charges
Nov 25, 2026
Merged

caseyhelbling merged 4 commits into
supporter_level_goalfrom
clh/stripe-recurrence-charges

Conversation

@caseyhelbling

Copy link
Copy Markdown
Collaborator

One row per monthly gift per month, unique on the gift and month, for Slipflow to write before it charges a gift's card and to record how the charge went.

One row per monthly gift per month, unique on the gift and month, for Slipflow to write before it charges a gift's card and to record how the charge went: the amount and fee as they were when it started, the attempt and its Stripe idempotency key, the PaymentIntent, and the outcome.
A retry after a decline now gets its own row, so each attempt keeps its PaymentIntent and decline. A month still has at most one row that isn't declined, failed or canceled, which a partial unique index holds, so a succeeded, skipped or in-progress month can't be charged again.

failed means Stripe confirmed nothing was charged. An error that leaves it unknown leaves the row pending with its PaymentIntent, for a retrieve to settle. A skipped row has no amount, fee or key, so sums of charges don't count it.
stripe_recurrence_id gets its own index, since the month index is partial now. failed means no PaymentIntent was created, and declined and canceled mean the PaymentIntent is canceled at Stripe, so a retry's row only frees the month when nothing else can charge it. A decline code goes only on a declined row and a failure code or message only on a declined, failed or canceled one, and the fee stays below the amount.
t.string :decline_code, comment: "Stripe's decline code when the card was declined"
t.string :failure_message, comment: "Stripe's error message when the charge was declined, failed or was canceled"
t.timestamps
t.index [:stripe_recurrence_id, :billing_month], unique: true, where: "status NOT IN ('declined', 'failed', 'canceled')", name: "index_stripe_recurrence_charges_on_recurrence_and_month_live"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since declined rows don't count toward the one-per-month rule, a declined month could get another row and be tried again. Is the plan to retry a declined card later in the month, like legacy does until 3 failures, or to leave it declined with no retry like on #517?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes - bingo. We'll do it just like legacy.

t.string :failure_message, comment: "Stripe's error message when the charge was declined, failed or was canceled"
t.timestamps
t.index [:stripe_recurrence_id, :billing_month], unique: true, where: "status NOT IN ('declined', 'failed', 'canceled')", name: "index_stripe_recurrence_charges_on_recurrence_and_month_live"
t.index :updated_at, where: "status = 'pending'", name: "index_stripe_recurrence_charges_pending_on_updated_at"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks like it's for finding rows stuck on pending, like if the job crashes before Stripe answers. Is a cleanup planned in Slipflow so a stuck row doesn't block that month?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. Yeah, the plan is to have a sweeper that looks at each pending row and settles it. We still need to build the sweeper stuff, though... Adding another ticket for that ...

…tripe-recurrence-charges

# Conflicts:
#	db/schema.rb

@aliyahmoore aliyahmoore left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for clarifying! Looks good.

@caseyhelbling
caseyhelbling merged commit 2a51386 into supporter_level_goal Nov 25, 2026
5 checks passed
@caseyhelbling
caseyhelbling deleted the clh/stripe-recurrence-charges branch November 25, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants