skip to Main Content

I am doing a Stripe Checkout payment.

I’ve created a Stripe Session so the user can fill his information:

$session = StripeCheckoutSession::create([ 
            ...
       ]);

Once he is redirected to the success page, I call a function that retrieve the Stripe Checkout Session with the session_id.

$checkout_session = StripeCheckoutSession::retrieve($session_id);

After that, I want to retrieve Customer info to store in database. So I do:

$customer = StripeCustomer::retrieve($checkout_session->customer);

Here is the problem. Stripe is returning an error:
StripeCustomer instance has invalid ID: StripeGetOrder.php(34): StripeCustomer::retrieve(NULL)

So, in Live mode of Stripe, $checkout_session->customer return NULL.

After I checked the documentation, creating a new Stripe Session should also create a new Customer with a new ID, so why the customer’s ID is NULL when I retrieve my Session?

Thanks,
Skyfrid

3

Answers


  1. Checkout will create a new Customer object based on information provided during the payment flow. The customer will only be created once the payment has been complete.

    Login or Signup to reply.
  2. It is possible for a Checkout Session to not create a Customer on success(for example: when mode=setup on the Checkout Session object). Assuming that is not the case: do you know that $checkout_session->customer is actually null? In other words, does echo $checkout_session->customer return a Customer ID?

    If it turns out that Customer is indeed null and you are not setting mode=setup on the Checkout Session object, then it might be that either (a) the Customer retrieve call went through before the Checkout Session was completed by the customer, or (b) the payment was not actually successful and the customer was not redirected to the success_url after all.

    Note: a Customer is only created after a payment is successful when using Checkout.

    I would recommend finding that specific Checkout Session in the Stripe Dashboard logs (see here), so you can figure out when the retrieve call was made during the lifecycle of the session.

    Login or Signup to reply.
  3. Checkout will not create a Customer by default if one is not required. You have to set customer_creation: 'always' if you want to force a Customer to be created all the time. This is documented here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search