Search code examples
stripe-payments

Cannot send email parameter while testing Stripe checkout.session.completed webhook


I am trying to trigger a test event using Stripe CLI but getting an error:


stripe trigger checkout.session.completed \
  --add checkout_session:customer_email='[email protected]'
Setting up fixture for: product
Running fixture for: product
Setting up fixture for: price
Running fixture for: price
Setting up fixture for: checkout_session
Running fixture for: checkout_session
Setting up fixture for: payment_page
Running fixture for: payment_page
Setting up fixture for: payment_method
Running fixture for: payment_method
Setting up fixture for: payment_page_confirm
Running fixture for: payment_page_confirm
Trigger failed: Request failed, status=400, body={
  "error": {
    "message": "An error has occurred confirming the Checkout Session.",
    "request_log_url": "https://dashboard.stripe.com/test/logs/req_elQJtM7U0QAPjO?t=1735241822",
    "type": "invalid_request_error"
  }
}

I am in test mode and using the latest Stripe CLI version. What could be causing this error and how can I fix it? Any help would be appreciated. Thanks!

I tried triggering a test checkout.session.completed webhook event using Stripe CLI with this command:

stripe trigger checkout.session.completed \
--add checkout_session:[email protected]

Expected behavior:

The webhook should trigger successfully with the provided email parameter Should receive a success response with test event data

Actual behavior:

Getting an error response:

{
  "error": {
    "message": "An error has occurred confirming the Checkout Session.",
    "request_log_url": "https://dashboard.stripe.com/test/logs/req_M8CaC5kpkEz0JH?t=1735241549",
    "type": "invalid_request_error"
  }
}

I am running this in test mode and have verified that my Stripe CLI is up to date. I need to test this webhook with a specific email parameter for development purposes.


Solution

  • The reason session confirmation fails is because Stripe CLI generates a new PaymentMethod object with dummy data when you trigger the checkout.session.completed event. This PaymentMethod object uses a dummy email address for billing information.

    Checkout Session then fails to match the email that you've passed in to the PaymentMethod billing email. In order to workaround this, you'd want to override the billing email on the PaymentMethod.

    You can do that by using --override flag like:

    stripe trigger checkout.session.completed   
    --add checkout_session:customer_email='[email protected]' 
    --override payment_method:billing_details['email']="[email protected]"
    

    The above code should work! :)