According to Stripe documentation
First creating a checkout session with $stripe->checkout->sessions->create()
. But at this point we don't have customer_id.
Then embedded checkout is triggered and customer pays.
Then after successful payment we get session_id
on success page. Now we are able to retrieve customer_id
.
At step 3 we are able get customer_id
but the webhooks are already fired before success page load. And at the webhook trigger time we don't have customer_id
to identify for which customer this customer_id
mentioned in webhook is about.
$stripe->checkout->sessions->create()
allows client_reference_id
parameter but webhook data don't return this field.
How can we get customer_id
of new customer before webhook is triggered?
If you need a customer.id
already at Checkout creation time, then I would recommend creating a Customer through the API and then passing the customer.id
of the newly created Customer in the Checkout Session.
The webhook events you are mentioning now are not webhook events for the Checkout Session, but for the Subscription. I assumed you were talking about Checkout Session events previously. The webhook events for the Checkout Session would also include the customer.id
.
With that being said, you can pass in additional information about the Customer not in the Session’s metadata
object, but into the subscription_data.metadata
object. This specific metadata
object will be added to the corresponding Subscription object and with that will also be available in the webhook events you mentioned.