Created
July 14, 2021 08:21
-
-
Save vaibhavgehani/fc1204406ef6835278dc998148645ecf to your computer and use it in GitHub Desktop.
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
| const express = require("express"); | |
| const app = express(); | |
| const bodyParser = require('body-parser'); | |
| const cors = require("cors") | |
| const braintree = require("braintree"); | |
| const gateway = new braintree.BraintreeGateway({ | |
| environment: braintree.Environment.Sandbox, | |
| merchantId: "USE_YOUR_MERCHENT_ID", | |
| publicKey: "USE_YOUR_PUBLIC_KEY", | |
| privateKey: "USE_YOUR_PRIVATE_KEY" | |
| }); | |
| app.use(cors()); | |
| var jsonParser = bodyParser.json() | |
| app.use(bodyParser.urlencoded({ | |
| extended:true | |
| })); | |
| // Braintree Paypal Payment | |
| app.get("/brainTreeClientToken", (req, res) => { | |
| gateway.clientToken.generate({}).then((response) => { | |
| console.log('Token', response); | |
| res.send(response); | |
| }); | |
| }); | |
| app.post("/checkoutWithPayment", jsonParser, (req, res) => { | |
| console.log(req.body) | |
| const nonceFromTheClient = req.body.nonceFromTheClient; | |
| const payment = req.body.paymentAmount; | |
| gateway.transaction.sale({ | |
| amount: payment, | |
| paymentMethodNonce: nonceFromTheClient, | |
| options: { | |
| submitForSettlement: true | |
| } | |
| }).then((result) => { | |
| console.log(result); | |
| res.send(result); | |
| }); | |
| }); | |
| app.listen(route, () => { | |
| console.log("Server Started at", process.env.PORT || 3000); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment