Skip to main content

Billing & Credits

The billing feature handles Stripe checkout, credit balance management, pre-operation credit validation, and billing error detection.

Checkout

Hook: useCheckout (lib/hooks/useCheckout.ts)

Orchestrates the Stripe subscription checkout flow:

  1. User selects a plan (and optional promo code)
  2. Hook determines whether to use company or personal checkout
  3. Redirects to Stripe Checkout session
  4. On return, subscription is activated

Method: startCheckout(planId, promoCodeId?)

Requires an authenticated user.

Credit Check

Hook: useCreditCheck (lib/hooks/useCreditCheck.ts)

Pre-operation credit balance validation. Called before AI operations to ensure sufficient credits:

OptionTypePurpose
estimatedCostnumberExpected credit cost of the operation
customMessagestringCustom warning message

Returns: CreditCheckResult with balance, warningThreshold, and showWarning flags.

Billing Error Detection

Hook: useBillingError (lib/hooks/useBillingError.ts)

Intercepts GraphQL errors and maps them to user-friendly billing messages:

Error CodeHTTP StatusMeaning
INSUFFICIENT_CREDITS402Not enough credits for the operation
PLAN_LIMIT_EXCEEDED403Feature limit reached on current plan
SUBSCRIPTION_INACTIVE--No active subscription
INVALID_PLAN_PRICING--Plan pricing configuration error

Methods: detectBillingError(), showBillingToastIfNeeded()

The BillingErrorToastHandler component (in the provider hierarchy) automatically intercepts these errors and shows toast notifications.

Credit Balance

Hook: useCreditBalance (lib/hooks/useCreditBalance.ts)

Fetches the current credit balance, automatically routing to the correct balance (company or personal) based on the authenticated context.

Other Billing Hooks

HookFilePurpose
useBillingConfiguseBillingConfig.tsFetch billing configuration and pricing
useCreditPurchaseuseCreditPurchase.tsCredit pack purchase flow
useSubscriptionStatususeSubscriptionStatus.tsCheck subscription status and feature eligibility

Components

ComponentFilePurpose
PromoCodeInputcomponents/reusable/payments/PromoCodeInput.tsxPromo code entry with validation
BillingErrorToastHandlerIn provider hierarchyAuto-intercepts billing errors

Pages

RoutePurpose
app/company/credits/Company credit management and billing
app/jobseeker/credits/Personal credit management
app/jobseeker/pricing/Subscription plan selection