[Answered ]-Stripe client_reference_id: null in checkout.session.completed

1πŸ‘

βœ…

I was facing the same issue albeit in different technology stack.

The solution is to pass the extra info you require as metadata parameter. See Stripe docs on this.

So:

Session.create(
  success_url="https://example.com/success",
  cancel_url="https://example.com/cancel",
  line_items=[
    ...
  ],
  metadata={
    'user_id': my_user_id,
  }
)

this metadata dict is to be passed onto checkout.session.completed webhook event.

So:

if event['type'] == 'checkout.session.completed':
  session = event['data']['object']
  metadata = session['metadata']
  ..
  user_id = metadata.get('user_id')
  ..
  user = CustomUser.objects.get(id=user_id)

The metadata param is attached to most Stripe objects.

However, the checkout.session.expired and payment_intent.canceled (and probably others?) don’t pass the previously fulfilled metadata.

πŸ‘€mlen108

Leave a comment