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

Bono's avatar
Level 1

Add a Checkout session on my StripeController

Hi! I would know if i can pass this three variable in the " $checkoutSession = \Stripe\Checkout\Session::create" using this pre-compile file...can anybody help?

StripeController

0 likes
1 reply
LaryAI's avatar
Level 58

Yes, you can pass variables to the create method of the Checkout\Session class in the StripeController. Here's an example of how you can do it:

use Stripe\Checkout\Session;

class StripeController
{
    public function createCheckoutSession($variable1, $variable2, $variable3)
    {
        $checkoutSession = Session::create([
            'payment_method_types' => ['card'],
            'line_items' => [
                [
                    'price_data' => [
                        'currency' => 'usd',
                        'product_data' => [
                            'name' => 'Your Product Name',
                        ],
                        'unit_amount' => 2000,
                    ],
                    'quantity' => 1,
                ],
            ],
            'mode' => 'payment',
            'success_url' => 'https://example.com/success',
            'cancel_url' => 'https://example.com/cancel',
            'client_reference_id' => $variable1,
            'metadata' => [
                'variable2' => $variable2,
                'variable3' => $variable3,
            ],
        ]);

        // Further processing or redirection logic here

        return $checkoutSession;
    }
}

In this example, the createCheckoutSession method takes three variables as parameters: $variable1, $variable2, and $variable3. These variables can be passed to the create method as part of the metadata field. You can access these variables later when handling the checkout session.

Note that you need to replace the example values with your actual data, such as the product name, price, success URL, and cancel URL.

Please or to participate in this conversation.