make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); $key=config('services.stripe.secret'); if (!str_starts_with((string)$key,'sk_test_')) throw new RuntimeException('Test mode required'); $url=route('stripe.webhook'); if(parse_url($url,PHP_URL_SCHEME)!=='https') throw new RuntimeException('HTTPS webhook URL required'); $stripe=new Stripe\StripeClient($key); $endpoint=$stripe->webhookEndpoints->create(['url'=>$url,'enabled_events'=>['checkout.session.completed'],'description'=>'Pawzody test checkout confirmation']); if($endpoint->livemode || !$endpoint->secret) throw new RuntimeException('Unexpected webhook mode'); $path='/home/designsfunnel/pawzody.designsfunnel.us/.env'; $env=file_get_contents($path); $line='STRIPE_WEBHOOK_SECRET='.$endpoint->secret; $count=0; $updated=preg_replace('/^STRIPE_WEBHOOK_SECRET=.*$/m',$line,$env,-1,$count); if(!$count) $updated=rtrim($env).PHP_EOL.$line.PHP_EOL; file_put_contents($path,$updated); echo 'Test webhook registered for '.parse_url($url,PHP_URL_HOST).PHP_EOL; echo 'Webhook signing secret saved securely to .env'.PHP_EOL;