#fusync-webhook-signature

1 messages · Page 1 of 1 (latest)

dense runeBOT
abstract holly
#

Hello! Yep, I believe that's correct, it's not shown in the Dashboard by default for most accounts.

#

You can still add it via the API though.

karmic cedar
#

Hi Rubeus, how would I do that?

abstract holly
karmic cedar
#

Will the lookupkey ever return to the dashboard?

abstract holly
#

I don't believe there are any plans for it, no. What's your use case for the lookup key in the Dashboard?

karmic cedar
#

To retrive the prodcut data when the user clicks on the plan they want. It will then direct them to checkout on stripe hosted checkout page. The lookup key is used to find product details. Saw it in the quickstart guide

abstract holly
#

Why do you want to be able to set it using the Dashboard though?

#

The operations you're decribing would be done via the API, correct?

karmic cedar
#

I prefer to set it up using the dashboard

abstract holly
karmic cedar
#

cool

#

I had another problem for
router.post(
'/webhook',
does it run after
router.post('/create-portal-session',
from the stripe server

abstract holly
#

Those are routes you would define on your server, and when they get called is up to how your frontend code works and how you configure webhooks.

#

Can you ask something more specific, or provide more details?

karmic cedar
#

And it has the three posts
create portal session which uses the product data and generates link to stripe checkout but after the payment it redirects to
domain.com/success.html?session_id={CHECKOUT_SESSION_ID}
but how does session id gert obtained? I am assuming from the webhook post but I am confused on how it will work?

abstract holly
#

{CHECKOUT_SESSION_ID} is a placeholder and will be replaced by the Checkout Session's ID when Checkout redirects.

karmic cedar
#

what about the webhook would I need that too?

abstract holly
#

That endpoint receives Events sent to your server directly from Stripe. You configure a Webhook Endpoint to point to that URL so we can let your server know when certain things happen.

karmic cedar
#

is that seperate to the payment e.g. I will only use webhook to manage the details but the acutal payament flow for the customer would be done with those to rest requests a post to checkout and app.get('/order/success',

abstract holly
#

Ideally you use both. By default most transactions will be handled by your client-side flow working as intended, with the webhooks as a backup in case something client-side goes wrong.

#

For example, if someone is paying you and just as they complete the payment their battery dies you want to know you got paid, so you can fulfill the order, even if the client-side code doesn't run.

#

There are a lot of cases where that happens. Losing your Internet when going into a tunnel, a strange browser extension breaking something, etc.

#

So webhooks are an important backup to your client-side flow.

karmic cedar
#

I see does that mean after the payment is done the post webhook runs separately

abstract holly
#

Yeah, your webhook URL is hit directly by Stripe. It's outside the client-side flow.

karmic cedar
#

I should inlcude this in a seprate file in my router folder in express.js then

abstract holly
#

That's up to you, it will work either way.

karmic cedar
#

How does stripe secure this webhook and how is it verfied I see a endpointsecret but theres no conditional checking statement like endpointsecret === secretkey

abstract holly
karmic cedar
#

in the code is this the condtional checking statement

event = stripe.webhooks.constructEvent(
request.body,
signature,
endpointSecret

abstract holly
#

Yep, constructEvent will validate the signature and return an error if it doesn't work out as expected.

dense runeBOT
rich osprey
#

fusync-webhook-signature

karmic cedar
#

Ok for wheen the webhook is sent back tot he server does the event contain the user id from stripe

rich osprey
#

what do you call "the user id" as it could mean many different things

karmic cedar
#

the customer details id

rich osprey
#

It depend on which Event you are listening for.

karmic cedar
#

e.g. for here

outer.get('/success', async (req, res) => {
const sessionID = req.query.session_id;
console.log('sessionID',sessionID)
const customer = await stripe.customers.retrieve(sessionID.customer);
console.log('customer',customer)

I get value for sessionId but the cutomer detail fails

rich osprey
#

Sure, step 1: log the information and debug
Like what does the customer id look like? Did you create one first? If not why do you expect one here?

karmic cedar
#

error for customer variable

C:\Users\Owner\Documents\web\node_modules\stripe\cjs\StripeResource.js:99
throw new Error(Stripe: Argument "${param}" must be a string, but got: ${arg} (on API request to \${requestMethod} ${path}`)`);
^

Error: Stripe: Argument "customer" must be a string, but got: undefined (on API request to GET /v1/customers/{customer})
at C:\Users\Owner\Documents\web\node_modules\stripe\cjs\StripeResource.js:99:23

rich osprey
#

I mean that's just dumping a crash with no info

#

You control the code here. Log the value before calling that API, make sure the value is correct and not null

karmic cedar
#

value for sessionID?

rich osprey
#

You are the developer triggering an Event. You receive that Event. You can then log the content to understand what's in it. You seem to expect customer to be set. But it's not by default, not unless you explicitly create a Customer first and attach it to the Session yourself on creation which I assume you didn't

karmic cedar
#

I think I am using the wrong function when I have the session Id after the user has payed (from session url => session_id={CHECKOUT_SESSION_ID}), can I use it to access the user data and if so which function would it be? e.g. something like await stripe.customers.retrieve(sessionID)

rich osprey
#

sorry we're completely talking past each other a bit right now

#

Checkout does not create a Customer for you by default for one-time payments. I'm assuming you use Checkout (per what you said) and are doing one-time payments and not creating a Customer yourself, so there would be no Customer id in customer.

karmic cedar
#

I set up a subscription payment
mode: 'subscription'

rich osprey
#

😅

#

okay so can you give me an example Checkout Session id?

karmic cedar
#

cs_test_a1fXvx1qjtaKcRu2xlALuIa1JspeQw4MB423EsNNWQEIt4ooarcDZ6jZbu

rich osprey
karmic cedar
#

Nice
What function can I use to retrieve it with nodejs

rich osprey
#

I mean right now I really don't get what you're asking just yet unfortunately and you seem quite lost

#

I just showed you what the Event looks like with its raw JSON which is what you were asking about earlier

#

but maybe you're not talking about an Event at all are just lost?

#
    const sessionID = req.query.session_id;
    console.log('sessionID',sessionID)
    const customer = await stripe.customers.retrieve(sessionID.customer);
    console.log('customer',customer)```
what is thios? Where does `res.query.session_id` come from?
#

Is this part of the Redirect URL?

karmic cedar
#

yeah but somehting like
const customer = await stripe.customers.retrieve(sessionID);
where all the detials can be gotten from event e.g. if I want customer data

rich osprey
#

yeah okay so we're back to what I said earlier, you need to log stuff

#

Like right now, the URL has session_id=cs_test_123 It's purely a string. How would it have a sub-property called customer, that wouldn't make sense

#

and that will have customer: 'cus_123' and any other information

karmic cedar
#

yeah thats why I was enquiring about

#

is there a api call I can make to stripe

#

e.g. await stirpe.something. retrieve(sessionId)

#

where the session string is the identifier

rich osprey
#

Gotcha, sorry that's definitely not what I understood from your ask! But all our objects have a Retrieve API equivalent

karmic cedar
#

nice may I know where to find it or what it is for this case?