stripe-dotnet
stripe-dotnet copied to clipboard
checkout_session.payment_intent_data can not be retrieved when downloading the session object
Is your feature request related to a problem? Please describe.
We're using payment_intent_data.metadata to store metadata values that should be added to the payment intent created by the checkout session.
I'm currently trying to write automated integration tests and would like to assert that the created checkout session has the proper metadata configured, however it seems like the information from payment_intent_data is not returned when I download the checkout session (using GET /v1/checkout/sessions/id via .NET SDK).
Describe the solution you'd like
When loading the checkout session the payment_intent_data property should be included or expandable.
Describe alternatives you've considered
I've tried to complete the checkout session and check the metadata of the created payment intent, however it looks like this is not possible programmatically (even in sandbox mode) without ui-based e2e tests.
Additional context
No response
Hi @dominik-weber Since Stripe API Version 2022-08-01. A PaymentIntent is no longer created during Checkout Session creation in payment mode. Instead, a PaymentIntent will be created when the Session is confirmed.
Therefore, if you are using a Stripe API version that is greater or equals to 2022-08-01, you'll want to expand the payment_intent field only when the checkout session is completed.
I'd also remind you that Stripe has security measures in place to prevent automated testing in frontend interfaces such as Checkout and Elements.
@seanzhang-stripe thanks for the quick response! Unfortunately it is not possible to complete the checkout session for the reasons mentioned. Instead, I would like to read the values before the checkout is completed.
Please note that I'm not trying to read the metadata of the (not yet created) payment intent, but from the checkout session payment_intent_data. My understanding is that this information is stored in the checkout session and used to prefill the payment intent once it will be created.
Could you please reopen the issue? I think the request is still valid :)
Hi @dominik-weber payment_intent_data is param that you can specify when you create a Checkout Session, it isn't a attribute that you can access from a Checkout Session object.
Can you tell me more about your integration? especially about why you need to access the payment_intent_data before the completion of a Checkout Session?
This is the workflow I want to execute (as a integration test):
- Run normal app logic (which will create the checkout session, required database entries etc.)
- The checkout session id is returned to the test
- Download the checkout session object from Stripe api
- Assert that the price provided in step 1 is correct (this works already!)
- Assert that the
payment_intent_datametadata provided in step 1 is correct
Normally after step 1 the checkout session id would be sent to the frontend to ask the user for payment, instead i want to programatically assert that the data inside is correct.
Thanks for the context.
You won't be able to automate the end-to-end flow due to the security measures in frontend interface. I'd recommend use stripe-mock to mock a response of a completed checkout session, so that you can assert the metadata on the mocked object.
Hi, thanks for the clarification.
My goal is not to test the flow end-to-end. Instead, I just wanna see if the checkout session has been created with the right properties.
In my opinion, payment_intent_data is still a property on the checkout session (even if it will affect the payment intent later down the line), and as such it should be possible to read back what i've sent in the create session request.
I'll try to provide more context on what I want to do, I hope this better helps you understand my problem.
Essentially I'm trying to write tests for a service that I've created called PaymentService to test the functionality of these methods:
ProcessOrder(): This will store an order in the database and create the stripe checkout session. I want to test if the total sum, used currency etc. is correct. Additionally, the stripe checkout session needs to have the proper metadata for the second call:ProcessWebhook(): This is triggered from Stripe webhooks, upon receiving apayment_intent_succeededevent it will mark the order as "payed" and forward it to our ERP. The method needs the metadata from stripe payment intent to figure out which order the payment was for.
These are the tests I'm planning to write (please note that I want to avoid mocking external services here):
Test 1: Check if order can be processed and checkout session is created
- Call
PaymentService.ProcessOrder() - Download the resulting checkout session from stripe api
- Assert that the price, metadata etc. of the checkout session is correct (Please note that I'm making these assertions on the checkout session object. I don't want to make the purchase and assert afterwards!)
Test 2: Check if purchase can be processed
- Manually create a fake
payment_intent_succeededjson event from stripe with fake payment intent id but "real" metadata - Call
PaymentService.ProcessWebhook()with the fake json (Let me be very clear here to avoid any confusion: While running the test, this endpoint will NOT be triggered by stripe because there is no real purchase. Instead, I'm triggering the endpoint myself with a fake json event) - Assert that all orders have been marked as "payed" in the database and forwarded to ERP system
I'll have a look at stripe-mock to see how I could use it in the future, however I still think it would be good if the checkout session api was able to return all information that was specified on creation.
Sorry for the long post! :)
Thanks for the detailed explanation.
It's Stripe's responsibility to make sure that the metadata that you set on a Checkout Session's payment_intent_data should match the metadata on the PaymentIntent that the same Checkout Session generates upon its completion. Your own test cases should focus on your own business logic.
You won't be able to assert the PaymentIntent metadata in Test 1 because Checkout Session object doesn't carry the payment_intent_data attribute, and its PaymentIntent will only be populated upon completion. For Test 2, I believe you can achieve it by using stripe-mock.