#Rian ROnald-checkout
1 messages · Page 1 of 1 (latest)
const { connection } = require('../../config/mysql');
const stripe = require('stripe')('KEY');
module.exports = (express) => {
const app = express.Router();
app.post('/api/auth/hasPaid', async (req, res) => {
const discordID = req.body.userId;
try {
const checkoutSessions = await stripe.checkout.sessions.list({ limit: 3 });
let found = false;
for (const checkoutSession of checkoutSessions.data) {
const sessionDiscordID = checkoutSession.custom_fields[0].text.value;
console.log(sessionDiscordID);
if (sessionDiscordID === discordID) {
found = true;
}
if (!found) {
console.log('User not found in checkout sessions.');
}
});
return app;
};
``` So I have its looking for their discordID that they provide in the custom field in the last 3 checkout session but it returns null
for all 3
The sessionDISCORDID returns null
Okay well I would back up and start logging out each piece
So start by logging out checkoutSession.custom_fields[0]
Then log out checkoutSession.custom_fields[0].text
Then checkoutSession.custom_fields[0].text.value
{
dropdown: null,
key: 'discordid',
label: { custom: 'Discord User ID (Not Username)', type: 'custom' },
numeric: null,
optional: false,
text: { maximum_length: null, minimum_length: null, value: null },
type: 'text'
}
{ maximum_length: null, minimum_length: null, value: null }
null
{
dropdown: null,
key: 'discordid',
label: { custom: 'Discord User ID (Not Username)', type: 'custom' },
numeric: null,
optional: false,
text: { maximum_length: null, minimum_length: null, value: null },
type: 'text'
}
{ maximum_length: null, minimum_length: null, value: null }
null
{
dropdown: null,
key: 'discordid',
label: { custom: 'Discord User ID (Not Username)', type: 'custom' },
numeric: null,
optional: false,
text: { maximum_length: null, minimum_length: null, value: null },
type: 'text'
}
{ maximum_length: null, minimum_length: null, value: null }
null
User not found in checkout sessions.
Logging all 3
console.log(checkoutSession.custom_fields[0]);
console.log(checkoutSession.custom_fields[0].text);
console.log(checkoutSession.custom_fields[0].text.value);```
All null
Okay so then you need to back up and log out the previous pieces
So just log checkoutSession then
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Not sure why its saying payment_status unpaid if they are all paid
When you list Checkout Sessions it will return all Sessions, unpaid or paid. You would need to filter based on the status after you list if you only want to examine paid Sessions
You loop over your list
And only access those Sessions that have payment_status: paid or status: complete depending on which you want to use
returns nothing
What does that mean?
Either way not sure why it shows unpaid for the last 3 even though its not
Have you listed out your Checkout Sessions in general and ensured that some of the list contain paid sesions?
It would not show unpaid sessions that are actually paid...
Why do you assume the last 3 were paid?
That's what it shows on my end
for (const checkoutSession of checkoutSessions.data) {
if (checkoutSession.paid) {
console.log(checkoutSession);
}
What does "That's what it shows on my end" mean?
Where are you looking to see that?
To start here just ignore filtering for paid
The event logs
And just list out your previous 10 or even 100 sessions
okay
How you doing @quartz dove ? Were you able to see some paid Sessions once you listed a greater amount?
Yes it does
Great! Did that help unblock you? Or are you still stuck somewhere?
It did but im now getting Error: TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) here ``` const checkoutSessions = await stripe.checkout.sessions.list({ limit: 100 });
That error is likely happening based on what you are doing to checkoutSessions thereafter
Shouldn't be thrown on your list request
const checkoutSessions = await stripe.checkout.sessions.list({ limit: 100 });
for (const checkoutSession of checkoutSessions.data) {
const sessionDiscordID = checkoutSession.custom_fields[0].text.value; }
Hmm not sure why it doesn't like that... checkoutSessions.data is an array here so it should be iterable