Skip to content

Instantly share code, notes, and snippets.

@iawaisrana
Created May 9, 2020 17:10
Show Gist options
  • Save iawaisrana/1baff2c452a82b160e7aed28c2acc4b2 to your computer and use it in GitHub Desktop.
Save iawaisrana/1baff2c452a82b160e7aed28c2acc4b2 to your computer and use it in GitHub Desktop.
const dotenv = require("dotenv");
const braintree = require("braintree");
const express = require("express");
dotenv.config();
const app = express();
var gateway = braintree.connect({
environment: braintree.Environment.Sandbox,
merchantId: process.env.MERCHANT_ID,
publicKey: process.env.PUBLIC_KEY,
privateKey: process.env.PRIVATE_KEY,
});
app.get("/getClientToken", async (req, res, next) => {
try {
gateway.clientToken.generate({}, function(err, response) {
if (err) {
res.status(400).send({
token: null,
});
}
res.status(200).send({
token: response.clientToken,
});
});
} catch (error) {
console.log(error);
res.status(400).send({
token: null,
});
}
});
const port = process.env.PORT || 3000;
app.listen(port, () =>
console.log(`Example app listening at http://localhost:${port}`)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment