#brain_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1308866453952270477
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- brain_api, 2 hours ago, 8 messages
So, in a nutshell, this would be related to "dynamic pricing" or similar. Unsure how to categorize it.
I migrated out of PaymentRequestButtonElement earlier today (which had shorter loading times), but it takes too long with the ExpressCheckoutElement and doesn't look good.
Are there any best practices recommendations for me?
Hello! It sounds like you're recreating the Express Checkout Element each time, which you shouldn't do. Instead, after you change the associated Intent, you can tell Elements to fetch updates: https://docs.stripe.com/js/elements_object/fetch_updates
Beautiful
This stripe discord is the best support any company ever had. Thank you so much Rubeus.
I will let you know in a few minutes how that goes
I'm attempting to change it this way:
useEffect(() => {
if (paymentIntentId && message && amount) {
updatePaymentIntentMetadata(paymentIntentId, message, amount);
}
}, [paymentIntentId, message, amount]);
useEffect(() => {
if (elements && !changedDetails) {
elements.fetchUpdates().then((result) => {
if (result.error) {
console.error("Error fetching updates:", result.error);
} else {
// Updates fetched successfully
console.log("Payment Element updated");
}
});
}
}, [elements, amount, changedDetails]);
& getting Payment Element updated logged to console
Having no success. On the Backend, we are correclty changing the payment intent:
// get previous metadata
const paymentIntent = await stripe.paymentIntents.retrieve(paymentIntentId);
const previousMetadata = paymentIntent.metadata;
const updates: {
metadata: Record<string, string>;
amount?: number;
} = {
metadata: {
...previousMetadata,
};
if (amount) {
// Convert amount to cents
const amountCents = Math.round(amount * 100);
updates.amount = amountCents;
}
const updatedPaymentIntent = await stripe.paymentIntents.update(
paymentIntentId,
updates,
);
console.log(updatedPaymentIntent);
return res.json({ message: "Payment intent updated" });
-- having the correct details in the updated payment intent.
๐ stepping in here
Okay so this is for Express Checkout Element where you set the amount on the frontend via your options object that you pass to Elements.
So if you are doing dynamic pricing then you need to update that frontend Elements object via elements.update(): https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
fetchUpdates doesn't really apply here since the PaymentIntent doesn't come into play until the actual payment is being made.