njosefbeck / gatsby-source-stripe

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

Support for "tiers" on the Prices API #65

Closed klintan closed 3 years ago

klintan commented 3 years ago

Hey, Thanks for an awesome plugin. I might be missing something; I read the documentation that you try to auto-expand as many objects as possible and also that the new Prices API is quite new.

However when running this query:

query {
      prices: allStripePrice(
        filter: { active: { eq: true } }
        sort: { fields: [unit_amount] }
      ) {
        edges {
          node {
            id
            active
            currency
            billing_scheme
            tiers_mode
            unit_amount
            product {
              id
              name
            }
          }
        }
      }
}

it seems tiers are not available, I tried

tiers {
   unit_amount
   flat_amount
}

and only tiers etc, but seems it's not there. Am i missing something or is there no support yet for that /not expanded in the plugin? (This is the object I'm referring to https://stripe.com/docs/api/prices/object#price_object-tiers )

njosefbeck commented 3 years ago

Hello!

Ah yeah, at the moment the only expanded field we have for the Price object is product.

https://github.com/njosefbeck/gatsby-source-stripe/blob/2c986483b6a347dba52ce53ca7fff87ff0a296bf/src/stripeObjects.json#L426

We can add data.tiers to the above expand array and that should work. I'm a bit busy at the moment, so feel free to fork this project, add it, and create a PR if you have more bandwidth! Otherwise it may be a week or two.

Thanks!

klintan commented 3 years ago

Ah awesome. Yes I thought about it like the minute after I posted "should've probably just checked the code', but I was lazy .. :P

Thanks for helping out, I created a PR with that one word change, so thanks for making it this easy to add :)

Let me know in the PR if you want me to do any other additional changes (bump the version?). I tested it out on my project and it worked perfect :).

njosefbeck commented 3 years ago

This is live now! Please test with the new npm version and let me know if you run into any issues. Closing this issue for now! Thanks again for the PR!

klintan commented 3 years ago

Awesome thanks for the swift release and everything, i'll try it out :)