Created
September 27, 2019 18:09
-
-
Save dapperAuteur/1ca57d29068bb95045b70e518aa0c642 to your computer and use it in GitHub Desktop.
This file contains 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
import React from "react" | |
const cardStyles = { | |
display: "flex", | |
flexDirection: "column", | |
justifyContent: "space-around", | |
alignItems: "flex-start", | |
padding: "1rem", | |
marginBottom: "1rem", | |
boxShadow: "5px 5px 25px 0 rgba(46,61,73,.2)", | |
backgroundColor: "#fff", | |
borderRadius: "6px", | |
maxWidth: "300px", | |
} | |
const buttonStyles = { | |
fontSize: "13px", | |
textAlign: "center", | |
color: "#fff", | |
outline: "none", | |
padding: "12px", | |
boxShadow: "2px 5px 10px rgba(0,0,0,.1)", | |
backgroundColor: "rgb(255, 178, 56)", | |
bordderRadius: "6px", | |
letterSpacing: "1.5px", | |
} | |
const formatPrice = (amount, currency) => { | |
let price = (amount / 100).toFixed(2) | |
let numberFormat = new Intl.NumberFormat(["en-US"], { | |
style: "currency", | |
currency: "USD", | |
currencyDisplay: "symbol", | |
}) | |
return numberFormat.format(price) | |
} | |
const SkuCard = class extends React.Component { | |
async redirectToCheckout(event, sku, quantity = 1) { | |
event.preventDefault() | |
const { error } = await this.props.stripe.redirectToCheckout({ | |
items: [{ sku, quantity }], | |
successUrl: `http://localhost:8000/page-2/`, | |
cancelUrl: `http://localhost:8000/advanced/`, | |
}) | |
if (error) { | |
console.warn("Error:", error) | |
} | |
} | |
render() { | |
const sku = this.props.sku | |
return ( | |
<div style={cardStyles}> | |
<h4>{sku.attributes.name}</h4> | |
<p>Price: {formatPrice(sku.price, sku.currency)}</p> | |
<button | |
style={buttonStyles} | |
onClick={event => this.redirectToCheckout(event, sku.id)} | |
> | |
BUY ME | |
</button> | |
</div> | |
) | |
} | |
} | |
export default SkuCard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment