#r3v3rb

1 messages · Page 1 of 1 (latest)

desert juncoBOT
dusty silo
#

Hi there. Taking over for bismarck as they have to step out soon. Are you referring to a stripe api response object that you want to mock?

junior elbow
#

Indeed, I was hoping to use the CLI so that the webhook would fire but I'm told it should be a mock object

#

\o/

dusty silo
#

Skimming the previous thread it's because you want to keep the same id

#

So yeah mock is the way to go

#

Basically just run through the flow once and copy and paste the response object (modifying other fields as you see fit)

junior elbow
#

Any document showing this for checkout.session.complete objects?

dusty silo
#

No it's a bit of an uncommon ask, so there's no support article

#

What part is still unclear? I can get more specific if need be

junior elbow
#

Okay, firstly where does the mock object get called/created because I'm hoping to fire off a webhook with the data

dusty silo
#

It would have to all be done through your end, not Stripe. Code on your end would generate the mock response object then hit your endpoint with it.

junior elbow
#

okay so create a new controller, create an object with the session id and then hit the webhook with that data?

#

Seems like it would be much easier if the API/CLI could handle being passed a session id/customer id etc and fire the trigger accordingly

#

stripe trigger checkout.session.completed --session-id=ca_&^^& for example

dusty silo
#

Yeah it's just currently not possible

#

You can write in to support to feature request it

#

But no guarantees if it would be implemented

junior elbow
#

🙂 always happy to be outside the box!

#

Reason being is the subscriptions we are offering are to clients who have accounts already on our solution - so this is an extra for them to use. So the whole process of Stripe creating customers/then us creating customers on our end to match via webhook is back to front

#

we already have a customer, but need to use the session_id to get the customer details in the checkout.session.completed by that ID to apply their subscription status

dusty silo
#

That all makes sense. Is the reason you need to generate an event with the same checkout session each time for automated testing purposes? Just curious why your testing flow needs the same id each time

junior elbow
#

yep, otherwise I'm in the browser checking out and waiting for the webhook to fire for each event

#

to ensure I'm getting the same customer(my side) that subscribed/checked out (your id)

dusty silo
#

Fair enough

#

Yeah mocking is what you'll need. For automated testing flows, that makes the most sense

junior elbow
#

only for this testing as there are at least five webhooks to process

#

I guess this needs to change too for testing: $event = Webhook::constructEvent( $payload, $sig_header, $endpoint_secret );

#

where payload is my mock data from a previous manual call stored locally

dusty silo
#

Correct yeah you wouldn't make that call in a test scenario with a mock

junior elbow
#

so I could just grab the $event data and have that as the mock object then?

dusty silo
#

Yep

junior elbow
#

Now to find out how to create mock object!

#

google will hopefully be my friend

dusty silo
#

It should mostly just be copy paste

junior elbow
#

I'm guessing you don't have a postman to handle this either then?

dusty silo
#

Take the existing event data and change any params you want

#

No postman collection unfortunately

junior elbow
#

:/ bah! What's going on even PayPal have that...

#

I shall leave this discord now for being rude

#

please accept my utmost apologies

dusty silo
#

I didn't think you were being rude

#

No apologies necessary

#

Wait just to clarify what do you want from postman? If it's just a collection with all our api endpoints we might have that

junior elbow
#

but yes Postman service

dusty silo
#

Oh for your own webhook endpoint. No you'd need to make that yourself

#

Because that's built by you