Retrieve the price for Product from stripe using laravel Cashier

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

Retrieving Stripe Product Prices in Laravel Cashier: A Deep Dive

When building robust e-commerce applications with Laravel and Stripe, developers often rely on Laravel Cashier to manage subscriptions and payments seamlessly. However, there are times when you need to interact directly with the raw data stored on the Stripe platform—specifically retrieving details like the price associated with a given Price ID. This guide will walk you through the correct, developer-focused way to achieve this integration.

The Challenge: Bridging Cashier and Raw Stripe Data

You have a specific Stripe Price ID, for example, "price_1IYwYtA4vM4p6MlHCuiAZx9X", which corresponds to a product costing $25.00 USD. Your goal is to use Laravel Cashier (which handles subscriptions) to retrieve this cost information.

The key understanding here is that while Laravel Cashier manages the transactional state (subscriptions, invoices) within your Laravel database, it generally relies on the underlying Stripe API for fetching immutable product metadata, such as specific price details, which are managed exclusively by Stripe. Therefore, retrieving the price requires making a direct, secure API call to Stripe, rather than expecting Cashier to magically hold this external reference data directly in its models.

The Solution: Direct Stripe API Interaction via a Service Layer

The most robust pattern for handling external API interactions in Laravel is to abstract these calls into dedicated Service Classes. This keeps your controllers clean and adheres to the principles of separation of concerns, which is critical when building scalable applications like those promoted by the team at laravelcompany.com.

We will use the official Stripe PHP library to interact directly with Stripe's API endpoints.

Step 1: Setting up the Service

Create a dedicated service class to handle all communication with Stripe. This keeps your business logic separate from HTTP concerns.

// app/Services/StripePriceService.php

namespace App\Services;

use Stripe\StripeClient;

class StripePriceService
{
    protected $stripe;

    public function __construct()
    {
        // Initialize the Stripe Client using your secret key
        $this->stripe = new StripeClient(config('services.stripe.secret'));
    }

    /**
     * Retrieves details for a specific Stripe Price ID.
     *
     * @param string $priceId The ID of the Stripe Price to retrieve.
     * @return array|object The price details from Stripe.
     * @throws \Exception If the API call fails.
     */
    public function getPriceDetails(string $priceId)
    {
        try {
            // Fetch the Price object from Stripe
            $price = $this->stripe->prices->retrieve($priceId);

            // Return the relevant cost information
            return [
                'id' => $price->id,
                'amount' => $price->amount, // Amount is in the smallest currency unit (cents)
                'currency' => $price->currency.toUpperCase(),
                'description' => $price->description ?? 'N/A',
            ];

        } catch (\Stripe\Exception\ApiErrorException $e) {
            // Handle specific Stripe API errors gracefully
            throw new \Exception("Stripe API Error: " . $e->getMessage());
        }
    }
}

Step 2: Using the Service in a Controller

Now, inject this service into your controller where you need to fetch the price information.

// app/Http/Controllers/ProductController.php

namespace App\Http\Controllers;

use App\Services\StripePriceService;
use Illuminate\Http\Request;

class ProductController extends Controller
{
    protected $stripeService;

    /**
     * Dependency Injection of the service
     */
    public function __construct(StripePriceService $stripeService)
    {
        $this->stripeService = $stripeService;
    }

    public function showProductPrice(Request $request, string $priceId)
    {
        try {
            // Call the service layer to get the price details
            $priceData = $this->stripeService->getPriceDetails($priceId);

            return response()->json([
                'status' => 'success',
                'product_id' => $priceId,
                'cost' => number_format($priceData['amount'] / 100, 2), // Convert cents to dollars
                'currency' => $priceData['currency'],
            ]);

        } catch (\Exception $e) {
            return response()->json(['status' => 'error', 'message' => $e->getMessage()], 500);
        }
    }
}

Conclusion

By abstracting the external Stripe API calls into a dedicated service class, you achieve clean separation of concerns. This approach ensures that your Laravel application remains testable, maintainable, and scalable—a philosophy highly aligned with modern framework development principles seen throughout laravelcompany.com. While Laravel Cashier excels at managing the lifecycle of subscriptions within your database, leveraging a well-structured service layer allows you to seamlessly integrate complex external data like Stripe pricing into your application logic whenever necessary.