Coin Tunnel
Search…
Putting it all together
Excited?
Here you can see that everything happens in 51 lines of code! To get started, just change the variables callback apikey verifac port hostname to the correct values! You also need to get the buyer's id, which you put in the buyerId variable.
app.js
const fetch = require('node-fetch');
const express = require('express');
const app = express();
var bodyParser = require('body-parser');
const callback = "https://example.com/callback";
const apikey = "your api key here";
const verifac = "Set your verifac in dashboard";
let port = 3000;
const hostname = "localhost"
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.set('port', port);
app.post("/create-transaction", async (req, res) => {
let data = {
buyerId:"Get this value from buyer",
callback: callback,
usd: 20,
expiry: 180000,
note: {
"item":"computer",
"id":"123456"
}
}
let headers = {
'Content-Type': 'application/json',
'Authorization': apikey
}
fetch('https://coin-Tunnel.joshuazou.repl.co/api/v1/create', {
method: 'POST',
body: JSON.stringify(data),
headers: headers
}).then(res => res.json())
.then(json => {
console.log(json);
if (json.status === "failed"){
// handle this
}
res.send("Success! Check your emails")
});
})
app.post("/callback", async (req, res) => {
if (req.headers.verifac !== verifac) return res.status(401);
// now you are certain that the server is who it says it is (Coin Tunnel)
console.log(req.body);
if (req.body.status !== "ok") console.log(req.body) // If something went wrong
let note = req.body.note;
// You can then give the user something based on the note that you set earlier!
return res.send("Wow thanks!")
})
app.listen(port, hostname, () => console.info(`Listening at ${hostname}:${port}`));
Copy link