#Rian ROnald-checkout

1 messages · Page 1 of 1 (latest)

sterile coveBOT
floral charm
#

Hello

#

What does "looking for a checkoutSession" mean exactly?

quartz dove
#
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

floral charm
#

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

quartz dove
#
{
  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

floral charm
#

Okay so then you need to back up and log out the previous pieces

#

So just log checkoutSession then

quartz dove
#

Not sure why its saying payment_status unpaid if they are all paid

floral charm
#

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

quartz dove
#

how would I do that?

#

Im assuming it's checkoutSession.paid

#

Returns nothing

floral charm
#

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

quartz dove
#

returns nothing

floral charm
#

What does that mean?

quartz dove
#

Either way not sure why it shows unpaid for the last 3 even though its not

floral charm
#

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?

quartz dove
#

That's what it shows on my end

#
     for (const checkoutSession of checkoutSessions.data) {
        if (checkoutSession.paid) {
        console.log(checkoutSession);
        }
floral charm
#

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

quartz dove
#

The event logs

floral charm
#

And just list out your previous 10 or even 100 sessions

sterile coveBOT
quartz dove
#

okay

floral charm
#

How you doing @quartz dove ? Were you able to see some paid Sessions once you listed a greater amount?

quartz dove
#

Yes it does

floral charm
#

Great! Did that help unblock you? Or are you still stuck somewhere?

quartz dove
#

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 });

floral charm
#

That error is likely happening based on what you are doing to checkoutSessions thereafter

#

Shouldn't be thrown on your list request

quartz dove
#
const checkoutSessions = await stripe.checkout.sessions.list({ limit: 100 });

      for (const checkoutSession of checkoutSessions.data) {
        const sessionDiscordID = checkoutSession.custom_fields[0].text.value; }
floral charm
#

Hmm not sure why it doesn't like that... checkoutSessions.data is an array here so it should be iterable