#kdtheegreat

1 messages · Page 1 of 1 (latest)

rain crystalBOT
#

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.

lusty blade
tough bridge
#

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

lusty blade
#

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

tough bridge
#

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

lusty blade
#

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

tough bridge
#

yeah im using custom elements

#

I have been stuck on this for the pass few days lol

lusty blade
tough bridge
#

I have come across that but that only talks about how to handle errors, not necessarily create successful paths

lusty blade
#

You could use the usual 4242 card and call the API to see what the object would look like when request succeeds

tough bridge
#

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

lusty blade
#

Right, instead of filling out the form you'd just pass the payment method directly to the PaymentIntent creation API request

#

with no client-side interaction invovled

#

The response would be identical to what you'd typically see with confirmPayment call

tough bridge
#
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

lusty blade
#

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

tough bridge
#

"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

lusty blade
#

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

tough bridge
#

ah

#

idk how else to make the api call

lusty blade
#

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

tough bridge
#

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

tough bridge