#robolist

1 messages ยท Page 1 of 1 (latest)

keen gazelleBOT
errant sapphire
#

Can you share your code when you initialise the ECE?

clear tapir
#

Sure, no problem

errant sapphire
#

Or the Elements group (stripe.elements()), sorry

clear tapir
#

`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}/>
    </>
)

}`

errant sapphire
#

Can you print your price variable?

clear tapir
#

Price is 9999

#

I am converting it from 99.99 to 9999

errant sapphire
#

The Google Pay UI would imply that it's 999900

clear tapir
#

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

errant sapphire
#

Yeah but you're converting a float (99.99) to an integer so I suspect it's not the value you expect

inland garnet
clear tapir
#
    value = (value + '').replace(/[^\d.-]/g, '');
    if (value && value.includes('.')) {
      value = value.substring(0, value.indexOf('.') + 3);
    }
  
    return value ? Math.round(parseFloat(value) * 100) : 0;
  }```
inland garnet
#

why not Math.round(price*100)

clear tapir
#
        const options = {
          emailRequired: true,
          phoneNumberRequired: true,
          lineItems: [
            {
                name: name,
                amount: 9999
            }
          ]
        };
        resolve(options);
    };```

When i hardcode it still comes out to ยฃ9999
inland garnet
clear tapir
errant sapphire
errant sapphire
#

I can't reproduce this

clear tapir
#

I feel so stupid now.... Sorry..
I had to reset the server, all my changes were not taking effect...
Its all working now..

errant sapphire
#

๐ŸŽ‰

clear tapir
#

Sorry about that. but many thanks for your help anyway ๐Ÿ™‚

errant sapphire
#

np! helps to rubber duck

clear tapir
#

๐Ÿ™‚

inland garnet