#CryptoFidget-pi-persist

1 messages ยท Page 1 of 1 (latest)

pulsar urchin
#

Hey, I guess that's entirely dependent on what data you need

#

What is it you're building

winged turtle
#

but what is the least I need to have, so I can track the payments if some errors happens?

I have always the same product and same price.. so I would say paymentIntentID and clientSecret?

#

maybe I just save the whole intent object.. it's better

pulsar urchin
#

so I can track the payments if some errors happens?
What kind of errors?

#

Are you subscribing to webhooks?

winged turtle
#

no I did this checkout.html checkout.js on the quickstart (https://stripe.com/docs/payments/quickstart)...

error: After the user clicks Pay => he get's somehow redirected to stripe right? and immediately redirected to my page.. there the status of the payment could be:

processing, requires_payment_method, or something else

means in those cases the payment did not work.. so I need to write it into the database, in case the user just closes the page..

pulsar urchin
winged turtle
#

thank you

#

and the quickstart? what is it good for?

proper stirrup
#

not sure what you mean? it's the guide to getting started and building the integration.

winged turtle
#

ah your link with the webhook is on top of the checkout which I already did right?

proper stirrup
#

yes, webhooks are related but separate and are what you do after the payment

winged turtle
#

ok now it makes sense for me.
Thank you. I'll implement that now. bb

winged turtle
#

I hope it's ok that I write you, since you have a track of my trying

#

is that correct that I take the endpointSecret from the Stripe CLI for my localhost testings?

#

whsec_...

proper stirrup
#

do read the page linked in the error message you posted, as getting this to work on Node can be tricky because a lot of frameworks mutate the webhook body in ways that prevent the signature being verified

winged turtle
#

even if I used:
bodyParser.raw({ type: "application/json" }) ?

proper stirrup
#

I believe that is generally the recommended fix yes

winged turtle
#

Karl thank you so much! ๐Ÿ™‚

#

this is the hack:

#

app.use((req, res, next) => {
if (req.originalUrl === "/webhook") {
next();
} else {
express.json({ limit: "50mb" })(req, res, next);
}
});

#

don't use json if its for stripe.. otherwise use it

#

how do I reach the "checkout.session.completed" phase? I have only "payment_intent.succeeded"

user fills out the cc (4242..) form and clicks pay, and that's it "succeeded".. how to make this now "completed"?

proper stirrup
#

are you actually using Checkout?

#

screenshot of the page you entered that 4242 into would be a quick way to show me

winged turtle
#

I don't know.. I tried this 2 years ago, and it was completely different.. my old code didn't work with this form..

#

please don't say that I am using the wrong form haha I am soo lost.

proper stirrup
#

so that is not Checkout, no

winged turtle
#

oh god

proper stirrup
#

that is the PaymentElement (i.e. in the quickstart you picked the "Custom payment form" option I suppose)

winged turtle
#

yes

proper stirrup
winged turtle
#

so I can not combine those? I mean it is somehow working

proper stirrup
#

sure, you can use either one, it's totally fine

#

like you say, it's payment_intent.* events

winged turtle
#

so but how do I get the "complete" or "paid" or "charged" event ?

#

I see in my test dashboard it is charged

proper stirrup
winged turtle
#

aaah I see... but can you tell me why in the example code there is also this event status:

if (event.type === "checkout.session.completed") {
    const session = event.data.object;
    // Fulfill the purchase...
    fulfillOrder(session);
}
#

"checkout.session.completed" this never happens in my case => because?

proper stirrup
winged turtle
#

OR you saying: I don't need webhooks when I am using elelments (the last link you sent with "to be clear")

#

everything is now mixed.

proper stirrup
#

you do need webhooks

#

but you don't need Checkout webhooks since you're not using Checkout

#

my colleague thought you were using Checkout, turns out you're not, so you actually want the payment_intent.* events from my link

winged turtle
#

right.
so I don't need to listen to
"checkout.session.completed"
but to
paymentIntent.status.succeeded

proper stirrup
#

right

#

well payment_intent.succeeded, but right

winged turtle
#

you are totally right.

#

paymentIntent.status.succeeded is only in frontend (stripe.retrievePaymentIntent(clientSecret)) ... ok ok

you helped me already a lot.. โค๏ธ

winged turtle
proper stirrup
#

no, it's payment_intent.succeeded

#

it does generate a charge.succeeded event as well but it's better to use the PaymentIntent events

proper stirrup
winged turtle
#

I somehow don't understand the concept..

now I implemented everything and it works.

but how can I know that the succeeded payment belongs to which user?

at which point to I save the payment intend_id (??) and match it with the payment_intent or order id?

#

in the end order object I don't have any relations to the user or the product he ordered

robust stag
#

Hi there! I'm taking over this thread.

#

but how can I know that the succeeded payment belongs to which user?
You could add some metadata to the PaymentIntent to know which user made the payment

winged turtle
#

because when I somehow can get those metadata in my webhook (in the backend) I can access them and write those into my own database + that the payment was a success.

#

that solves everything.

#

const paymentIntent = await stripe.paymentIntents.create({
amount: calculateOrderAmount(items),
currency: "usd",
automatic_payment_methods: {
enabled: true
}
});

#

maybe here?

#

found it ๐Ÿ™‚

#

thank you!

robust stag
#

So is the issue solved?

winged turtle
#

issue is solved. Thanks!