Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • add notif for first failed payment, with a link to pay to recover
  • added upgrade email from free, asking how things are going
  • updated providers that supported granular tool control to support them, small bug to follow best anthropic practice
  • fixed envvar popover unable to use keyboard, wouldn't let me press enter
  • fixed redirect to wrong workspace after oauth connect, store the whole URL instead of going to /workspace

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Nov 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Nov 16, 2025 0:09am

@waleedlatif1 waleedlatif1 marked this pull request as ready for review November 15, 2025 22:43
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 15, 2025

Greptile Overview

Greptile Summary

This PR implements several billing and UX improvements across multiple areas:

Billing & Notifications:

  • Adds payment failure email notifications sent only on the first failed payment attempt (prevents spam during Stripe's automatic retries)
  • Introduces a 90% usage threshold email specifically for free tier users to encourage upgrades
  • Email templates include actionable links to billing portal and clear payment recovery instructions

Provider Tool Control:

  • Updates Cerebras and Groq providers to support granular tool usage control with forced tool tracking for sequential execution
  • Correctly removes forced tool tracking from Ollama provider since it doesn't support the tool_choice parameter beyond basic auto mode
  • Improves best practices alignment for Anthropic-style tool forcing across OpenAI-compatible providers

UI Improvements:

  • Fixes OAuth redirect issue by preserving the full URL path instead of hardcoding /workspace redirect
  • Enhances blocked account UX with direct billing portal access, red styling, and "Payment Required" messaging
  • Removes redundant label text from tool usage control descriptions

Confidence Score: 4/5

  • Safe to merge with minor considerations around error handling edge cases
  • The code is well-structured with proper error handling and logging. The payment failure notification logic correctly sends emails only on first attempt to avoid spam. Provider updates properly handle tool forcing capabilities. The main considerations are around potential edge cases in payment method retrieval and email validation logic, but these are handled with appropriate fallbacks.
  • Pay attention to apps/sim/lib/billing/webhooks/invoices.ts for payment failure email logic and apps/sim/providers/cerebras/index.ts and apps/sim/providers/groq/index.ts for tool forcing implementation

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/lib/billing/webhooks/invoices.ts 4/5 Added payment failure notification system with email sending on first failed payment attempt, including billing portal URL generation and payment method details extraction
apps/sim/components/emails/billing/payment-failed-email.tsx 5/5 New email template for payment failures with payment details, billing portal link, and clear action items for users
apps/sim/lib/billing/core/usage.ts 4/5 Added 90% threshold email for free users in addition to existing 80% threshold, with separate upgrade-focused messaging
apps/sim/providers/cerebras/index.ts 4/5 Implemented proper tool usage control with forced tool tracking for sequential tool execution
apps/sim/providers/groq/index.ts 4/5 Implemented proper tool usage control with forced tool tracking matching Cerebras implementation
apps/sim/providers/ollama/index.ts 5/5 Removed forced tool tracking logic since Ollama doesn't support tool_choice parameter, added warning for forced tools
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/usage-indicator/usage-indicator.tsx 4/5 Enhanced blocked account UX with direct billing portal link, red styling, and "Payment Required" messaging
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/components-new/settings-modal/components/credentials/credentials.tsx 4/5 Fixed OAuth redirect by preserving full URL path instead of hardcoded /workspace redirect

Sequence Diagram

sequenceDiagram
    participant Stripe
    participant Webhook as Invoice Webhook Handler
    participant DB as Database
    participant Email as Email Service
    participant User
    
    Stripe->>Webhook: invoice.payment_failed event
    Webhook->>Webhook: Validate customer ID
    Webhook->>Webhook: Check attempt_count === 1
    
    alt First Payment Failure
        Webhook->>DB: Find subscription by stripeSubscriptionId
        Webhook->>DB: Update subscription status to blocked
        Webhook->>Stripe: Create billing portal session
        Stripe-->>Webhook: Return portal URL
        Webhook->>Stripe: Get payment method details
        Stripe-->>Webhook: Return last 4 digits & failure reason
        
        alt Team/Enterprise Plan
            Webhook->>DB: Get all owners and admins
            Webhook->>DB: Get user details for owners/admins
            loop For each owner/admin
                Webhook->>Email: Send payment failed email
                Email->>User: Payment Failed - Action Required
            end
        else Individual Plan
            Webhook->>DB: Get user details
            Webhook->>Email: Send payment failed email
            Email->>User: Payment Failed - Action Required
        end
    else Retry Attempt (attempt_count > 1)
        Webhook->>Webhook: Skip email (already sent)
        Webhook->>DB: Update subscription status
    end
    
    User->>Email: Click "Update Payment Method"
    Email->>Stripe: Redirect to billing portal
    User->>Stripe: Update payment details
    Stripe->>Webhook: Auto-retry charge

Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

32 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

…l from free, updated providers that supported granular tool control to support them, fixed envvar popover, fixed redirect to wrong workspace after oauth connect
@waleedlatif1 waleedlatif1 merged commit d99d5fe into staging Nov 16, 2025
4 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/payments branch November 16, 2025 00:10
waleedlatif1 added a commit that referenced this pull request Nov 17, 2025
* test(pr): hackathon (#1999)

* test(pr): github trigger (#2000)

* fix(usage-indicator): conditional rendering, upgrade, and ui/ux (#2001)

* fix: usage-limit indicator and render conditonally on is billing enabled

* fix: upgrade render

* fix(notes): fix notes, tighten spacing, update deprecated zustand function, update use mention data to ignore block positon (#2002)

* fix(pdfs): use unpdf instead of pdf-parse (#2004)

* fix(modals): fix z-index for various modals and output selector and variables (#2005)

* fix(condition): treat condition input the same as the code subblock (#2006)

* feat(models): added gpt-5.1 (#2007)

* improvement: runpath edges, blocks, active (#2008)

* feat(i18n): update translations (#2009)

* fix(triggers): check triggermode and consolidate block type (#2011)

* fix(triggers): disabled trigger shouldn't be added to dag (#2012)

* Fix disabled blocks

* Comments

* Fix api/chat trigger not found message

* fix(tags): only show start block upstream if is ancestor (#2013)

* fix(variables): Fix resolution on double < (#2016)

* Fix variable <>

* Ling

* Clean

* feat(billing): add notif for first failed payment, added upgrade email from free, updated providers that supported granular tool control to support them, fixed envvar popover, fixed redirect to wrong workspace after oauth connect (#2015)

* feat(billing): add notif for first failed payment, added upgrade email from free, updated providers that supported granular tool control to support them, fixed envvar popover, fixed redirect to wrong workspace after oauth connect

* fix build

* ack PR comments

* feat(performance): added reactquery hooks for workflow operations, for logs, fixed logs reloading, fix subscription UI (#2017)

* feat(performance): added reactquery hooks for workflow operations, for logs, fixed logs reloading, fix subscription UI

* use useInfiniteQuery for logs fetching

* fix(copilot): run workflow supports input format and fix run id (#2018)

* fix(router): fix error edge in router block + fix source handle problem (#2019)

* Fix router block error port handling

* Remove comment

* Fix edge execution

* improvement: code subblock, action bar, connections (#2024)

* improvement: action bar, connections

* fix: code block draggable resize

* fix(response): fix response block http format (#2027)

* Fix response block

* Lint

* fix(notes): fix notes block spacing, additional logs for billing transfer route (#2029)

---------

Co-authored-by: Vikhyath Mondreti <vikhyathvikku@gmail.com>
Co-authored-by: Emir Karabeg <78010029+emir-karabeg@users.noreply.github.com>
Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
Sg312 pushed a commit that referenced this pull request Nov 18, 2025
…l from free, updated providers that supported granular tool control to support them, fixed envvar popover, fixed redirect to wrong workspace after oauth connect (#2015)

* feat(billing): add notif for first failed payment, added upgrade email from free, updated providers that supported granular tool control to support them, fixed envvar popover, fixed redirect to wrong workspace after oauth connect

* fix build

* ack PR comments
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