Skip to content

Commit 45460b1

Browse files
committed
feat(stripe): add early fraud warning persistence foundation
1 parent 4030ca0 commit 45460b1

14 files changed

Lines changed: 24877 additions & 24 deletions

.specs/impact-affiliate-tracking.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Updated 2026-05-12 -- note price-versioned billing preserves affiliate semantics
2020
Updated 2026-05-20 -- broaden tracking to Kilo Pass SALE conversions and rename the affiliate spec.
2121
Updated 2026-05-20 -- tighten attribution boundaries, SALE uniqueness, Kilo Pass eligibility, reversal scope, and
2222
provider-contract ownership after audit.
23+
Updated 2026-05-28 -- allow full SALE reversal for enforced Stripe EFW refunds.
2324

2425
## Conventions
2526

@@ -57,9 +58,9 @@ BCP 14 [RFC 2119] [RFC 8174] keywords apply only when they appear in all capital
5758
- **Kilo Pass cadence**: Eligible billing cadence `monthly` or `yearly`.
5859
- **Promo code**: Provider- or checkout-applied purchase code that is available as a discrete reportable value for an
5960
eligible SALE.
60-
- **Disputed eligible sale**: Eligible payment-provider-backed SALE whose underlying payment later receives a provider
61-
dispute notification.
62-
- **Commission reversal**: Provider-facing rejection of an affiliate SALE commission for a disputed eligible sale.
61+
- **Adverse eligible sale**: Eligible payment-provider-backed SALE whose underlying payment later receives a provider
62+
dispute notification or is refunded under enforced Stripe Early Fraud Warning handling.
63+
- **Commission reversal**: Provider-facing rejection of an affiliate SALE commission for an adverse eligible sale.
6364
- **Reversal identity**: Provider-retained reference needed to reverse a prior SALE without guessing which reported
6465
action to reject.
6566
- **Primary operation**: User creation, authentication, subscription settlement, billing progression, or another
@@ -193,26 +194,28 @@ after the winning attribution is established.
193194
27. Admin-only subscription interventions, such as admin trial resets, admin cancellations, or manual trial-date edits,
194195
MUST NOT emit affiliate conversion events.
195196

196-
### Dispute Reversals
197+
### Adverse Payment Reversals
197198

198-
28. When the payment provider reports creation of a dispute for a disputed eligible sale, the system MUST submit a full
199-
commission reversal. This covers payment-provider-backed personal KiloClaw SALE events and eligible Kilo Pass SALE
200-
events.
199+
28. When the payment provider reports creation of a dispute for an adverse eligible sale, or Kilo refunds that sale under
200+
enforced Stripe Early Fraud Warning handling, the system MUST submit a full commission reversal. This covers
201+
payment-provider-backed personal KiloClaw SALE events and eligible Kilo Pass SALE events.
201202

202-
29. Partial payment disputes MUST still reverse the full associated affiliate commission.
203+
29. Partial payment disputes and an enforced EFW refund of only the remaining refundable amount MUST still reverse the
204+
full associated affiliate commission.
203205

204-
30. The system MUST NOT automatically restore reversed commission if the dispute is later resolved in the brand's favor.
206+
30. The system MUST NOT automatically restore reversed commission if the dispute is later resolved in the brand's favor
207+
or an EFW-enforced account later receives legitimate-user remediation.
205208

206-
31. Reversal handling MUST preserve intent when a dispute arrives before the corresponding SALE is reversal-ready. Once
207-
the relevant SALE and reversal identity become resolvable, the pending dispute MUST be eligible for reversal
208-
submission.
209+
31. Reversal handling MUST preserve intent when a dispute or enforced EFW refund arrives before the corresponding SALE is
210+
reversal-ready. Once the relevant SALE and reversal identity become resolvable, the pending adverse payment MUST be
211+
eligible for reversal submission.
209212

210213
32. Automatic reversal is REQUIRED only when a reversal identity exists or can be recovered without guessing. If an
211214
earlier eligible sale lacks recoverable reversal identity, the system MUST make that gap operationally observable for
212215
non-automated follow-up.
213216

214-
33. Reversal processing MUST be idempotent. Duplicate dispute notifications for the same disputed eligible sale MUST NOT
215-
produce multiple commission reversals.
217+
33. Reversal processing MUST be idempotent. Duplicate dispute notifications, duplicate EFW processing, or a later
218+
dispute for an already EFW-reversed eligible sale MUST NOT produce multiple commission reversals.
216219

217220
### Client-Side Identity Bridging
218221

@@ -249,6 +252,10 @@ after the winning attribution is established.
249252

250253
## Changelog
251254

255+
### 2026-05-28 -- Enforced EFW refund reversals
256+
257+
Expanded adverse SALE reversal to enforced Stripe Early Fraud Warning refunds so proactive refunds can reverse a full eligible affiliate commission without waiting for a dispute, while preserving reversal identity and deduplication requirements.
258+
252259
### 2026-05-20 -- Audit clarifications after Kilo Pass expansion
253260

254261
Removed VISIT reporting from this spec, clarified that Kilo Pass affiliate SALE requires a positive paid invoice amount,

