Skip to content

feat(auto-recharge): enterprise#2127

Merged
mogery merged 5 commits intomainfrom
mogery/eng-3429-use-acucprice_associated_auto_recharge_price_id-in-acuc
Sep 15, 2025
Merged

feat(auto-recharge): enterprise#2127
mogery merged 5 commits intomainfrom
mogery/eng-3429-use-acucprice_associated_auto_recharge_price_id-in-acuc

Conversation

@mogery
Copy link
Copy Markdown
Member

@mogery mogery commented Sep 9, 2025

Summary by cubic

Adds enterprise auto‑recharge that creates a Stripe subscription to top up credits when teams drop below a threshold, driven by ACUC.price_associated_auto_recharge_price_id. Addresses ENG-3429 with a safe, locked flow, notifications, and cache refresh.

  • New Features

    • Enterprise auto‑recharge path when price_associated_auto_recharge_price_id is set.
    • Creates a new Stripe subscription (off-session) for the recharge price; clones valid coupons from the main subscription; tags metadata with team_id and auto_recharge.
    • Guardrails: redlock to avoid duplicate charges, max 4 recharges/month, and a weekly “frequent recharge” notification from the second event.
    • ACUC updated with price_associated_auto_recharge_price_id; RPCs bumped to auth_credit_usage_chunk_35; clears ACUC caches after recharge.
  • Dependencies

    • Adds @mendable/firecrawl-rs (and platform binaries) and builds it via pnpm onlyBuiltDependencies.

@mogery mogery requested a review from nickscamara as a code owner September 9, 2025 14:18
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

3 issues found across 9 files

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

Comment thread apps/api/src/services/billing/stripe.ts Outdated
Comment thread apps/api/src/services/billing/stripe.ts Outdated
Comment thread apps/api/src/services/billing/stripe.ts Outdated
@mogery
Copy link
Copy Markdown
Member Author

mogery commented Sep 9, 2025

@cubic-dev-ai re-review

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Sep 9, 2025

@cubic-dev-ai re-review

@mogery I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 8 files

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

}
});
} catch (error) {
logger.error(`Failed to acquire lock for auto-recharge`, { error });
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Sep 9, 2025

Choose a reason for hiding this comment

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

Misleading error message: this catch can capture non-lock errors from within the critical section; use a generic message to aid debugging.

Prompt for AI agents
Address the following comment on apps/api/src/services/billing/auto_charge.ts at line 320:

<comment>Misleading error message: this catch can capture non-lock errors from within the critical section; use a generic message to aid debugging.</comment>

<file context>
@@ -34,10 +38,307 @@ export async function autoCharge(
+      }
+    });
+  } catch (error) {
+    logger.error(`Failed to acquire lock for auto-recharge`, { error });
+    return {
+      success: false,
</file context>
Suggested change
logger.error(`Failed to acquire lock for auto-recharge`, { error });
logger.error(`Auto-recharge failed`, { error });

team_id,
auto_recharge: "true",
},
...(discount.coupon.percent_off
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Sep 9, 2025

Choose a reason for hiding this comment

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

Duplicate percent_off key in coupons.create; the latter overrides the former and may mask the intended value. Remove one of the definitions.

Prompt for AI agents
Address the following comment on apps/api/src/services/billing/stripe.ts at line 132:

<comment>Duplicate percent_off key in coupons.create; the latter overrides the former and may mask the intended value. Remove one of the definitions.</comment>

<file context>
@@ -57,3 +62,120 @@ export async function createPaymentIntent(
+                team_id,
+                auto_recharge: &quot;true&quot;,
+              },
+              ...(discount.coupon.percent_off
+                ? { percent_off: discount.coupon.percent_off }
+                : {}),
</file context>

@mogery
Copy link
Copy Markdown
Member Author

mogery commented Sep 10, 2025

@cubic-dev-ai re-review

@cubic-dev-ai
Copy link
Copy Markdown
Contributor

cubic-dev-ai Bot commented Sep 10, 2025

@cubic-dev-ai re-review

@mogery I've started the AI code review. It'll take a few minutes to complete.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 8 files

@mogery mogery force-pushed the mogery/eng-3429-use-acucprice_associated_auto_recharge_price_id-in-acuc branch from 0cea50a to 8fc4aab Compare September 11, 2025 15:25
@mogery mogery force-pushed the mogery/eng-3429-use-acucprice_associated_auto_recharge_price_id-in-acuc branch from 93810b8 to cf87838 Compare September 15, 2025 15:47
@mogery mogery force-pushed the mogery/eng-3429-use-acucprice_associated_auto_recharge_price_id-in-acuc branch from cf87838 to 9a77409 Compare September 15, 2025 16:00
@mogery mogery merged commit 87dc366 into main Sep 15, 2025
3 of 12 checks passed
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