Skip to content

feat: Configure AI usage counter#11

Draft
kofimokome wants to merge 3 commits into
mainfrom
feat/ai-allowance
Draft

feat: Configure AI usage counter#11
kofimokome wants to merge 3 commits into
mainfrom
feat/ai-allowance

Conversation

@kofimokome

@kofimokome kofimokome commented Jun 28, 2026

Copy link
Copy Markdown
Collaborator

Fixes #7

@kofimokome kofimokome marked this pull request as draft June 28, 2026 16:52
@sourceant

sourceant Bot commented Jun 28, 2026

Copy link
Copy Markdown

Code Review Summary

This PR introduces AI usage tracking and Stripe-based billing using Laravel Cashier. It includes migrations for usage counters and billing entities, a service for entitlement management, and a checkout controller.

🚀 Key Improvements

  • Integrated Laravel Cashier for subscription management.
  • Implemented an idempotency check for token consumption using Laravel Cache.
  • Added OpenAPI (Swagger) documentation for the new checkout endpoint.

💡 Minor Suggestions

  • Standardize config keys in cloudplans.php.
  • Use explicit dependency injection for usage tracking instead of backtraces.

🚨 Critical Issues

  • Stripe webhook endpoint lacks signature verification middleware.
  • Potential 'Undefined index' in CloudController when region is missing from config.

@sourceant sourceant Bot 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.

Review complete. See the overview comment for a summary.

Comment thread config/cloudplans.php
'us' => [
'name' => 'United States',
'currency' => 'USD',
'monthly_price_id'=>'plan_id', // from stripe

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The keys 'monthly_price_id' and 'yearly_price_id' should be consistent across all regions and should preferably use ENV variables instead of hardcoded 'plan_id' or 'price_id' placeholders to ensure security and flexibility across environments.

Suggested change
'monthly_price_id'=>'plan_id', // from stripe
'monthly_price_id' => env('STRIPE_MONTHLY_PRICE_ID_US'),
'monthly_price' => (float) env('CLOUD_PLAN_MONTHLY_PRICE_US', 5.00),
'yearly_price' => (float) env('CLOUD_PLAN_YEARLY_PRICE_US', 50.00),
'yearly_price_id' => env('STRIPE_YEARLY_PRICE_ID_US'),

/**
* Find the chat message ID from the backtrace to key the idempotent increment.
*/
private function getCurrentChatMessageId(): ?int

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using debug_backtrace to implement idempotency is highly discouraged. It is slow and relies on internal call structures that may change. Pass the message ID or an idempotency token explicitly to the consume method instead.

Suggested change
private function getCurrentChatMessageId(): ?int
// Recommended: Pass the unique identifier directly to the consume method.
// If that is not possible, ensure ProcessChatMessageJob is always present in the stack.

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.

feat(cloud): Add Stripe subscriptions via Cashier mirror

1 participant