.specs/impact-referrals.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Draft -- created 2026-04-21 as `.specs/kiloclaw-referrals.md` for KiloClaw refer
1717
Updated 2026-05-06 -- require Impact Advocate reward redemption after local KiloClaw reward application.
1818
Updated 2026-05-12 -- note price-versioned KiloClaw billing preserves referral semantics.
1919
Updated 2026-05-22 -- renamed to `.specs/impact-referrals.md` and expanded to Kilo Pass referrals.
20+
Updated 2026-05-28 -- classify enforced Stripe EFW refunds as adverse payments.
2021

2122
## Conventions
2223

@@ -73,6 +74,9 @@ BCP 14 [RFC 2119] [RFC 8174] keywords apply only when they appear in all capital
7374
- **Chargeback**: Stripe dispute event for the qualifying Stripe payment.
7475
- **Fraud-marked payment**: Qualifying payment marked fraudulent by Stripe, an internal fraud process, or an authorized
7576
operator.
77+
- **Enforced EFW refund**: Refund of a qualifying personal Stripe payment performed under
78+
`.specs/stripe-early-fraud-warnings.md` after a new Stripe Early Fraud Warning; it is an adverse payment even when no
79+
later chargeback is created.
7680
- **Support review**: Durable `review_required` reward state with triggering reason, affected billing period, and source
7781
payment or dispute recorded. Kilo team review is required before an already-applied reward can be canceled, clawed
7882
back, or otherwise adjusted.
@@ -625,18 +629,22 @@ conversion, local referral rewards are authoritative and affiliate SALE reportin
625629

626630
### Refunds, Reversals, and Fraud
627631

628-
159. Rewards from a qualifying Stripe payment MUST be canceled if Stripe reports a chargeback for that payment.
632+
159. Rewards from a qualifying Stripe payment MUST be treated as adverse when Stripe reports a chargeback or when
633+
Kilo enforces an EFW refund for that payment.
629634

630635
160. Pending or earned-but-unapplied rewards MUST be canceled when the qualifying Stripe payment is charged back,
631-
refunded, or fraud-marked.
636+
refunded, fraud-marked, or refunded as part of enforced EFW handling. This rule applies to both KiloClaw and Kilo
637+
Pass qualifying payments.
632638

633-
161. Already-applied rewards from a charged-back, refunded, or fraud-marked payment MUST be marked for support review
634-
and MUST NOT be automatically canceled or clawed back.
639+
161. Already-applied rewards from a charged-back, refunded, fraud-marked, or EFW-refunded payment MUST be marked for
640+
support review and MUST NOT be automatically canceled or clawed back.
635641

636-
162. If a qualifying Impact action must be reversed, the system SHOULD use Impact's reverse-action mechanism instead of
637-
creating an unrelated negative conversion.
642+
162. If a qualifying Impact action must be reversed, including after an enforced EFW refund that prevents a later
643+
chargeback event, the system SHOULD use Impact's reverse-action mechanism instead of creating an unrelated negative
644+
conversion.
638645

639-
163. Reversal and reward-cancellation handling MUST be idempotent.
646+
163. Reversal and reward-cancellation handling MUST be idempotent across EFW refund, ordinary refund, fraud marking, and
647+
later chargeback delivery for the same qualifying payment.
640648

641649
### GDPR and PII
642650

@@ -715,6 +723,10 @@ conversion, local referral rewards are authoritative and affiliate SALE reportin
715723

716724
## Changelog
717725

726+
### 2026-05-28 -- Enforced EFW refunds are adverse payments
727+
728+
Classified an enforced Stripe Early Fraud Warning refund as an adverse qualifying payment for both covered products. Pending or earned-but-unapplied rewards cancel, already-applied rewards require support review, and later refund or chargeback delivery must remain idempotent.
729+
718730
### 2026-05-22 -- Rename and expand to Kilo Pass
719731

720732
Renamed `.specs/kiloclaw-referrals.md` to `.specs/impact-referrals.md`. Generalized shared Impact Advocate referral

.specs/kiloclaw-billing.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Updated 2026-04-16 -- successor subscription rows on personal reprovision.
3030
Updated 2026-05-10 -- price-versioned legacy and current pricing.
3131
Updated 2026-05-12 -- retired current Standard first-month discount.
3232
Updated 2026-05-18 -- organization hard-expiry suspension and recovery contract.
33+
Updated 2026-05-28 -- exceptional personal Stripe EFW cancellation and suspension contract.
3334

3435
## Conventions
3536

@@ -91,6 +92,10 @@ capitals, as shown here.
9192
the pre-increase KiloClaw prices.
9293
- **Current pricing**: The default price version for fresh subscription
9394
rows created after the price-increase rollout.
95+
- **Fraud-enforcement cancellation**: Exceptional immediate personal
96+
subscription cancellation and suspension required when a personal
97+
Stripe payment is enforced under `.specs/stripe-early-fraud-warnings.md`.
98+
It is not a user cancellation or ordinary payment-dunning transition.
9499

95100
## Overview
96101

@@ -831,6 +836,15 @@ rows renew.
831836
price version. Re-enrollment after final cancellation MUST follow
832837
Pricing Versions and Legacy Lineages rule 9.
833838

