#jcodog-invoice-settings
1 messages · Page 1 of 1 (latest)
Hello! Stripe.js is client-side code, this should never have access to things like invoice_settings that only exist server-side.
Can you try to provide a lot more details
const Discord = require('discord.js');
const Stripe = require('stripe');
let key;
if (process.env.env == 'prod') {
key = process.env.stripelive;
} else {
key = process.env.stripetest;
}
const stripe = Stripe(key);
module.exports = {
data: new Discord.SlashCommandBuilder()
.setName("stripe")
.setDescription("Get a GDPR request result for your Stripe data. (third party payment provider - No JCN Support)")
.setDefaultMemberPermissions(Discord.PermissionFlagsBits.SendMessages)
.setDMPermission(true),
async execute (interaction) {
let data;
data = getStripe(interaction, data);
if (data != null) {
let user = {
"Stripe ID": data.id,
"Email": data.email,
"Address": data.address
}
let card = {
"Card": data.invoice_settings.default_payment_method.card,
"Billing Address": data.invoice_settings.default_payment_method.billing_details.address,
"Billing Name": data.invoice_settings.default_payment_method.billing_details.name,
"Billing Email": data.invoice_settings.default_payment_method.billing_details.email,
}
interaction.reply({
content: `User: \`\`\`${user}\`\`\`Payment Method: \`\`\`${card}\`\`\`\n\nJCoNet never stores or logs any data returned by Stripe Requests such as this.`,
ephemeral: true
});
} else {
interaction.reply({
content: `We are sorry ${interaction.member.user.username}, We were unable to find a customer ID tied to your discord ID of ${interaction.member.id}. This means you have not made a payment on our system and therefore Stripe has no customer related to you.`,
ephemeral: true
});
}
}
}
async function getStripe(interaction, data) {
let result = await interaction.client.db.query('SELECT stripeID FROM customers WHERE ID='+interaction.member.id);
let results = result[0];
if (results.length > 0) {
data = await stripe.customers.retrieve(results[0].stripeID, {
expand: ['default_source', 'invoice_settings.default_payment_method'],
});
} else {
data = null;
}
return data;
}```
its so a user can view their details and their billing details such as card on an integration I am making. However for some reason the extends invoice settings default_payment_method is not working and says undefined.
and this is node sorry, not stripe.js
I am so used to node libraries for things like this being the company name.js
so what's your question?
sorry that's a lot of code, what exact line is the problem?
"Card": data.invoice_settings.default_payment_method.card, says data.invoice_settings is unefined so cannot read default_payment_method
what is "Card" what is data?
data is returned from the getStripe function
wgat is getStripe?
async function getStripe(interaction, data) {
let result = await interaction.client.db.query('SELECT stripeID FROM customers WHERE ID='+interaction.member.id);
let results = result[0];
if (results.length > 0) {
data = await stripe.customers.retrieve(results[0].stripeID, {
expand: ['default_source', 'invoice_settings.default_payment_method'],
});
} else {
data = null;
}
return data;
}
sorry this is really complex with re-using the same names like data is a param and a returned code
i checked... nothing from the customer object shared the name data.... and Card is just akey for my json
Like really just step 1 log what is returned?
is data = await stripe.customers.retrieve(results[0].stripeID, { expand: ['default_source', 'invoice_settings.default_payment_method'], }); even called? It's in an if for your own code with your own database
if it is called, what exactly is returned?
the full customer object with default_source and invoice_settings.default_payment_method shown in full.
I had issue getting the details to show earlier...
This is a repeat issue as no the error is something else... Do I need to be using a restricted key for this request?
it works fine on the test key
I'm sorry you go way too fast for me
Using a Secret API key or a Restricted API key with the right permissions should just work. Why are you talking about a restricted key all of a sudden?
Can you please confirm and go step by step first. what exactly is returned by your call? Why do you call the variable datawhen data is a parameter name already. Why not call this customer and return customer and store it in a variable tha tis called customer
and then can you please log exactly what you get for that call and what getStripe() returns
I think I solved it trying to get the console log...
I need to await getStripe(interaction, data)
let me test
ah yeah since you use await in some cases and not others
completely forgot that it returns a promise... It fixxed it. Sorry to waste your time. That was my error with my function.
its not working for my live key...
Hi @sweet linden I'm taking over this thread. Give me a sec to catch up
@sweet linden can you tell me what doesn't work? is there an error message?
So I am just checking because I swapped to live to test on myself to see if my data pulled, I have a default payment method saved… but it’s saying bull to invoice_settings default_paymetn_method
OK, did you use the live key when you set the invoice_settings.default_payment_method to the customer?
Can you also share with me the customer ID?
cus_KhfzKiBmXMI12G
Thanks, I can see that you've set a default_source to this customer, and the invoice_settings.default_payment_method is null
How did you set invoice_settings.default_payment_method to this customer?
Yeah... Not sure why...
I didnt yet. I added all my details on the dashboard. That is me in that customer
I see, you need to call the API to set the invoice_settings.default_payment_method to the customer, otherwise it's null.
ive chaned my code to accommodate for this.
Its working now but its weird it did that.
When you select a default payment method in Dashboard, it will set it to the customer's default_source, not invoice_settings.default_payment_method
I fixed the issue, the live one wasnt working on my prod server
had an issue making the command switch to the prod environment variables
When you switch to prod, make sure you use both live mode secret key and publishable key in your application.
What kind of issue are you facing? Let me see if I can help you out.
No it was not getting my live key, it was trying to use my test key… because it wasn’t detecting that the environment tag was prod bot test.
It’s all resolved now.
Great to hear that 🙂