The error message suggests that the Stripe API key is not being provided. The solution is to ensure that the API key is set correctly.
In this case, the .env file seems to have the correct keys set. However, the code does not seem to be using the Stripe API key.
To use the Stripe API key, you need to pass it to the StripeClient instance. In Laravel Cashier, this is done automatically when you use the Billable trait.
In the code provided, the Billable trait is being used, but the payWith method is not passing the Stripe API key.
To fix this, you can pass the Stripe API key as the second argument to the payWith method.
For example:
$payment = $rootUser->payWith('20', ['card'], $this->stripeOptions());
Here, the stripeOptions method returns an array with the api_key key set to the Stripe API key.
You can define the stripeOptions method in the User model like this:
public function stripeOptions()
{
return [
'api_key' => config('services.stripe.secret'),
];
}
This method returns an array with the api_key key set to the Stripe API key from the .env file.
Make sure to import the config helper at the top of the file:
use Illuminate\Support\Facades\Config;
With this change, the payWith method should be able to use the Stripe API key and the error should be resolved.