#robolist
1 messages ยท Page 1 of 1 (latest)
Can you share your code when you initialise the ECE?
Sure, no problem
Or the Elements group (stripe.elements()), sorry
`const stripePromise = loadStripe(process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY);
export default function StripeWrapper({children, price}){
const paymentOptions = {
mode: 'payment',
amount: price,
currency: 'usd',
// Customizable with appearance API.
appearance: {/*...*/},
};
return (
<Elements stripe={stripePromise} options={paymentOptions}>
{children}
</Elements>
)
}`
`import { ExpressCheckoutElement } from "@stripe/react-stripe-js"
export default function StripeExpress({name, price}){
const checkoutOnClick = ({resolve}) => {
const options = {
emailRequired: true,
phoneNumberRequired: true,
lineItems: [
{
name: name,
amount: price
}
]
};
resolve(options);
};
return (
<>
<ExpressCheckoutElement onClick={checkoutOnClick}/>
</>
)
}`
Can you print your price variable?
The Google Pay UI would imply that it's 999900
The actual price of the product is 99.99 which is coming from the DB. But when I pass that into Stripe it says i need to pass the subunit, so I am multiplying it by 100 to get the amount in pence/cents
Yeah but you're converting a float (99.99) to an integer so I suspect it's not the value you expect
try to check the request on stripe developer dashboard. https://dashboard.stripe.com/test/logs?showIP=false
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
value = (value + '').replace(/[^\d.-]/g, '');
if (value && value.includes('.')) {
value = value.substring(0, value.indexOf('.') + 3);
}
return value ? Math.round(parseFloat(value) * 100) : 0;
}```
why not Math.round(price*100)
const options = {
emailRequired: true,
phoneNumberRequired: true,
lineItems: [
{
name: name,
amount: 9999
}
]
};
resolve(options);
};```
When i hardcode it still comes out to ยฃ9999
i mean this seems too robust.
Because the output value is not correct.
Yeah was about to suggest hardcoding, let me check
Did you hardcode it in the stripe.elements() instance?
I can't reproduce this
I feel so stupid now.... Sorry..
I had to reset the server, all my changes were not taking effect...
Its all working now..
๐
Sorry about that. but many thanks for your help anyway ๐
np! helps to rubber duck
๐
glad you resolved it, sorry for stupid suggestions, your logic is fine ther, it just took me time to understand. hate regexes.