Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
3,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. module.exports = {
  2. "name": "invoice",
  3. "args": true,
  4. "usage": "<amount in number> <email id> <@user>",
  5. async execute(client, message, args) {
  6. const Discord = require("discord.js");
  7. if (!message.member.roles.has("621913732657709066")) return message.channel.send("No permission.");
  8. const paypal = require("paypal-rest-sdk");
  9. const { paypal_client_id, paypal_client_secret } = require("../config.json");
  10. const { invoices } = require("../index.js")
  11. if (!message.mentions.members.first()) return message.channel.send("Specify the user the invoice is created for.")
  12. let dambed = new Discord.MessageEmbed()
  13. .setTitle("Product Name")
  14. .setDescription("Reply to this channel with the product name!");
  15. let moo = await message.channel.send(dambed);
  16. let theamount = 4.4 / 100 + 0.3 * parseInt(args[0]) + parseInt(args[0]);
  17. let therealamount = theamount.toFixed(2);
  18. let thestring = therealamount.toString()
  19. const filter = m => m.author.id === message.author.id;
  20. const collector = message.channel.createMessageCollector(filter, {max:1});
  21. collector.on("collect", async m => {
  22. moo.delete();
  23. m.delete();
  24. paypal.configure({
  25. "mode": "live",
  26. "client_id": paypal_client_id,
  27. "client_secret": paypal_client_secret
  28. });
  29. var create_invoice_json = {
  30. "merchant_info": {
  31. "email": "administration@endurablemc.com",
  32. "first_name": "Administration",
  33. "last_name": "",
  34. "business_name": "Endurable Services",
  35. },
  36. "billing_info": [{
  37. "email": args[1]
  38. }],
  39. "items": [{
  40. "name": m.content,
  41. "quantity": 1.0,
  42. "unit_price": {
  43. "currency": "USD",
  44. "value": thestring
  45. }
  46. }],
  47. "tax_inclusive": false,
  48. "total_amount": {
  49. "currency": "USD",
  50. "value": thestring
  51. }
  52. };
  53. message.delete();
  54. paypal.invoice.create(create_invoice_json, async function (error, invoice) {
  55. if (error) {
  56. throw error;
  57. } else {
  58. console.log("Create Invoice Response");
  59. console.log(invoice);
  60. paypal.invoice.send(invoice.id, async function (error, rv) {
  61. if (error) {
  62. console.log(error);
  63. console.log(error.response);
  64. throw error;
  65. } else {
  66. console.log("Send Invoice Response");
  67. console.log(rv);
  68. if (invoices.get(message.mentions.members.first().id)) { invoices.delete(message.author.id); }
  69. invoices.ensure(message.mentions.members.first().id, invoice.id)
  70. const embed = new Discord.MessageEmbed()
  71. .setTitle("Invoice Created")
  72.  
  73. .setDescription(`Your invoice has been created for ${message.mentions.members.first()}, click [here](https://www.paypal.com/invoice/payerView/details/${invoice.id}) to pay it! React with a :white_check_mark: once it has been paid.`)
  74. .setURL(`https://www.paypal.com/invoice/payerView/details/${invoice.id}`)
  75. .setTimestamp();
  76. let invoicembed = await message.channel.send(embed);
  77. message.channel.send(`<@${message.mentions.members.first().id}>`).then(m => m.delete())
  78. invoicembed.react("✅");
  79. const filter = (reaction, fuser) => reaction.emoji.name === "✅" && fuser.id === message.author.id;
  80. const recollector = invoicembed.createReactionCollector(filter);
  81. recollector.on("collect", (reaction, user) => {
  82. paypal.invoice.get(invoice.id, function (error, invoice) {
  83. if (error) {
  84. throw error;
  85. } else {
  86. console.log("Get Invoice Response");
  87. console.log(invoice);
  88. if(invoice.status === "PAID") {
  89. const embed = new Discord.MessageEmbed()
  90. .setTitle("Invoice Paid!")
  91. .setDescription(":check: You have successfully paid your invoice!")
  92. .setTimestamp();
  93. recollector.message.channel.send(embed);
  94. } else {
  95. const embed = new Discord.MessageEmbed()
  96. .setTitle("Invoice unpaid!")
  97. .setDescription(":cross: You have not paid your invoice!")
  98. .setTimestamp();
  99. recollector.message.channel.send(embed);
  100. reaction.users.remove(message.author.id);
  101. }
  102. }
  103. });
  104. })
  105.  
  106. }
  107. });
  108. }
  109. });
  110. })
  111.  
  112.  
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement