0

I want to implement a paiement in Stripe using Checkout in server side. I followed their tutorial but I can't return the id. I used the following code, just added echo 1,2,3... to check where there is a problem.

When I execute the following code I just return "1".

(of course I have created an account on Stripe)

<?php
    echo "1";
    \Stripe\Stripe::setApiKey('sk_test_XXXXXXXXXXXXXXXXXXXX');
    echo "2";
    $session = \Stripe\Checkout\Session::create([
                                                'payment_method_types' => ['card'],
                                                'line_items' => [[
                                                'name' => 'T-shirt',
                                                'description' => 'Comfortable cotton t-shirt',
                                                'images' => ['https://example.com/t-shirt.png'],
                                                'amount' => 500,
                                                'currency' => 'eur',
                                                'quantity' => 1,
                                                ]],
                                                'success_url' => 'https://example.com/success',
                                                'cancel_url' => 'https://example.com/cancel',
                                                ]);
    echo "3";
    $session_id = $object->id;
    echo "4";
    if ($session_id) {
        echo "sessionID OK";
    } else {  
        echo "No Session ID!";
    }
    echo "5";
?>

Do you know what is wrong ?

droledenom
  • 157
  • 1
  • 10
  • 2
    Does any additional information appear when you [show error messages](https://stackoverflow.com/questions/5680831/php-does-not-display-error-messages)? You also want to make sure that the Stripe library [is included](https://github.com/stripe/stripe-php) properly. – taintedzodiac May 09 '19 at 15:12

1 Answers1

0

I cant see that you import the stripe library.

The go to way to do this is via composer.

If you already have composer you run composer require stripe

If not: install composer from https://getcomposer.org

And then include the path to the generated autoload.php file like this: require "/path/to/vendor/autoload.php";

You could check here for offical stripe docs (referencing what i have said): https://stripe.com/docs/development#php