#pulley871_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/1234954698541240442
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
const [is_loading, setIsLoading] = useState(false)
const stripePromise = loadStripe(stripe_api_key)
function convertCurrencyStringToNumber(currency_string): number {
const float_number = parseFloat(currency_string.replace('$', ''))
const integer_number = Math.round(float_number * 100)
return integer_number
}
useEffect(() => {
paymentProcessingCallback(is_loading)
}, [is_loading])
const stripeOptions: StripeElementsOptions = {
mode: 'subscription',
amount: convertCurrencyStringToNumber(grand_total),
currency: 'usd',
paymentMethodCreation: 'manual', // allows usage of stripe.createPaymentMethod
setupFutureUsage: 'off_session', // indicates intention to make future payments
appearance: {
theme: 'stripe',
variables: {
spacingUnit: '4px',
borderRadius: '14px',
},
},
}
return (
<div>
<Elements stripe={stripePromise} options={stripeOptions}>
<CheckoutForm
setPaymentLoading={setIsLoading}
is_tax_exempt={is_tax_exempt}
checkout_url={checkout_url}
cart_id={cart_id}
paymentMethod={paymentMethod}
shouldProcessOrder={shouldProcessOrder}
goBackUrl={goBackUrl}
/>
</Elements>
</div>
)
Here is the code, looks like it was not all captured in the form
Hmm thinking
no worries!
Hmm still thinking, one option could be to keep cart and elements in separate components?
that way cart state changes only affect cart component and its child
well i can force the page to reload only updating the correct items (cart). But the issue is that the price changes, so the value that is passed into the original mounted Element needs to be updated and passed through to stripe. Or am i wrong on that?
Ah the SDK has a built in function for that
https://docs.stripe.com/js/elements_object/fetch_updates
got ya i will give that a gander! THanks