Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module.exports = {
- "name": "invoice",
- "args": true,
- "usage": "<amount in number> <email id> <@user>",
- async execute(client, message, args) {
- const Discord = require("discord.js");
- if (!message.member.roles.has("621913732657709066")) return message.channel.send("No permission.");
- const paypal = require("paypal-rest-sdk");
- const { paypal_client_id, paypal_client_secret } = require("../config.json");
- const { invoices } = require("../index.js")
- if (!message.mentions.members.first()) return message.channel.send("Specify the user the invoice is created for.")
- let dambed = new Discord.MessageEmbed()
- .setTitle("Product Name")
- .setDescription("Reply to this channel with the product name!");
- let moo = await message.channel.send(dambed);
- let theamount = 4.4 / 100 + 0.3 * parseInt(args[0]) + parseInt(args[0]);
- let therealamount = theamount.toFixed(2);
- let thestring = therealamount.toString()
- const filter = m => m.author.id === message.author.id;
- const collector = message.channel.createMessageCollector(filter, {max:1});
- collector.on("collect", async m => {
- moo.delete();
- m.delete();
- paypal.configure({
- "mode": "live",
- "client_id": paypal_client_id,
- "client_secret": paypal_client_secret
- });
- var create_invoice_json = {
- "merchant_info": {
- "email": "administration@endurablemc.com",
- "first_name": "Administration",
- "last_name": "",
- "business_name": "Endurable Services",
- },
- "billing_info": [{
- "email": args[1]
- }],
- "items": [{
- "name": m.content,
- "quantity": 1.0,
- "unit_price": {
- "currency": "USD",
- "value": thestring
- }
- }],
- "tax_inclusive": false,
- "total_amount": {
- "currency": "USD",
- "value": thestring
- }
- };
- message.delete();
- paypal.invoice.create(create_invoice_json, async function (error, invoice) {
- if (error) {
- throw error;
- } else {
- console.log("Create Invoice Response");
- console.log(invoice);
- paypal.invoice.send(invoice.id, async function (error, rv) {
- if (error) {
- console.log(error);
- console.log(error.response);
- throw error;
- } else {
- console.log("Send Invoice Response");
- console.log(rv);
- if (invoices.get(message.mentions.members.first().id)) { invoices.delete(message.author.id); }
- invoices.ensure(message.mentions.members.first().id, invoice.id)
- const embed = new Discord.MessageEmbed()
- .setTitle("Invoice Created")
- .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.`)
- .setURL(`https://www.paypal.com/invoice/payerView/details/${invoice.id}`)
- .setTimestamp();
- let invoicembed = await message.channel.send(embed);
- message.channel.send(`<@${message.mentions.members.first().id}>`).then(m => m.delete())
- invoicembed.react("✅");
- const filter = (reaction, fuser) => reaction.emoji.name === "✅" && fuser.id === message.author.id;
- const recollector = invoicembed.createReactionCollector(filter);
- recollector.on("collect", (reaction, user) => {
- paypal.invoice.get(invoice.id, function (error, invoice) {
- if (error) {
- throw error;
- } else {
- console.log("Get Invoice Response");
- console.log(invoice);
- if(invoice.status === "PAID") {
- const embed = new Discord.MessageEmbed()
- .setTitle("Invoice Paid!")
- .setDescription(":check: You have successfully paid your invoice!")
- .setTimestamp();
- recollector.message.channel.send(embed);
- } else {
- const embed = new Discord.MessageEmbed()
- .setTitle("Invoice unpaid!")
- .setDescription(":cross: You have not paid your invoice!")
- .setTimestamp();
- recollector.message.channel.send(embed);
- reaction.users.remove(message.author.id);
- }
- }
- });
- })
- }
- });
- }
- });
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement