I am making a Discord bot that has a where it generates a payment link and once you pay it sends a message saying Paid in the chat. I have seen it done before so I know it's possible and I have the basics done but I am getting stuck on something. I use the Paypal-express-checkout npm addon and when you run -pay (amount0) it generated a payment link for the amount given but when it returns to my return URL which is confirm.php it has the variables in the URL but I don't know how to send them to the node.js application or for the node.js applicaiton to fetch them so it can confirm that it was actually made. There are 2 functions with the addon that I use, one of them creates the link and one of them confirms it hence why I need the variables sent to the php file.
Thanks
paypal.pay(message.id, args[0], 'Invoice', 'USD', function(err, url) {
if(err) {
console.log(err);
return;
}
message.channel.send({embed: {
color: 0x28d651,
title: "Slashy Payment",
fields: [
{
name: "Invoice Amount",
value: "$" + args[0],
inline: true
},
{
name: "Invoice Client",
value: message.author.username,
inline: true
},
{
name: "Invoice Status",
value: "Pending..."
},
{
name: "Payment Link",
value: '[Pay here](' + url + ')'
}
],
timestamp: new Date(),
footer: {
icon_url: bot.user.avatarURL,
text: "© Slashy 2018"
}
}
});
});
Just for anyone wanting to know how I managed to do it in the end just store the message.channel.id in the URL for the paypal return link and when they get to the page save the info into a database with the channel id and just keep checking the database every 5 seconds in the channel if the item has been marked as paid in the database. Really cool fix that seems to work fine
Just another solution for you, instead of polling, just create an express webserver or open a tcp socket. Yes php does tcp sockets as well. Anyways, once paypal returns its message to your php server, have the php script send a request to your node.js express server that is also running your bot. I don't know how option people will be purchasing via your bot, but it seems like a good alternative than to waste some cpu time if loads of people start buying :D but hey, that's a good problem right?