#pulley871_code

1 messages ¡ Page 1 of 1 (latest)

frozen oysterBOT
#

👋 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.

granite magnet
#

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

fossil patrol
#

Hmm thinking

granite magnet
#

no worries!

fossil patrol
#

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

granite magnet
#

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?

fossil patrol
granite magnet
#

got ya i will give that a gander! THanks