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

vincent15000's avatar

Need some advice for Stripe to display prices

Hello,

I have read somewhere that it's possible to manage prices only on Stripe and display the prices on (for example) a Laravel application, just via a link generated on Stripe.

Hmmm I can't find this functionality, who knows it ?

And then another question : if the prices are only managed on Stripe, what's the best solution to identify which plan a user has subscribed to on the application, for example to apply some restrictions like a max number of users ?

Thanks for your help.

V

0 likes
2 replies
LaryAI's avatar
Level 58

To manage and display prices from Stripe in your Laravel application, you can use Stripe's API to fetch the prices and display them dynamically. Here's a step-by-step guide on how to achieve this:

Step 1: Set Up Stripe in Your Laravel Application

First, ensure you have the Stripe PHP library installed in your Laravel application. You can do this via Composer:

composer require stripe/stripe-php

Step 2: Configure Stripe

Add your Stripe API keys to your .env file:

STRIPE_SECRET=your_stripe_secret_key
STRIPE_PUBLIC=your_stripe_public_key

Step 3: Fetch Prices from Stripe

You can create a controller method to fetch prices from Stripe. Here's an example:

use Stripe\Stripe;
use Stripe\Price;

public function getPrices()
{
    Stripe::setApiKey(env('STRIPE_SECRET'));

    $prices = Price::all(['limit' => 10]); // Adjust the limit as needed

    return view('prices.index', compact('prices'));
}

Step 4: Display Prices in Your View

In your Blade view, you can loop through the prices and display them:

@foreach ($prices->data as $price)
    <div>
        <p>Product: {{ $price->product }}</p>
        <p>Price: {{ $price->unit_amount / 100 }} {{ strtoupper($price->currency) }}</p>
    </div>
@endforeach

Step 5: Identify User's Plan

To identify which plan a user has subscribed to, you can store the subscription ID or plan ID in your database when the user subscribes. You can then use this information to apply restrictions or features based on the user's plan.

Here's a basic example of how you might store and check a user's subscription:

// When a user subscribes
$user->subscription_id = $stripeSubscriptionId;
$user->save();

// To check the user's plan
if ($user->subscription_id) {
    // Fetch subscription details from Stripe
    $subscription = \Stripe\Subscription::retrieve($user->subscription_id);

    // Check the plan
    if ($subscription->items->data[0]->price->id == 'your_plan_id') {
        // Apply restrictions or features
    }
}

Conclusion

By using Stripe's API, you can dynamically manage and display prices in your Laravel application. Storing subscription details in your database allows you to easily identify and manage user plans. Make sure to handle any exceptions and errors that may occur when interacting with the Stripe API.

vincent15000's avatar

Lary's response seems interesting, but the solution I'm looking for is completely externalized from the application. A stripe link allows to display the prices and pay for a subscription.

Please or to participate in this conversation.