Skip to content

Instantly share code, notes, and snippets.

@matthewarkin
Created March 31, 2016 20:09
Show Gist options
  • Save matthewarkin/3ad512656f2b56f523a181c70e8c0e73 to your computer and use it in GitHub Desktop.
Save matthewarkin/3ad512656f2b56f523a181c70e8c0e73 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Checkout</title>
</head>
<body>
<article id="store">
<h1>This is the checkout page</h1>
<p>order ID: <%= orderId %></p>
</article>
<form id="checkout" method="post" action="/checkout">
<div id="payment-form"></div>
<input type="submit" value="Pay $10">
</form>
<script src="https://js.braintreegateway.com/js/braintree-2.21.0.min.js"></script>
<script>
// We generated a client token for you so you can test out this code
// immediately. In a production-ready integration, you will need to
// generate a client token on your server (see section below).
var clientToken = "<%= clientToken %>";
braintree.setup(clientToken, "dropin", {
container: "payment-form"
});
</script>
</body>
</html>
var express = require('express');
var router = express.Router();
var braintree = require("braintree");
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: "w2dm9nsqv2ngjg76",
publicKey: "rqvc7zvmpm6rw63c",
privateKey: "108531f07f5a30dbb64ad8d21f8f3cf8"
});
router.post("/checkout", function (req, res) {
var nonce = req.body.payment_method_nonce;
// Use payment method nonce here
});
router.get('/checkout', function(req, res) {
gateway.clientToken.generate({}, function (err, response) {
res.render('checkout', {clientToken: response.clientToken});
});
});
module.exports = router;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment