#kdtheegreat
1 messages · Page 1 of 1 (latest)
Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- kdtheegreat-client-testing, 1 day ago, 5 messages
Hello 👋
We do have stripe-mock repo here
https://github.com/stripe/stripe-mock
have you looked at that already?
I have not
I was thinking since I couldn't access any of the text inputs, they would always be empty and reject me hitting the pay button if that makes sense
So completing a checkout is an async process. The API call you make to create the checkout session, comes back with a checkout object
Once the checkout is complete, Stripe updates the same object with relevant details. Typically, merchants use webhooks to listen for these in real-time.
What you could do is run through a test checkout in test mode and clone the checkout object for your tests
You could also use Stripe CLI to trigger each step involved in "completing" a checkout session by running stripe trigger checkout.sessions.completed
So through using the Stipe CLI, I can bypass these errors of empty text fields?
I had tried to "intercept" the confirmPayment request and entering data manually but couldn't get that to work
The CLI adds dummy values to those fields. To be clear, it won't really run any UI tests but it should give you access to the objects that are created on the API side when a checkout is actually completed
also it seems like you're not using Stripe hosted checkout page
We have this doc that talks about automated testing on a higher level
https://stripe.com/docs/automated-testing
I have come across that but that only talks about how to handle errors, not necessarily create successful paths
You could use the usual 4242 card and call the API to see what the object would look like when request succeeds
I suppose what u are referring to when u mean calling the API is creating a paymentIntent which happens when I click on the pay button, but that gives me the error above that the text fields are empty
Right, instead of filling out the form you'd just pass the payment method directly to the PaymentIntent creation API request
Like there are some pre-tokenized payment methods listed here
https://stripe.com/docs/testing?testing-method=payment-methods#cards
you could pass pm_card_visa when creating the payment intent and also confirm it server-side
with no client-side interaction invovled
The response would be identical to what you'd typically see with confirmPayment call
cy.request("POST", "https://api.stripe.com/v1/payment_intents/**/confirm", {
id: "{random id}",
object: "payment_intent",
amount: 55000,
automatic_payment_methods: {
allow_redirects: "always",
enabled: true
},
capture_method: "automatic",
client_secret: "{entered my secret here}",
confirmation_method: "automatic",
created: 1702046327,
currency: "usd",
livemode: false,
payment_method: "pm_1OL5JfLIx0Zt0FdxlT0KWvHh",
payment_method_types: [
"card"
],
shipping: {
address: {
city: "Kings Park",
country: "US",
line1: "123 Sesame Street",
line2: null,
postal_code: "11754",
state: "NY"
},
carrier: null,
name: "adwad",
phone: "",
tracking_number: null
},
status: "succeeded"
})
I tried to send a request like this once i get to my checkout and just got a bunch of errors
You're setting status: "succeeded"
that's not a valid parameter when trying to confirm a PaymentIntent
also the payment intent would have to be in requires_payment_method status when you attempt to confirm it
"error": { "message": "You did not provide an API key. You need to provide your API key in the Authorization header, using Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY').
its saying I didnt enter my api keys but I did replace my secret
doesn't look like it was able to read your secret key and make the request.
Also I'd recommend against actually calling our APIs directly from the test suite
You'd rather want to call it outside the tests and store the response & use that as mock
Stripe CLI would be a good medium to do that
You can use stripe trigger payment_intent.succeeded
This should generate the events/objects for a successful payment
So what I did to get the request object was actually submit a successful payment on my local development, which I copied the request object from network
But how would I test end to end flow if user doesnt make call in test