njosefbeck / gatsby-source-stripe

Gatsby source plugin for building websites using Stripe as a data source
74 stars 17 forks source link

Support for the new Prices API #53

Closed acommodari closed 4 years ago

acommodari commented 4 years ago

Hello, today I noticed that stripe is recommending we use their new Prices API for Stripe Checkout. I was wondering if you were aware of this new API and if so, do you have a timeline for when Prices will be added as a supported type?

Here is a link to the stripe docs migration guide: https://stripe.com/docs/payments/checkout/migrating-prices

Thank you for your time 😄

njosefbeck commented 4 years ago

Thanks for reaching out and letting me know about this new resource! I've gone ahead and added that as well as the recently added checkout sessions resource. This is live on npm now, so if you update to v3.1.0 you should be able to pull down prices. Let me know if you run into any issues!

robinlarsson commented 4 years ago

Cheers for fixing prices! I been looking for this feature for a while.

I wonder if the documentation should refer to the type of object in singular, 'Price' rather than 'Prices'.

Also, instead of graphql I am trying a more plain approach. Would you have any clue what I am missing? (I'm new to Stripe):

import { loadStripe } from '@stripe/stripe-js'

const stripePromise = loadStripe(<key>);
const stripe = await stripePromise;
const { error, prices } = await stripe.prices.list();

result: Catched Error: TypeError: Cannot read property 'list' of undefined`

njosefbeck commented 4 years ago

Hello!

So Stripe.js, which is the front-end JS library, doesn't have access to the prices endpoint. On the other hand, stripe-node does have access to that endpoint.

By using this plugin, you can access the prices.list() method on the Stripe object automatically, thus bringing in all your prices into your Gatsby project. Then you use GraphQL to make them available to your front-end React code.

Hopefully that's helpful! Let me know if you have other questions!