#CryptoFidget-pi-persist
1 messages ยท Page 1 of 1 (latest)
Hey, I guess that's entirely dependent on what data you need
What is it you're building
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
so I can track the payments if some errors happens?
What kind of errors?
Are you subscribing to webhooks?
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..
You should rely on webhooks to notify you of successful/failed payments instead of if/when they're redirected back to your site: https://stripe.com/docs/payments/checkout/fulfill-orders
not sure what you mean? it's the guide to getting started and building the integration.
ah your link with the webhook is on top of the checkout which I already did right?
yes, webhooks are related but separate and are what you do after the payment
ok now it makes sense for me.
Thank you. I'll implement that now. bb
I hope it's ok that I write you, since you have a track of my trying
[ Node] Webhook Error: No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe? https://github.com/stripe/stripe-node#webhook-signing
is that correct that I take the endpointSecret from the Stripe CLI for my localhost testings?
whsec_...
if you're using stripe listen --forward-to to forward the webhooks to your local server, then yep that's correct, you configure your code to use the whsec_xxx it prints in the console
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
even if I used:
bodyParser.raw({ type: "application/json" }) ?
I believe that is generally the recommended fix yes
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"?
are you actually using Checkout?
screenshot of the page you entered that 4242 into would be a quick way to show me
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.
so that is not Checkout, no
oh god
that is the PaymentElement (i.e. in the quickstart you picked the "Custom payment form" option I suppose)
yes
which is fine, that's a supported integration! it's just not Checkout so the https://stripe.com/docs/payments/checkout/fulfill-orders guide is not relevant
so I can not combine those? I mean it is somehow working
sure, you can use either one, it's totally fine
https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-post-payment is how you handle webhooks for the PaymentElement
like you say, it's payment_intent.* events
so but how do I get the "complete" or "paid" or "charged" event ?
I see in my test dashboard it is charged
have a read of that accept-a-payment guide steps 5 and 6
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?
I don't see that code in the link I posted (https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements#web-post-payment , to be clear)
but here in this webhook
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.
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
right.
so I don't need to listen to
"checkout.session.completed"
but to
paymentIntent.status.succeeded
you are totally right.
paymentIntent.status.succeeded is only in frontend (stripe.retrievePaymentIntent(clientSecret)) ... ok ok
you helped me already a lot.. โค๏ธ
actually it's "charge.succeeded"
no, it's payment_intent.succeeded
it does generate a charge.succeeded event as well but it's better to use the PaymentIntent events
and yes, you can retrieve the PI on the success page in the frontend too to get that and show a message to the customer(step 5 in the guide)
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
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
OK THIS. how do I do this?
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!
So is the issue solved?
issue is solved. Thanks!