Last active
May 17, 2020 02:43
-
-
Save ryanbelke/8eaa7c68bdb9b545a67efeacc7802570 to your computer and use it in GitHub Desktop.
checkout.js from step 6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* pages/checkout.js */ | |
import React, { useContext } from "react"; | |
import { Row, Col } from "reactstrap"; | |
import { loadStripe } from "@stripe/stripe-js"; | |
import { Elements } from "@stripe/react-stripe-js"; | |
import InjectedCheckoutForm from "../components/checkout/CheckoutForm"; | |
import AppContext from "../context/AppContext"; | |
import Cart from "../components/cart/"; | |
function Checkout() { | |
// get app context | |
const appContext = useContext(AppContext); | |
// isAuthenticated is passed to the cart component to display order button | |
const { isAuthenticated } = appContext; | |
// load stripe to inject into elements components | |
const stripePromise = loadStripe("YOUR STRIPE PUBLIC (pk_) KEY"); | |
return ( | |
<Row> | |
<Col style={{ paddingRight: 0 }} sm={{ size: 3, order: 1, offset: 2 }}> | |
<h1 style={{ margin: 20 }}>Checkout</h1> | |
<Cart isAuthenticated={isAuthenticated} /> | |
</Col> | |
<Col style={{ paddingLeft: 5 }} sm={{ size: 6, order: 2 }}> | |
<Elements stripe={stripePromise}> | |
<InjectedCheckoutForm /> | |
</Elements> | |
</Col> | |
</Row> | |
); | |
// } | |
} | |
export default Checkout; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment