@extends('layouts.user') @section('title') Purchase AI Plan @endsection @section('content') @php $user = auth()->user(); $mainBalance = $user->balance; $grantBalance = $user->grant_balance ?? 0; $canAffordMain = $mainBalance >= $plan->price; $canAffordGrant= $grantBalance >= $plan->price; $activeGrant = \App\Models\Grant::where('user_id', $user->id) ->where('status', 1) ->where('expires_at', '>', now()) ->orderByDesc('expires_at') ->first(); $hasGrant = $activeGrant !== null; // After buying the plan the user must fund it from the SAME wallet. // Pre-calculate whether each wallet can ALSO cover the minimum fund amount. $minFund = $plan->min_fund ?? 0; // What remains in each wallet after the purchase cost is deducted? $mainAfterPurchase = $mainBalance - $plan->price; $grantAfterPurchase = $grantBalance - $plan->price; // Can they meet the minimum funding requirement from what's left? $mainCanFund = $mainAfterPurchase >= $minFund; $grantCanFund = $grantAfterPurchase >= $minFund; @endphp
{{ ucfirst($plan->name) }}
${{ number_format($plan->price, 2) }}
One-time plan purchase · 30-day access
{{-- Plan details --}}
Plan {{ ucfirst($plan->name) }}
Capital Range ${{ number_format($plan->min_fund, 2) }} – ${{ number_format($plan->max_fund, 2) }}
Access One-time funding until next purchase

{{ $plan->description }}

{{-- Wallet selector --}}

Choose payment source

Whichever wallet you purchase with, you must also fund the bot from that same wallet. Minimum bot capital: ${{ number_format($minFund, 2) }}.

@csrf
{{-- Main wallet --}}
{{-- Grant wallet --}} @if($hasGrant)
@else
No active grant available. Apply for a grant →
@endif
{{-- /wallet-selector --}} {{-- Funding warning — shown by JS when selected wallet can't cover min fund --}}
{{-- All-clear strip — shown by JS when everything is fine --}}
The plan cost is deducted from your selected wallet. You must then fund the bot capital from that same wallet. If funded with Grant Funds, AI withdraw proceeds return to your Grant Funds.
@if(!$canAffordMain && !$canAffordGrant)
Insufficient funds in both wallets. Deposit funds →
@else @endif
@endsection