stripe / react-stripe-js

React components for Stripe.js and Stripe Elements
https://stripe.com/docs/stripe-js/react
MIT License
1.7k stars 259 forks source link

[BUG]: Test mode API is fetching archived products - Live mode is working perfectly #496

Closed Ehtz closed 2 months ago

Ehtz commented 2 months ago

What happened?

The issue still persists with NextJS14. It was rendering fine and now it just disappeared so wired...

Stripe API version: apiVersion: '2023-08-16',

Stripe test dashboard is fine nothing to report... .env keys are the same as before and working. I can access Stripe Payment Page.

I haven't touched or refactored the card component just have been working with Stripe Webhooks.

I believe this occurred after i used: stripe trigger checkout.session.completed to test webhooks

Environment

"stripe": "^13.2.0",

Reproduction

No response

### Tasks
### Tasks
Ehtz commented 2 months ago

Is this normal that with the triggering: stripe trigger checkout.session.completed from CLI it creates products?

image image
Ehtz commented 2 months ago

I have found the code where the issue is likely coming from:

  const stripe = new Stripe(`${process.env.STRIPE_SECRET_KEY}`, {
    apiVersion: '2023-08-16',
  });
  const userIp = await fetchIpAddress();
  const userCountry = await fetchIPData(userIp as string);
  const prices = await stripe.prices.list();
  console.log('Prices:', prices);

  const sortedPrices = prices.data
    .sort((a, b) => a.unit_amount! - b.unit_amount!)
    .filter(({ active, currency }) => {
      if (!active) return false;
      switch (userCountry) {
        case 'EU':
          return currency === 'eur';
        case 'US':
          return currency === 'usd';
        case 'UK':
          return currency === 'gbp';
        default:
          return false;
      }
    });

  console.log('Country:', userCountry);
  console.log('Sorted Prices:', sortedPrices);
  return sortedPrices;
}

Now Stripe is returning archived products and this despite if (!active) return false;

Tested Live products and works... Live API is pulling the proper products which are Active, the Test is not only the inactive, maybe the API is stuck for Test?

Investigating further as to why it is returning only archived products...

Ehtz commented 2 months ago

Is this normal that with the triggering: stripe trigger checkout.session.completed from CLI it creates products?

image image

Says it's active when called but it's not true it was archived and is archived when calling

image
Ehtz commented 2 months ago

Fixed by archiving all products and creating new ones in test dashboard

brendanm-stripe commented 2 months ago

Note that you can also specify active=true in your Prices List API request: https://docs.stripe.com/api/prices/list#list_prices-active

Ehtz commented 2 months ago

Note that you can also specify active=true in your Prices List API request: https://docs.stripe.com/api/prices/list#list_prices-active

Yes thanks for the observation, will implement this