Not getting data for authenticated user from database in Laravel for setting stripe

  laravel, laravel-5, stripe-payments

I’ve been trying to get the saved customer id for stripe from database but with no luck.
It works everywhere else, I could get it and save it again if I wanted, but whenever I try to use it in payment intent to automatically renew a subscription, it gives me this error: Trying to get property 'stripecustomerid' of non-object.

this is the bit of the stripe code for recurring charge where the error happens:

 public function renew($subscription)
        header('Content-Type: application/json');

        try {
               $json_str = file_get_contents('php://input');
               $json_obj = json_decode($json_str);
               $user = Auth::user();

               $payment_methods = StripePaymentMethod::all([
                    'customer' => $user->stripecustomerid,
                    'type' => 'card'

               $payment_intent = StripePaymentIntent::create([
                    'amount' => $subscription->plan->stripePrice(),
                    'currency' => 'usd',
                    'customer' => $user->stripecustomerid,
                    'payment_method' => $payment_methods->data[0]->id,
                    'off_session' => true,
                    'confirm' => true,


               echo json_encode([
                    'paymentIntent' => $payment_intent,
      catch (Exception $e) {
                echo json_encode(['error' => $e->getMessage()]);


and stripecustomerid is the name of the column where I saved the customer id.

I can print it in another function, but it just doesn’t work when the subscription tries to renew.

Source: Laravel

Leave a Reply