#Ludvig-payment-intent-metadata
1 messages ยท Page 1 of 1 (latest)
Hi ๐ yup, metadata sounds like exactly what you're looking for. Do you have the request ID from where you set the metadata that I could take a look at?
Well, the metadata is there when I check my dashboard, but not on the client when I retrieve the data like so:
stripe.retrievePaymentIntent(clientSecret).then(({ paymentIntent }) => {
console.log(paymentIntent);
});
I see it should be under charges.data.metadata
but as you see above there is no "charges" in the paymentIntent object retrieved on the client
There is tons of stuff that isn't on the client paymentIntent but that is there on the dashboard, I'm guessing for security reasons. But it feels like metadata should be there?
I'll send you the ID if you really need it, but I feel like there's no need
It's going to depend on how you're setting the metadata. Most of our objects have the metadata field, but the values don't move from one object to another. So if you're putting the metadata on the Payment Intent, you'll need to look at the Payment Intent, but if you're putting it on the Charge then you'll need to look there.
I'll have a quick look at this
Creating a paymentIntent on the server. Then sending the paymentIntent back to the client.
const params = {
automatic_payment_methods: {
enabled: true,
},
payment_method_options: {
klarna: {
preferred_locale: formatLocaleForKlarna(locale),
},
},
metadata: {
someMetaData: "someMetaData",
},
amount: formatAmountForStripe(amount, "eur"),
currency: "eur",
};
const payment_intent = await stripe.paymentIntents.create(params);
res.status(200).json(payment_intent);
On confirming the payment, return_url is set to the success page on which I do this:
Retrieving the paymentIntent on success page:
const clientSecret = new URLSearchParams(window.location.search).get(
"payment_intent_client_secret"
);
stripe.retrievePaymentIntent(clientSecret).then(({ paymentIntent }) => {
console.log(paymentIntent);
});
Alright, so looks like you are setting the metadata directly on the payment intent.
Well, what does this mean to me? Am I not retrieving the paymentIntent in the latter codesnippet?
How would you suggest that I do this? I feel like putting the metadata in the paymentIntent seems good, as I could update the metadata when I update the paymentIntent
When you retrieve it, that's on your frontend with a publishable key?
Yes I believe so
Ah, so when using a publishable key to retrieve a Payment Intent, not all fields are returned for security reasons and it looks like metadata is one of those.
Yeah I was thinking that could be the case. But how am I supposed to do my success/receipt page then?
You could have your frontend send a request to your backend, have your backend retrieve the payment intent, and then respond to your frontend with the necessary metadata.
Happy to help!
Hey, what about this
In the docs for "accept a payment, custom payment flow" it says Use one of the query parameters to retrieve the PaymentIntent. Inspect the status of the PaymentIntent to decide what to show your customers. You can also append your own query parameters when providing the return_url, which persist through the redirect process.
Should I put data inside the query parameters instead?
To avoid one trip to the backend, only to show metadata the customer already knows about?
Oh, that's really clever. Yeah that seems like a better approach.