Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Stripe API loop over subscription plans

David Carr

Stripe API Tutorials Nova Framework

Have subscription plans setup on Stripe? this post will guide you on using Stripe’s API to get all subscription plans from your account.

I’m using Nova Framework not setup with Nova? please read Getting Stripe API setup with Nova Framework

To get all subscriptions:

$plans = Plan::all()->data;

This returns an array containing the plans:

{
    "id": "12 months",
    "object": "plan",
    "amount": 40000,
    "created": 1503494115,
    "currency": "gbp",
    "interval": "year",
    "interval_count": 1,
    "livemode": false,
    "metadata": [
      
    ],
    "name": "12 Months",
    "statement_descriptor": "12 Months",
    "trial_period_days": null
}

 To put this into a selectable list:

<select name="package_id" required>
    <option value="">Select</option>
    @foreach($plans as $plan)
        <option value="{{ $plan->id }}">{{ $plan->name }}</option>
    @endforeach
</select>

To get a single plan by its id:

Plan::retrieve($id)

 

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.