Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="container">
</div>
              
            
!

CSS

              
                .productInfoRow {
    margin-bottom: 10px
}

.productHeaderRow {
    text-transform: uppercase;
    font-weight: bold;
    background-color: #764abc;
    color: white;
    padding: 5px;
    margin-top: 5px;
    margin-bottom: 10px;
    border-radius: 5px;
}

.productInfoColumn {
    display: flex;
    align-items: center;
}

.productInfoColumnCenter {
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn {
    color: white;
    background-color: rgba(118, 74, 188, 0.8) !important;
}

.btn:hover {
    color: white;
    background-color: rgba(118, 74, 188, 1) !important;
}

.braintreePayButton {
    margin-left: auto;
    display: flex;
}

#braintree-drop-in-div {
    min-height: 150px;
    margin-top: 5px;
    margin-bottom: 10px;
}
              
            
!

JS

              
                //import "https://cdn.skypack.dev/bootstrap/dist/css/bootstrap.min.css";
//import * as reactTransitionGroup from "https://cdn.skypack.dev/react-transition-group@v2.9.0";
import React, { useState, useEffect } from "https://cdn.skypack.dev/react@17.0.1";
import * as ReactDOM from "https://cdn.skypack.dev/react-dom@17.0.1";
import * as dropin from "https://cdn.skypack.dev/braintree-web-drop-in@1.31.2";
const {Col, Container, Input, Row, Button} = Reactstrap;

function BraintreeDropIn(props) {
    const { show, onPaymentCompleted } = props;

    const [braintreeInstance, setBraintreeInstance] = useState(undefined)

    useEffect(() => {
        if (show) {
            const initializeBraintree = () => dropin.create({
                authorization: "sandbox_s9gd7m2p_vp62s592633kc5p5", // insert your tokenization key or client token here
                container: '#braintree-drop-in-div',
            }, function (error, instance) {
                if (error)
                    console.error(error)
                else
                    setBraintreeInstance(instance);
            });

            if (braintreeInstance) {
                braintreeInstance
                    .teardown()
                    .then(() => {
                        initializeBraintree();
                    });
            } else {
                initializeBraintree();
            }
        }
    }, [show])

    return (
        <div
            style={{display: `${show ? "block" : "none"}`}}
        >
            <div
                id={"braintree-drop-in-div"}
            />

            <Button
                className={"braintreePayButton"}
                type="primary"
                disabled={!braintreeInstance}
                onClick={() => {
                    if (braintreeInstance) {
                        braintreeInstance.requestPaymentMethod(
                            (error, payload) => {
                                if (error) {
                                    console.error(error);
                                } else {
                                    const paymentMethodNonce = payload.nonce;
                                    console.log("payment method nonce", payload.nonce);

                                    // TODO: use the paymentMethodNonce to
                                    //  call you server and complete the payment here

                                    // ...

                                    alert(`Payment completed with nonce=${paymentMethodNonce}`);

                                    onPaymentCompleted();
                                }
                            });
                    }
                }}
            >
                {
                    "Pay"
                }
            </Button>
        </div>
    )
}

function App() {
    const [showBraintreeDropIn, setShowBraintreeDropIn] = useState(false);
    const [numberOfProducts, setNumberOfProducts] = useState(1);

    const PRICE = 50;

    return (
        <Container>
            <Col>
                <Row
                    className={"productHeaderRow"}
                >
                    <Col
                        xs={4}
                    >
                        {
                            "Product"
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"text-center"}
                    >
                        {
                            "Price"
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"text-center"}
                    >
                        {
                            "Quantity"
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"text-center"}
                    >
                        {
                            "Total"
                        }
                    </Col>
                    <Col
                        xs={2}
                    />
                </Row>
                <Row
                    className={"productInfoRow"}
                >
                    <Col
                        xs={4}
                        className={"productInfoColumn"}
                    >
                        {
                            "Foo product"
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"productInfoColumnCenter"}
                    >
                        {
                            `$ ${PRICE}`
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"productInfoColumnCenter"}
                    >
                        <Input
                            placeholder="0"
                            min={1}
                            max={100}
                            type="number"
                            step="1"
                            value={numberOfProducts}
                            onChange={((e) => {
                                setNumberOfProducts(e.target.value)
                            })}
                        />
                    </Col>
                    <Col
                        xs={2}
                        className={"productInfoColumnCenter"}
                    >
                        {
                            `$ ${numberOfProducts * PRICE}`
                        }
                    </Col>
                    <Col
                        xs={2}
                        className={"productInfoColumnCenter"}
                    >
                        <Button
                            onClick={() => {setShowBraintreeDropIn(true)}}
                            disabled={showBraintreeDropIn}
                        >
                            {
                                "Go to Checkout"
                            }
                        </Button>
                    </Col>
                </Row>
            </Col>
            <BraintreeDropIn
                show={showBraintreeDropIn}
                onPaymentCompleted={() => {
                    setShowBraintreeDropIn(false);
                    setNumberOfProducts(1);
                }}
            />
        </Container>
    );
}

ReactDOM.render(<App />, document.getElementById("container"));

              
            
!
999px

Console