%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/
Upload File :
Create Path :
Current File : //home/forge/api-takeaseat.eco-n-tech.co.uk/app/Console/Commands/CreateStripeCustomers.php

<?php

namespace App\Console\Commands;

use App\Models\User;
use Laravel\Cashier\Cashier;
use Illuminate\Console\Command;

class CreateStripeCustomers extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'stripe:create-customers';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Create all current users as a stripe customer';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $users = User::orderBy('created_at', 'desc')
            ->where('stripe_id', '=', '')
            ->orWhereNull('stripe_id')
            ->get();

        foreach($users as $user) {
            try {
                $user->createAsStripeCustomer([
                    'name' => $user->full_name
                ]);
                
                $this->info("Creating stripe customer for: {$user->id}!");
            } catch (Exception $e) {
                $this->info("Error: {$e->getMessage()}!");
                continue;
            }
        }
    }
}

Zerion Mini Shell 1.0