Repository navigation
Add stripe_recurrence_charges - #1481
Conversation
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Thanks for clarifying! Looks good.
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.