839+
### Fraud-Enforcement Cancellation Exception
840+
841+
1. The ordinary period-end continuation rule in Cancellation and Reactivation rule 4 MUST NOT apply when a canonical personal Stripe payment is enforced under `.specs/stripe-early-fraud-warnings.md`.
842+
2. Fraud enforcement MUST immediately cancel renewal for every current personal KiloClaw subscription belonging to the contained user, including Stripe-funded, hybrid, and pure-credit renewal state. Any Stripe-backed cancellation MUST leave local billing state reconciled with the provider outcome.
843+
3. Fraud enforcement MUST stop or suspend affected personal compute promptly, transition the affected subscription into non-access-granting canceled/suspended state, and assign a fresh destruction deadline 7 days after suspension.
844+
4. Fraud enforcement MUST preserve the seven-day destruction grace and MUST NOT destroy instance data immediately. Remediation during that interval is an audited admin/support path, not automatic payment recovery.
845+
5. Every fraud-enforcement mutation MUST be captured in append-only subscription change history with a non-sensitive fraud-enforcement reason and a system actor.
846+
6. This exception MUST NOT apply to organization-managed KiloClaw subscriptions or instances based solely on an organization-owned EFW; organization warnings remain review-only under the EFW spec.
847+
834848
### Billing Lifecycle Background Job
835849

836850
1. The background job MUST be protected by an authorization secret;
@@ -1325,6 +1339,11 @@ rows renew.
13251339

13261340
### Changelog
13271341

1342+
#### 2026-05-28 -- Personal Stripe EFW fraud-enforcement exception
1343+
1344+
- Defined fraud enforcement as an exceptional immediate cancellation/suspension path for personal KiloClaw subscriptions rather than ordinary period-end cancellation.
1345+
- Preserved append-only change history and the fresh seven-day destruction grace while excluding organization-owned EFWs from automatic KiloClaw action.
1346+
13281347
#### 2026-05-18 -- Organization hard-expiry suspension contract
13291348

13301349
- Defined hard-expired organization trial state as the organization-managed

.specs/kiloclaw-datamodel.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ background jobs). All consumers MUST comply with the rules below.
1919

2020
## Status
2121

22-
Draft created 2026-04-15.
22+
Draft -- created 2026-04-15.
2323
Updated 2026-05-12 -- required KiloClaw price-version lineage invariants.
24+
Updated 2026-05-28 -- fraud-enforcement subscription mutation invariants.
2425

2526
## Conventions
2627

@@ -57,11 +58,14 @@ capitals, as shown here.
5758
- **Actor**: The entity responsible for a subscription mutation.
5859
An actor is either a user (identified by user ID) or the system
5960
(identified by a service or process name).
60-
- **Context**: The ownership scope of an instance either
61+
- **Context**: The ownership scope of an instance -- either
6162
_personal_ (not associated with any organization) or
6263
_organizational_ (associated with a specific organization). A user
6364
has one personal context and one organizational context per
6465
organization they belong to.
66+
- **Fraud-enforcement mutation**: Exceptional personal subscription
67+
cancellation or suspension required by an enforced Stripe Early
68+
Fraud Warning under `.specs/stripe-early-fraud-warnings.md`.
6569
- **Active instance**: An instance record that has not been marked
6670
as destroyed.
6771
- **Mutation**: Any database write (INSERT or UPDATE) to a
@@ -269,6 +273,13 @@ and serves as the authoritative audit trail for subscription state.
269273
identifiers (e.g., Stripe subscription ID, invoice ID) MAY be
270274
included as context.
271275

276+
### Fraud-Enforcement Mutations
277+
278+
- An enforced personal Stripe Early Fraud Warning is an exceptional immediate mutation path. It MUST cancel or suspend affected personal subscription state without relying on ordinary paid-period continuation.
279+
- A fraud-enforcement cancellation or suspension MUST write subscription change log entries with a system actor, consistent action labels, and a non-sensitive fraud-enforcement reason.
280+
- A fraud-enforcement suspension MUST retain the associated instance and subscription records and MUST assign the seven-day destruction grace defined by KiloClaw billing rather than destroying data immediately.
281+
- Organization-managed subscription and instance rows MUST NOT be mutated automatically for an organization-owned Early Fraud Warning in the initial rollout.
282+
272283
### Record Creation Order
273284

274285
The creation order below reflects the target lifecycle. This order
@@ -342,6 +353,11 @@ not yet enforced in the current codebase:
342353

343354
## Changelog
344355

356+
### 2026-05-28 -- Fraud-enforcement subscription mutations
357+
358+
- Defined enforced personal Stripe Early Fraud Warnings as exceptional immediate cancellation/suspension mutations that retain instance history, write system-attributed change logs, and preserve the seven-day destruction grace.
359+
- Excluded organization-owned warnings from automatic organization-managed instance or subscription mutation.
360+
345361
### 2026-05-12 -- Required KiloClaw price-version lineage invariants
346362

347363
- Added required `kiloclaw_price_version` row semantics.

0 commit comments

Comments
 (0)