Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BikashKatwal's avatar

Stripe Recurring payments in laravel

How can I setup Stripe laravel payments in laravel. I have following https://stripe.com/docs/payments/save-and-reuse#web-setup and I am stuck in step 4 \Stripe\Customer::create([ 'payment_method' => $intent->payment_method, ]); When I see the data of $intent.

  +saveWithParent: false
  #_opts: RequestOptions {#241 ▶}
  #_originalValues: array:20 [▶]
  #_values: array:20 [▶]
  #_unsavedValues: Set {#260 ▶}
  #_transientValues: Set {#261 ▶}
  #_retrieveOptions: []
  #_lastResponse: ApiResponse {#258 ▶}
  id: "seti_1FgjPOGiRAGMGVqvfb7pA7kU"
  object: "setup_intent"
  application: null
  cancellation_reason: null
  client_secret: "seti_1FgjPOGiRAGMGVqvfb7pA7kU_secret_GD9iIlXc9OIVKNBItPUGIbJ61U4ao9Z"
  created: 1574218750
  customer: null
  description: null
  last_setup_error: null
  livemode: false
  mandate: null
  metadata: StripeObject {#262 ▶}
  next_action: null
  on_behalf_of: null
  payment_method: null
  payment_method_options: StripeObject {#263 ▶}
  payment_method_types: array:1 [▶]
  single_use_mandate: null
  status: "requires_payment_method"
  usage: "off_session"
}```


Here, payment_method is null. How can I setip payment_method and complete all the steps? Is there any easyily explained tutorials regarding Stripe Recurring Payments?
0 likes
6 replies
BikashKatwal's avatar

@fylzero Thank you, but I have to use stripe libraries because of difficulty in installing composer and artisan commands not executing in my project. This project was built in laravel 4.2 and I dont know why those commands doesn't works so I thould of integrating using stripe libraries and I am having difficulties in understanding in few steps.

fylzero's avatar

@bikashkatwal Sounds like a pain. I'd advise to figure out how to fix composer / migrations / follow an upgrade path to get Cashier on its feet... that said...

Recurring payments are best handled by subscriptions... read up on them here.

https://stripe.com/docs/billing/subscriptions/set-up-subscription

Basically you tokenize a card... add the card to a subscription... Stripe pretty much handles the rest.

If you just want to schedule a recurring dead ahead payment triggered from your app... you're gonna need cron for that... am I'm guessing if you're stuck on composer and migrations... cron won't be an option. lol =)

23 likes
Geekguy's avatar

I feel your pain. I'm migrating to Stripe on a Symfony 2.3 project right now. The site has been around since 2006.

BikashKatwal's avatar

Following the document https://stripe.com/docs/payments/save-and-reuse

  1. Create a SetupIntent:: Here $intent->client_secret is used in button
    $intent = \Stripe\SetupIntent::create();
?>
...
<input id="cardholder-name" type="text">
<!-- placeholder for Elements -->
<div id="card-element"></div>
<button id="card-button" data-secret="<?= $intent->client_secret ?>">
  Save Card
</button>
...```

What I did :

In index.blade.php
 <form id="payment-form" method="post">
        @csrf
        <input id="cardholder-name" type="text">
        <!-- placeholder for Elements -->
        <div id="card-element"></div>
        <button id="card-button" data-secret="<?= $intent->client_secret ?>">
            Save Card
        </button>
    </form>


In PaymentController: Since $intent is used in index.blade.php, I passed $intent by doing the following code.
    public function index()
    {
        \Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));
        $intent = \Stripe\SetupIntent::create();
        return view('payments.index', compact("intent"));
    }

3. Collect card details : I copied and pasted the scripts as explained.

4. Save the card to a customer
\Stripe\Customer::create([
  'payment_method' => $intent->payment_method,
]);
This is only in the documentation

my side of code
public function store(Request $request)
    {
        \Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));

        $intent = \Stripe\SetupIntent::all();

        $customers = \Stripe\Customer::create([
            'payment_method' => $intent->payment_method,
        ]);
        dd($customers);
    }

I am confused here the way I am doing is correct or not? This is setup recurring payments. Please help.
Cronix's avatar

Thank you, but I have to use stripe libraries because of difficulty in installing composer and artisan commands not executing in my project.

You can also just include them in your repo by not ignoring the /vendor folder. Working with Cashier is so much easier with laravel than the sdk directly as the vast majority of the work is already done. I agree with others who suggested to find out why composer isn't working. That single limitation is costing you, or your employer/client, money by having to spend a good deal of extra time working around it.

Please or to participate in this conversation.