I am integrating Stripe payment in Laravel 5.1 for the first time and I am referring this tutorial Simple Payments with Stripe and Laravel and completed all the steps.
After payment, I am getting this error:
In stripe logs, its show me the payment done successfully.
I am getting this error in this function:
public function createStripeCustomer($token)
{
\Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
$customer = \Stripe\Customer::create(array(
"description" => Auth::user()->email, <-- Error at this line
"source" => $token
));
//Auth::user()->stripe_id = $customer->id;
Auth::user()->save();
return $customer;
}
I have created bellow schema for the user but don't understand which details need to store:
Schema::table('users', function ($table) {
$table->string('stripe_id')->nullable();
$table->string('card_brand')->nullable();
$table->string('card_last_four')->nullable();
$table->timestamp('trial_ends_at')->nullable();
});
Protect your Route using Auth middleware:
Route::get('stripepayment', [
'middleware' => 'auth',
'uses' => 'OrderController@savePayment'
]);
it will automatically check for Auth::user() and redirect you to login page if by chance you logout.
your code gives error because it fails to get Auth::user() because you are not logged-in.