#jacko-checkout

1 messages · Page 1 of 1 (latest)

lyric mantle
worldly flare
#

ok awesome

#

just making sure it is possible to use variable prices in the checkout session

#

before i dive down a rabbit hole

#

sorry @lyric mantle another question

#
import "./App.css";

const ProductDisplay = () => (
  <section>
    <div className="product">
      <img
        src="https://i.imgur.com/EHyR2nP.png"
        alt="The cover of Stubborn Attachments"
      />
      <div className="description">
      <h3>Stubborn Attachments</h3>
      <h5>$20.00</h5>
      </div>
    </div>
    <form action="/create-checkout-session" method="POST">
      <button type="submit">
        Checkout
      </button>
    </form>
  </section>
);

const Message = ({ message }) => (
  <section>
    <p>{message}</p>
  </section>
);

export default function App() {
  const [message, setMessage] = useState("");

  useEffect(() => {
    // Check to see if this is a redirect back from Checkout
    const query = new URLSearchParams(window.location.search);

    if (query.get("success")) {
      setMessage("Order placed! You will receive an email confirmation.");
    }

    if (query.get("canceled")) {
      setMessage(
        "Order canceled -- continue to shop around and checkout when you're ready."
      );
    }
  }, []);

  return message ? (
    <Message message={message} />
  ) : (
    <ProductDisplay />
  );
}
#

if i use this for my client

#

where it calls the server on ```<form action="/create-checkout-session" method="POST">
<button type="submit">
Checkout
</button>
</form>

#

can I pass in a variable for price?

lyric mantle
#

sorry, i didn't quite understand that, what do you mean by variable for price?

worldly flare
#

@lyric mantle im using react for the client and I want to have the price be a variable that can change. So that the user can customize their price they will pay.

lyric mantle
#

are you referring to the amount?

#

you want to allow the customer to choose how much they pay?

worldly flare
#

yes exactly

#

the amount

lyric mantle
#

ah, alright, sorry about that, i misunderstood what you were looking for previously

worldly flare
#

sort of

#

I guess i would like to keep the price the same and just change the quantity