Giter Site home page Giter Site logo

gatsby-source-stripe's Introduction

gatsby-source-stripe

Source plugin for pulling in data from the Stripe API. Current with Stripe API version 2020-08-27.

This plugin is a source plugin, so it brings in your Stripe data. Use cases for this Stripe source plugin:

  • Create an ecommerce store. This plugin allows you to bring your product and SKU data into your Gatsby site at build time to be used with Stripe Checkout.
  • Create various dashboards around customers, invoices, etc. Use this plugin to bring in any of the data types listed below.

Do you use this plugin in your Gatsby project? Let us know and we can add it here as an example!

Check out the CHANGELOG for past and upcoming updates.

Install

npm install gatsby-source-stripe

or

yarn add gatsby-source-stripe

How to use

NOTE: You must be using Gatsby version 4.0.0 or greater.

In the plugin options objects' array, specify the object types you would like to get data for. For example, if you'd like to get the lists of data for your Skus and Products, your objects array would look like this: ['Product', 'Sku'].

Additionally, only include your Stripe secret key via a .env file that is not version-controlled. We don't want your key ending up in your version-controlled source code! For enhanced security, you can also create a restricted API key in your Stripe Developer Dashboard. Since this plugin only ever sources data, you can restrict All core resources to Read only, and even turn off access to certain resources that you know you don't use.

Enable downloading files associated with your Stripe Skus and Products by setting downloadFiles to true.

Example:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-stripe`,
    options: {
      objects: ['Balance', 'BalanceTransaction', 'Product', 'ApplicationFee', 'Sku', 'Subscription'],
      secretKey: 'stripe_secret_key_here',
      downloadFiles: true,
    }
  }
]

Supported List of Types

Below is a table with a list of the Stripe types supported in the options' objects array, as well as what Stripe API method the type maps to, and any other additional notes.

Type Stripe API Method Notes
Balance stripe.balance.retrieve() Not iterable
BalanceTransaction stripe.balanceTransactions.list() None
Charge stripe.charges.list() None
Customer stripe.customers.list() None
Dispute stripe.disputes.list() None
Event stripe.events.list() None
File stripe.files.list() None
FileLink stripe.fileLinks.list() None
PaymentIntent stripe.paymentIntents.list() None
Payout stripe.payouts.list() None
Product stripe.products.list() None
Refund stripe.refunds.list() None
Coupon stripe.coupons.list() None
Invoice stripe.invoices.list() None
InvoiceItem stripe.invoiceItems.list() None
Plan stripe.plans.list() None
Subscription stripe.subscriptions.list() None
Account stripe.accounts.list() None
ApplicationFee stripe.applicationFees.list() None
CountrySpec stripe.countrySpecs.list() None
TopUp stripe.topUps.list() None
Transfer stripe.transfers.list() None
IssuingAuthorization stripe.issuing.authorizations.list() Issuing is in closed beta. Can only get data if you have access to the beta.
IssuingCardholder stripe.issuing.cardholders.list() Issuing is in closed beta. Can only get data if you have access to the beta.
IssuingCard stripe.issuing.cards.list() Issuing is in closed beta. Can only get data if you have access to the beta.
IssuingDispute stripe.issuing.disputes.list() Issuing is in closed beta. Can only get data if you have access to the beta.
IssuingTransaction stripe.issuing.transactions.list() Issuing is in closed beta. Can only get data if you have access to the beta.
TerminalLocation stripe.terminal.locations.list() None
TerminalReader stripe.terminal.readers.list() None
Order stripe.orders.list() None
OrderReturn stripe.orderReturns.list() None
Sku stripe.skus.list() None
SigmaScheduledQueryRun stripe.sigma.ScheduledQueryRuns.list() Only works with live secret keys, not test keys
WebhookEndpoint stripe.webhookEndpoints.list() None
CreditNote stripe.creditNotes.list() None
Review stripe.reviews.list() None
Session stripe.checkout.sessions.list() None
Price stripe.prices.list() None
TaxRate stripe.taxRates.list() None
SetupIntent stripe.setupIntents.list() None
PromotionCode stripe.promotionCodes.list() None
SubscriptionSchedule stripe.subscriptionSchedules.list() None
EarlyFraudWarning stripe.radar.earlyFraudWarnings.list() None

Expanding Objects

Expanding all Stripe objects is tricky, as some objects have a lot of nested sub-objects to expand! We've tried to auto-expand as much of the top-level objects as possible. You can peruse a list of what is expanded per object in the stripeObjects.json file. If we're missing something that you'd like expanded, please create an issue!

Auto-pagination

NOTE: Due to stripe-node's autopagination recommendations this plugin has been tested against v10.13.0 and later. If you experience any issues with earlier versions of Node, please first consider upgrading your Node version. Otherwise, file an issue and we'll try to resolve!

All list responses are fully paginated.

Downloading Files

Setting downloadFiles: true in the plugin configuration enables downloading of images on Sku and Product objects. A Gatsby File node is created for each downloaded file, and references are placed on the localFiles field of their Stripe nodes.

You can give these File nodes to plugins like gatsby-image to create responsive images and/or gatsby-transformer-sharp to process images at build.

How to query with Skus

NOTE: For the example below, be sure that you actually have products with SKUs in your Stripe account, otherwise you will get an error saying: Cannot query field "allStripeSku" on type "Query". With the update to Prices API, the Sku/Order API is now deprecated. If you have an account that uses Prices, see How to query with Prices.

Below is an example query for fetching all your Stripe SKUs. Note that the localFiles will not be there if you didn't specify downloadFiles: true in the plugin options.

{
  allStripeSku {
    edges {
      node {
        id,
        active,
        localFiles {
          id
        }
        product {
          id
        }
      }
    }
  }
}

Just replace "Sku" with any of the types used in your config objects array.

You can also query for a specific Stripe object like this:

{
  stripeCustomer(id: { eq: "customer_id_here" }) {
    id,
    name
  }
}

When using GraphiQL, click on "Docs" in the top-right corner of the screen to explore all of the Stripe data being brought in, including their schemas. Additionally, check out Gatsby's handy GraphQL Reference for information about filtering, sorting, etc.

How to query with Prices

NOTE: With the update to Prices API, the Sku/Order API is now deprecated. If you still have an account that uses Skus, see How to query with Skus.

Below is an example query for fetching all Stripe Prices.

{
allStripePrice {
    edges {
      node {
        id,
        object,
        active,
        billing_scheme,
        product,
        type,
        livemode,
        unit_amount,
        unit_amount_decimal,
        currency
      }
    }
  }
}  

You can add or remove any of the nodes to query for what you need.

Gotchas

This section outlines common questions and issues that other user's have run into and how they were resolved.

"My Subscription objects aren't showing up in my GraphQL results"

This issue comes up when trying to get back all SKU for your account, expecting that products of type service will also be present. As Subscriptions (products of type service) don't have SKUs, they won't show up in the SKU results. To get back those, you must also query for Product objects.

Thus, for those who have Subscription products, we recommend you have an objects array like below.

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-stripe`,
    options: {
      objects: ['Sku', 'Product'],
      secretKey: 'stripe_secret_key_here',
      downloadFiles: true,
    }
  }
]

Develop

Would you like to help maintain this project? We would love your help! Checkout issues and look for tags labeled help wanted. Also please check out our CODE OF CONDUCT and our CONTRIBUTING documents.

To set up the project locally, follow these steps:

  1. Fork the repo and pull it down locally. For ease of testing, we recommend pulling it into an existing Gatsby project, in a plugins directory.
  2. Add the plugin, with options, to gatsby-config.js.
  3. Install dependencies by running npm install in the project directory.
  4. Run npm run build in the console, to transpile the code for testing and running in your project.
  5. Hack away!

Included is an ESLint config to help check the correctness of your changes of your code, and a prettier config to format it. Use them with the corresponding plugins for your editor of choice, or run the tools from the command line with npm run lint and npm run format. Don't forget to format your changes with prettier before submitting a PR!

gatsby-source-stripe's People

Contributors

brittneypostma avatar brxck avatar develo-pera avatar francesco-lanciana avatar klintan avatar njosefbeck avatar raae avatar robinlarsson avatar t2ca avatar thorsten-stripe avatar vsterlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gatsby-source-stripe's Issues

Possible to include `metadata` parameter in object response?

The metadata parameter is useful for showing arbitrary information related to certain Stripe objects. According to the docs, Account, Charge, Customer, PaymentIntent, Refund, Subscription, and Transfer support this property, and I know that Plan and Product do as well.

Is it possible for metadata to be one of the queryable fields?

Expand all the objects and sub-objects, oh my!

The Stripe API allows for the auto-expansion of objects returned. To handle auto-expansion, I've added a methodArgs key to each Stripe Object in stripeObjects.json. Inside that methodArgs key, an expand array is defined (example here).

Ultimately this looks like:

"methodArgs": {
  "expand": [
    "data.source.destination",
    "data.source.customer",
    "data.source.invoice"
  ]
}

Where I need help, is that there are MANY more expansion possibilities across the Stripe objects that this plugin supports. I need help looking through the Stripe API documentation for "expandable" fields, and also subsequent "expandable" sub-fields.

Additionally, someone would need to test to ensure that these expandable fields actually work, by running the plugin in a Gatsby project. If the field isn't expandable, and you've specified that it is, stripe-node will error out. We want to avoid fields that error out!

Feel free to:

  1. Fork the project
  2. Update stripeObjects.json with additional expandable fields
  3. Test in a local Gatsby project that those additions actually work
  4. Submit a pull request so I can test

Any and all help would be awesome. โค๏ธ

Support for "tiers" on the Prices API

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 )

Cannot query product field on price object

Prerequisites

[X] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
GrapghQL query for the product field as a property of a price object (allStripePrice) errors with:

Cannot query field "product" on type "Query"

This includes a suggestion that the field cannot be queried if it is optional, as Gatsby can't infer the type in the schema.

To Reproduce
Steps to reproduce the behavior:

  1. Configure gatsby-source-stripe to use objects: ['Product', 'Price']
  2. Set up a page query similar to: (simplified for brevity)
  query Shop {
    allStripePrice(filter: {active: {eq: true}}) {
      edges {
        node {
          unit_amount
          product {
            id
          }
        }
      }
    }
  }
  1. Run in develop mode or build site
  2. Error is displayed

Expected behavior
product field can be queried on price objects as it always present on responses from the Stripe API (expandable).

Screenshots
If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

os: macOS 10.15.7
node: 14.15.5
npm: 6.14.11
gatsby: 2.32.3
gatsby-source-stripe: 3.2.1

Gatsby config:

Copy the portion of your Gatsby config for this plugin here. Do not include your secretKey.

{
  resolve: `gatsby-source-stripe`,
  options: {
    objects: ['Product', 'Price'],
    secretKey: '...',
    downloadFiles: false,
  },
}

Additional context
If I run this query in the GraphiQL explorer, it works fine!

Stop trying to download the file object URL

Description

Currently we try to use the url property of the Stripe file Object when downloading files is set too true. This never works as it doesn't actually point to any files. @brxck said previously that we don't use the urls contained in the objects that make up payload.links.data because:

  1. We want to avoid downloading files multiple times if it has multiple links
  2. It only contains links to publicly accessable files.

The more I think about it the less this makes sense to me. My arguments for no longer using the url property and instead switching to links are:

  1. The url property will never work (at least I don't currently know how to make it work)
  2. I'm not aware of any way to provide multiple links to the same file in Stripe
    2a. Even if there were it's still better to download multiple than nothing at all
  3. I'm currently chasing this up with Stripe support but I don't actually think it's possible to make files private. All Stripe hosted files seem to be public.

Steps to Reproduce

  1. Upload an image to Stripe (SKU's let you upload an image to Stripe)
  2. Add "File" to options.objects of this plugin
  3. Run "npm run start" and you will see that the URLs associated with the File object will fail

Additional Information

I am currently chasing up the following two questions with Stripe support and will get post back when I have answers:

  1. What is the URL property of the File object actually used for? Can we make some use of it?
  2. Are all images hosted by Stripe public or is it possible to have private images/files.
    2a. In this case what HTTP headers would need to be provided to pull down these files.

A reference to the File object: https://stripe.com/docs/api/files/object

Update CONTRIBUTING.md about how we handle dep versioning & committing

Now that we're getting more contributors to this project (very exciting!), we need to formalize a couple of things that we do in this project. I plan on adding the following to the CONTRIBUTING.md:

  1. If you add any dependencies to the project via package.json, we only use absolute versions and not 'fuzzy' versions. For example, 2.2.6 instead of ^2.2.6. This helps with consistency across npm installs.

  2. For commits, we prefer the active voice / imperative mood. For more info (and a great article), check here.

  3. Encourage frequent running of ESLint and Prettier, to ensure consistency across how we code.

Unknown argument "product" on field "allStripeSku" of type "Query"

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

Using product argument on allStripeSku results in error Unknown argument "product" on field "allStripeSku" of type "Query". If the argument is changed to another argument, like limit it works as expected. The documentation shows product is a valid argument.

Steps to Reproduce

  1. Consider the following query:
query productDetail {
  product: stripeProduct(id: {eq: "prod_NNNNN"}) {
    id
    name,
  },
  skus: allStripeSku(product: {eq: "prod_NNNNN"}) {
    edges {
      node {
        id
      }
    }
  }
}

Expected behavior: [What you expect to happen]
The query should return a single product, and all SKUs belonging to that product.

Actual behavior: [What actually happens]
Returns an error Unknown argument "product" on field "allStripeSku" of type "Query".

Reproduces how often: [What percentage of the time does it reproduce?]
100%

Versions

os: Mac 10.14.3
node: 10.15.1
npm: 6.4.1
gatsby: 2.4.1
gatsby-source-stripe: 2.1.7

Products with recurring payment not shown on Gatsby shop

Prerequisites

  • [ X] Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

I'm trying to use this plugin to set up a Gatsby storefront for my company. However, we want our products to be subscription-based. The one time payment products show up fine, but the ones with recurring payments fail to show up on the storefront even after I stop my localhost and start it up again.

Steps to Reproduce

  1. Add product to Stripe with recurring payment
  2. Close local server and restart
  3. The recurring payment product does not show up

Expected behavior: The recurring payment product should show up on the store along with the one time payment products

Actual behavior: The recurring payment product does not show up.

Reproduces how often: 100% of the time

Versions

os: MacOS High Sierra 10.13.6
node: v10.7.0
npm: 6.14.2
gatsby: Gatsby CLI version: 2.8.22
gatsby-source-stripe: 2.2.2

Additional Information

None.

Is there a way of getting back the price of a subscription (product)

Prerequisites

[ X ] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
Is there a way of getting back the price of a subscription (Product)

Enable GraphQL support for Product images

Any GraphQL File object that contains an image has a childImageSharp field that you can query and pass to Gatsby image components (using gatsby-plugin-image). It would be very cool if it were possible to do the same thing with gatsby-source-stripe when retrieving Product images. This would allow seamless interaction between the gatsby-image-plugin and gatsby-stripe-plugin to display product images.

At present, querying for the image field on a product returns something like the following;

{
  "data": {
    "stripePrice": {
      "id": "price_1KEBiRGuNIhpNc5curNr3z04",
      "product": {
        "description": "A tote bag 4 u <3",
        "images": [
          "https://files.stripe.com/links/MDB8YWNjdF8xN2JIV29HdU5JaHBOYzVjfGZsX3Rlc3RfMUhlM0hwbEFaSkUxdDJjZkVtejNnQmR500hXn0ZUFq"
        ],
        "name": "Fancy tote"
      }
    }
  },
  "extensions": {}
}

i.e. an array of links that can be used to download the image file. Somehow you'd need to convert this to a File(-like?) object so that GraphQL / gatsby-plugin-image could expand an associated childImageSharp field. From a glance, it looks like it might be possible to use the FileDownloadService class to do this?

Docs for gatsby-plugin-image: https://www.gatsbyjs.com/plugins/gatsby-plugin-image

[HELP WANTED] - GatsbyV4 [bug] - error while running the sourceNodes lifecycle

Prerequisites

[ X ] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
A clear and concise description of what the bug is.
I've updated to GtsabyV4 - When running my site i get the following error

"gatsby-source-stripe" threw an error while running the sourceNodes lifecycle:
Cannot read property 'type' of undefined
TypeError: Cannot read property 'type' of undefined

This is not necessarily a BUG but maybe a request to update to support Gatsby V4.

To Reproduce
Steps to reproduce the behavior:

  1. Update all packages to the latest Gatsby V4
  2. Run Gatsby in Develop or on Serve.
  3. error appears, and does not allow Stripe Graphwl to be generated

Expected behavior
Everything to run smoothly and all Stripe Graphql data to appear.

Screenshots

Screenshot 2021-11-01 at 16 50 22

Versions (please complete the following information):

os: macOS Big Sur 11.6
node: v14.17.3
npm: 6.14.13
gatsby: 4.0.2
gatsby-source-stripe: 3.2.2

Gatsby config:

Copy the portion of your Gatsby config for this plugin here. Do not include your secretKey.

{
      resolve: `gatsby-source-stripe`,
      options: {
        objects: ['Price'],
        secretKey: ...,
        downloadFiles: true
      }
    },

Using gatsby-transformer-json in the same project causes build errors

Pre-requisites

  • Read through the README fully
  • Ensured you are running Node v.10 or above
  • Made sure you're using at least Gatsby v.2.0.15
  • Checked that your issue isn't already filed

Description

When running gatsby build on a project that uses both gatsby-source-stripe and gatsby-transformer-json, the build fails with an error like the following:

Error: Nodes can only be updated by their owner. Node "prod_FKQdtEsTJLpdoG" is owned by "gatsby-source-stripe" and another plugin "gatsby-transformer-json" tried to update it.

With a non-zero exit code, the build fails.

Steps to Reproduce

  1. Create a new Gatsby project that uses gatsby-source-stripe
  2. Add your stripe credentials via environment variable or .env file
  3. Add gatsby-transformer-json to plugins section of gatsby-config.js
  4. Run gatsby build

Expected behavior: gatsby-transformer-node does nothing to the Stripe object nodes

Actual behavior: gatsby-transformer-node sees an application/json node internal type and tries to transform it.

Reproduces how often: 100% of builds

Versions

os: [version]
node: 10.13.0
npm: 6.7.0
gatsby: 2.10.4
gatsby-source-stripe: 3.0.1

Additional Information

If you modify the plugin to use a different internal mediaType in StripeObject.js, the error disappears.

Remove auth header entirely

Description

Turns out that files/images hosted on Stripe don't actually require you to authenticate with your Stripe credentials. They are entirely public. This means that there isn't ever a need for you to provide the auth header - it should simply always be removed. I have tested this locally and can now successfully pull down all images.

I'm happy to create a PR that will remove the auth option, remove the auth header in every instance, and simplify LocalFile.js since the downloadStripeHostedFile method is now no longer needed. @njosefbeck @brxck let me know if I'm forgetting something important.

Steps to Reproduce

  1. Grab one of the URLs that points to an image hosted on Stripe.
  2. Open up an incognito window and paste in the address.
  3. Hit enter and the file should download

This means that the file can be downloaded without any cookies being provided for authentication.

Using Gatsby Image with Gatsby Source Stripe

Screen Shot 2021-05-23 at 10 13 28 AM

Hi,

Thanks for creating this. It's extremely helpful.

I'm having an issue using the plugin with Gatsby Image.

I've changed downloadFiles to true, but when building the query for products in GraphiQL I'm unable to see a local files field mentioned in the read me. My query looks as follows.

query MyQuery {
  allStripePrice {
    edges {
      node {
        active
        product {
          id
          images
        }
      }
    }
  }
}

Is there a way to use the plugin alongside Gatsby Image to optimize the images attached to each product? I've attached an image of what GraphiQL is giving me as options.

Thanks,

Jon

Linking products and SKUs

I'm building some e-commerce functionality, pulling product data from stripe. Is there a way to link products and skus together? Since we need to pull information like description etc from the product API and things like price etc from the SKU api.

Ideally we could make a query like this.

{
  allStripeSku {
    edges {
      node {
        id
        active
        price
        products {
          id
          name
          description
        }	
      }
    }
  }
}

Is something like this possible, or would I need to chain several queries to get the product which belongs to a sku?

More robust testing

To test this plugin, I typically use the test data provided by Stripe. I would love to test the plugin across more complex, larger Stripe data.

Do you have a Stripe account with a lot of data in it?
Are you a Stripe Connect user?
Are you a part of any closed betas (thinking: issuing)?

If so, it would be great if you would test this plugin using that data.

Q1 Updates

Just a list of some small updates want to do:

  • Add a "gotchas" section to the README and add example of Subscription products vs skus.
  • Use GitHub's new Issues template and remove old one.
  • Update usage of getAppInfo to remove deprecation warning.

Avoid stripe secret key in gatsby-config?

Is there a way to avoid putting the stripe secret key in the gatsby-config and accessing it from an environment variable instead? I'm a little weary of including sensitive keys in the repo.

Subscription Plan Query Example

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

Is there a way to query the plans for Subscription objects?
It looks like I can only query allStripeSku for skus or allStripeProduct where I can get the product id of any type of product (product and services) but not the plan id.

Steps to Reproduce

  1. Search for an allStripeSubscription

Expected behavior: A way to query the different products that are plans of a subscription for a reoccurring payment

Actual behavior: Can't find it

Write unit tests for project

Just putting a reminder here that I'd like to integrate unit tests into this project, especially now that more people are contributing to it.

I'm open to suggestions on unit testing frameworks. My first thought is Jest, as I have the most experience with that, but I'm not 100% married to the idea.

Product object not showing in the graphQL

Prerequisites

[ x ] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
The "Product" object is not showing up. I can add other objects, such as "Price" and "Customer" and they show up in the graphQL, but Product does not. I can get to products through the price object, but it does not have all of the attributes of the product that I need to display.

To Reproduce
Steps to reproduce the behavior:

  1. add the product object to gatsby-config.js
  2. restart
  3. check graphQL

Expected behavior
I would expect to see the allStripeProduct in the graphQL

Screenshots
Screenshot 2022-11-08 at 8 36 49 PM

Versions (please complete the following information):

os: Mac OS 13.0
node: v18.6.0
npm: 8.13.2
gatsby: 4.5.4
gatsby-source-stripe: 4.0.0

Gatsby config:

'gatsby-plugin-netlify',
    {
      resolve: `gatsby-source-stripe`,
      options: {
        objects: ['Price', 'Product', 'Customer'],
        secretKey: process.env.STRIPE_SECRET_KEY,
        downloadFiles: false,
      },
    },

Error "Cannot query field \"product\" on type \"StripePrice\"."

Prerequisites

[ ] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
When we try to query prices an error occures : {
"errors": [
{
"message": "Cannot query field "product" on type "StripePrice".",
"locations": [
{
"line": 9,
"column": 9
}
],
"extensions": {
"stack": [
"GraphQLError: Cannot query field "product" on type "StripePrice".",
" at Object.Field (D:\immal\immal.org\node_modules\graphql\validation\rules\FieldsOnCorrectTypeRule.js:48:31)",
" at Object.enter (D:\immal\immal.org\node_modules\graphql\language\visitor.js:323:29)",
" at Object.enter (D:\immal\immal.org\node_modules\graphql\utilities\TypeInfo.js:370:25)",
" at visit (D:\immal\immal.org\node_modules\graphql\language\visitor.js:243:26)",
" at validate (D:\immal\immal.org\node_modules\graphql\validation\validate.js:69:24)",
" at graphqlMiddleware (D:\immal\immal.org\node_modules\express-graphql\index.js:98:38)",
" at processTicksAndRejections (internal/process/task_queues.js:93:5)"
]
}
}
]
}

To Reproduce
Query : {
allStripePrice {
edges {
node {
id,
object,
active,
billing_scheme,
product,
type,
livemode,
unit_amount,
unit_amount_decimal,
currency
}
}
}
}

image

Gatsby config:
{
resolve: gatsby-source-stripe,
options: {
objects: ["Product", "Price", "Plan"],
secretKey: process.env.STRIPE_SECRET_KEY,
downloadFiles: true,
},
},

Pulling product details

Hi,

Not entirely sure if this is an issue but I'm not getting the whole product details especially price and it's api_id, i believed this api_id was sku before.

It's pulling the product name, images etc. but no price and api_id

gatsby config used

{
resolve: gatsby-source-stripe,
options: {
objects: [
"Balance",
"BalanceTransaction",
"Product",
"ApplicationFee",
"Sku",
"Subscription",
],
secretKey: "my_secret_key",
downloadFiles: true,
},
},

Thanks

Error: Cannot query field "localFiles" on type "StripeProduct".

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Question

I'm using the Stripe Checkout Beta, as well as images[] field on Products. For Product images, an array of image URLs is added to a product via the Stripe API. These images are hosted elsewhere, in my case they live in the static directory of my Gatsby site.

Here's an example of a query and it's response:

Query

query allProducts {
    products: allStripeProduct {
      edges {
        node {
          id
          images
        }
      }
    }
  }

Response

{
  "data": {
    "products": {
      "edges": [
        {
          "node": {
            "id": "prod_EcDfq1CvGkdgbc",
            "images": [
              "http://localhost:8000/products/600.jpg"
            ]
          }
        },
        ...
      ]
    }
  }
}

If I change the query to add localFiles, an error is returned.

Query

query allProducts {
    products: allStripeProduct {
      edges {
        node {
          id
          images
          localFiles
        }
      }
    }
  }

Response

{
  "errors": [
    {
      "message": "Cannot query field \"localFiles\" on type \"StripeProduct\".",
      "locations": [
        {
          "line": 7,
          "column": 11
        }
      ]
    }
  ]
}

I've reviewed the existing issues related to this but it seems I'm doing everything correctly. I'm using Checkout Beta, but I believe that only comes into play on SKU images.

Is the current version of gatsby-source-stripe setup to work with the Product images array?

Versions

os: Mac 10.14.3
node: 10.15.1
npm: 6.4.1
gatsby: 2.1.17
gatsby-source-stripe: 2.1.7

Update README.md with more querying examples

Right now the How to query section is looking kind of sad. Sure, it covers the basics, but it would be nice if there were more examples. Especially, more complex examples.

Mainly I'm interested in showing examples of how to:

  • Sort
  • Filter
  • Limit

Additionally, creating examples that show how to put together queries both in GraphiQL and how that query would look in code, in a GraphQL project. Both coded static queries and regular queries would be great, too.

Further, sharing how to access the "Docs" section in GraphiQL to peruse the schema (i.e. to answer a question like: "what are the fields on my StripeCustomer nodes").

If you're interested in helping beef up this section, feel free to:

  1. Fork the project
  2. Update the README.md
  3. Submit a PR!

Any and all help, as always, would be much appreciated. ๐ŸŽ‰

Support Image Downloading

It would be really great if the source plugin supported the downloading of product and sku images. This would make it possible to use things like gatsby-image with the resulting nodes.

@njosefbeck, you mentioned that a separate transformer plugin might be the way to do this, but I think it might be better to keep this within the source plugin. The transformer plugin wouldn't be able to place links to the new File nodes directly on the Stripe nodes, because they cannot be directly modified after creation. Instead links would have to be placed within fields using createNodeField.

The difference is in querying
{ stripeProduct (id: { eq: "..." }) { localImages } }
vs
{ stripeProduct (id: { eq: "..." }) { fields { localImages } } }

Browsing around, it seems that this sort of thing is usually implemented by the source plugin itself, and that transformers usually create new types of nodes from others, rather than modifying old nodes.

In any case, I'd definitely like to help get this implemented. Let me know what you think!

Format download files errors better

Screen Shot 2019-04-13 at 7 51 30 AM

So I know that the download files feature doesn't work with images uploaded to Stripe, so the errors I got make sense, BUT all the errors were a bit overwhelming. The URL in the "Failed to process remote content" seems to show up twice, and the formatting could be improved.

Ignore the non-capitalization of "stripe" in the screenshot. I fixed that and it's in the latest release.

Let me know your thoughts on how we might improve these error outputs @brxck and @Francesco-Lanciana !

Thanks!

Cannot query field "allStripeSku" on type "Query" even with a valid secret key

Prerequisites

  • [ x] Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

I read in one closed issue in the repo of the tutorial I followed that this can happen because of the wrong Stripe secret key, but I don't think that's the reason in my case. I've added the right secret key exactly as described here: https://www.gatsbyjs.org/tutorial/ecommerce-tutorial/, I've even hardcoded it and it still doesn't work, I rolled the secret key and tried with the new one and I have the same problem. I even created a new account and still the same.

Steps to Reproduce

  1. Just add gatsby-source-stripe to your project
  2. Add what's needed to be added to the gatsby-config.js
  3. Try example query allStripeSku

Expected behavior: To have that query

Actual behavior: Graphql error Unknown field 'allStripeSku' on type 'Query'.

Reproduces how often: Every time

Versions

os: macOs Mojave 10.14.5
node: 10.16.0
npm: 6.9.0
gatsby: 2.17.11
gatsby-source-stripe: 3.0.4

Additional Information

Here's the full log. Maybe this line can tell something warn The gatsby-source-stripe plugin has generated no Gatsby nodes. Do you need it?

> [email protected] develop /Users/developera/moje/ecommerce-gatsby-tutorial
> gatsby develop

success open and validate gatsby-configs - 0.040s
success load plugins - 2.058s
success onPreInit - 0.006s
success initialize cache - 0.029s
success copy gatsby files - 0.213s
success onPreBootstrap - 0.020s
warn The gatsby-source-stripe plugin has generated no Gatsby nodes. Do you need it?
success source and transform nodes - 0.733s
success building schema - 0.382s
success createPages - 0.002s
success createPagesStatefully - 0.052s
success onPreExtractQueries - 0.011s
success update schema - 0.023s

 ERROR #85907  GRAPHQL

There was an error in your GraphQL query:

- Unknown field 'allStripeSku' on type 'Query'.

File: src/components/Skus.js

failed extract queries from components - 0.343s
success write out requires - 0.033s
success write out redirect data - 0.002s
success Build manifest and related icons - 0.125s
success onPostBootstrap - 0.148s
โ €
info bootstrap finished - 14.662 s
โ €
success run queries - 0.055s - 5/5 91.65/s

 ERROR #98123  WEBPACK

Generating development JavaScript bundle failed


/Users/developera/moje/ecommerce-gatsby-tutorial/src/components/Skus.js
  8:9  error  Cannot query field "allStripeSku" on type "Query". Did you mean "allSite"?  graphql/template-strings

โœ– 1 problem (1 error, 0 warnings)


File: src/components/Skus.js

failed Building development bundle - 6.482s


โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”
5 pages                                                                                   Failed                                                                                  gatsby-starter-default

Fix issues with downloading files

I was playing a bit with your plugin tonight โ€” thanks for making it! Noticed a couple of things that could be improved with the image downloading.

First, I noticed that sometimes my image processing query failed. Looking at the bootstrap output, I noticed that files didn't finish downloading until after bootstrap was finished. Which means that you're not waiting for the Promise returned by createRemoteFileNode to resolve before telling Gatsby you're finished.

Second, fairly recently we added a new required field to createRemoteFileNode โ€” parentNodeId https://www.gatsbyjs.org/packages/gatsby-source-filesystem/?=filesys#createremotefilenode

This is needed so that Gatsby knows what node the newly downloaded File is connected to. Without this, Gatsby will delete the File node when you restart the develop server.

Would appreciate a fix to these, thanks!

[question] how rebuild happens automatically when something changes in product information!

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

I am trying to implement the retrigger the gatsby develop automatically whenever something changes in headless cms as this feature provided by gatsby-source-stripe. I found that when something changes in the product information on stripe website a webhook is retriggered and gatsby build initiated on the client side. But I didn't find the code which handles this trigger event in the source code. can anyone point out the code where we handle the webhook retrigger please!

Price instead of SKU

It looks like SKUs are not used with Stripe Checkout anymore, they use Price object instead (there is no way to add SKU in Stripe dashboard). When I query allStripePrice with the plugin, I can retrieve the product's id but not its name, so I need a separate query for Stripe products to retrieve the product's name which is inconvenient. If it would be possible to retrieve product's name from price query it would be a great addition to plugin.

Out of date Stripe SDK API version

Prerequisites

[x] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug

The stripe version for this library is now about 3 years old. https://github.com/njosefbeck/gatsby-source-stripe/blob/main/package.json#L51 ([email protected]) and I'm needing some newer functionality from the sdk for my netlify worker functions. Any chance of updating this to the current version of Stripe API (apiVersion: 2022-11-15 at the time of this writing)?

Fwiw, I've used this project a ton for helping small businesses depend on stripe as a source for gatsby builds. I'm also willing to attempt the upgrade myself but want to check that such a PR would be well received before I attempt

To Reproduce
Attempt to access newer stripe sdk methods

Expected behavior
They work

Versions (please complete the following information):

os: [macos]
node: [16]
npm: [9]
gatsby: [4]
gatsby-source-stripe: [4]

Gatsby config:

Copy the portion of your Gatsby config for this plugin here. Do not include your secretKey.

{
  resolve: `gatsby-source-stripe`,
  options: {
    objects: ['Sku', 'Product', 'Customer'],
    secretKey: '...',
    downloadFiles: true,
  }
}

Additional context
Add any other context about the problem here.

Get Price in stripeProduct query

It would be very useful to be able to extract prices while querying allStripeProducts or stripeProduct. It is currently possible to get products from price query, but not other way around.

sku.product.localFiles is empty unless sku.image is present

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Read through the README fully
    • Ensured you are running Node v.10 or above
    • Made sure you're using at least Gatsby v.2.0.15
    • Checked that your issue isn't already filed

Description

Hey! I've been having an issue with gatsby-starter-stripe and I'm finally getting around to figuring it out.

This started happening after upgrading the plugin to 3.0+. sku.product.images is always empty unless sku.image is present. I'll provide an example of two skus of the same product:

{
  "node": {
    "id": "sku_EsZzIlws0rJnTu",
    "image": "https://raw.githubusercontent.com/brxck/gatsby-starter-stripe/master/images/osprey_aether_pro1.jpg",
    "product": {
      "name": "Osprey Aether Pro 70",
      "id": "prod_EsZynTea7jNNWv",
      "images": [ ... ],
      "localFiles": [
        // yep they're here
      ]
    }
  }
},
{
  "node": {
    "id": "sku_EsZzHhPj9lU0ck",
    "image": null,  // this is the only difference
    "product": {
      "name": "Osprey Aether Pro 70",
      "id": "prod_EsZynTea7jNNWv",
      "images": [ ... ],
      "localFiles": null  // but they're not here!
    }
  }
},

I haven't been able to figure out why this is happening yet.

Steps to Reproduce

Create a product with a product image. Create two skus for the product, one with a sku image (with_image) and one without (without_image).

Expected behavior: Both skus should have product images on sku.product.localFiles.

Actual behavior: Only with_image.product.localFiles contains file nodes. without_image.product.localFiles is null.

Reproduces how often: Every time.

Versions

os: Linux
node: v10.11.0
npm: 6.9.0
gatsby: 2.5.12
gatsby-source-stripe: 3.0.2

Allow more control around auth headers for image downloads

I've also been experiencing issues with the image download. My images are hosted in a Google Cloud Platform Storage Bucket (which is public), however the request to grab those images includes an Authorization header which causes Google to send back a 401 (Unauthorized). In order to avoid this it would be helpful to either remove the auth options when fetching the images (after having already fetched the URLs from Stripe) and/or provide a way for users to provide auth details in the options for the plugin if required.

More details

In the gatsby-node file you create an instance of LocalFile with one of the options passed through being:
auth: { htaccess_user: secretKey }
This is then passed through to createRemoteFileNode (gatsby-source-filesystem) which is finally passed through to an npm module called got as one of its options. By passing this auth option got adds in an Authorization header to the HTTP request. This triggers google to send back a 401 because the contents of the header doesn't match anything google knows about.

Issues with downloading files feature

@brxck
Hey! The downloading files integration needs to be looked at a bit, if you have the time. Ran into some issues recently.

(1) For some reason, I can't get "localFiles" to show up anymore for Skus. I'm running the latest version of Gatsby, am getting no console errors, but when I go to query the "localFiles" field in GraphiQL it says the field is unqueryable. I haven't tested other Stripe object types, but thought I'd reach out about Skus to begin with.

{
  allStripeSku {
    edges {
      node {
        id,
        active,
        localFiles,
        product {
          id
        }
      }
    }
  }
}

Here's the contents my gatsby-config.js file in case that's helpful.

module.exports = {
  siteMetadata: {
    title: `Gatsby Default Starter`,
    description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
    author: `@gatsbyjs`,
  },
  plugins: [
    `gatsby-plugin-react-helmet`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `images`,
        path: `${__dirname}/src/images`,
      },
    },
    `gatsby-transformer-sharp`,
    `gatsby-plugin-sharp`,
    {
      resolve: `gatsby-plugin-manifest`,
      options: {
        name: `gatsby-starter-default`,
        short_name: `starter`,
        start_url: `/`,
        background_color: `#663399`,
        theme_color: `#663399`,
        display: `minimal-ui`,
        icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.
      },
    },
    {
    resolve: `gatsby-source-stripe`,
    options: {
      objects: ['Sku'],
      secretKey: 'xxx',
      downloadFiles: true
    }
  }
    // this (optional) plugin enables Progressive Web App + Offline functionality
    // To learn more, visit: https://gatsby.app/offline
    // 'gatsby-plugin-offline',
  ],
}

(2) If you run the plugin with the same exact config as found in the README, it errors out. In LocalFile.js, line 16 seems to error out because "fields" becomes undefined and line 47 errors out because payload.data is undefined. Maybe there needs to be some logic in there to return early if certain things don't exist.

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-stripe`,
    options: {
      objects: ['Balance', 'BalanceTransaction', 'Product', 'ApplicationFee', 'Sku', 'Subscription'],
      secretKey: 'stripe_secret_key_here',
      downloadFiles: true
    }
  }
]

Let me know if you have the bandwidth to look into these things, otherwise I can dig deeper! Thanks!

Support Node 8

Could you change your package.json engines to support the same versions as Gatsby e.g. 6+? Or at least 8+

Many people don't have Node 10 installed still so this plugin will break for them.

Images not downloaded for Price objects

Prerequisites

[X] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug
Images are not downloaded for Price objects even when the downloadFiles is set to true.

To Reproduce
Steps to reproduce the behavior:

  1. Add the source plugin
  2. Set objects to ["Price"]
  3. Set downloadFiles to true.

Expected behavior
Images should also be downloaded for products based on the new Prices API setup.

Versions (please complete the following information):

os: Linux (Pop!_OS 20.04)
node: 14.13.1
npm: 6.14.8
gatsby: 2.12.109
gatsby-source-stripe: 3.1.1

Gatsby config:

Copy the portion of your Gatsby config for this plugin here. Do not include your secretKey.

{
      resolve: `gatsby-source-stripe`,
      options: {
        objects: ["Price"],
        secretKey: process.env.STRIPE_SECRET_KEY,
        downloadFiles: true,
      },
}

Additional context
I can force the images to download by adding case "price" following the same path as case "sku" to both downloadAndAddTo() in the FileDownloadService.js and to extractUrls() in extractUrls.js. I'm not sure if there are any further changes necessary for full integration.

'Unable to find plugin' After 2.20 Update

I just updated to the newest release, but I'm running into this error on develop/build:

error Unable to find plugin "gatsby-source-stripe". Perhaps you need to install its package?

I checked and the plugin is indeed in my node_modules. I've also tried deleting node_modules & package-lock.json and then reinstalling.

Same deal on both projects I tested.

@njosefbeck Looks like the publishing setup changed, maybe something's not quite right?

Versions

os: Linux / Solus 4
node: 10.11.0
npm: 6.5.0
gatsby: 2.5.7
gatsby-source-stripe: 2.2.0

Gatsby 3 touchNode deprecation warning

Prerequisites

[X] Put an X between the brackets on this line if you have done all of the following:

  • Read through the README fully.
  • Ensured you are running Node v.10 or above.
  • Made sure you're using at least Gatsby v.2.0.15.
  • Checked that your issue isn't already filed.

Describe the bug

Using the latest gatsby-source-stripe with Gatsby 3 triggers a deprecation warning:

warning Calling "touchNode" with an object containing the nodeId is deprecated. Please pass the node directly to the function: touchNode(node) "touchNode" was called by gatsby-source-stripe

The touchNode call in question is here.

To Reproduce

Steps to reproduce the behavior:

  1. Start Gatsby 3 development server

Versions (please complete the following information):

gatsby: 3.1.2
gatsby-source-stripe: 3.2.2

Gatsby config:

{
    resolve: `gatsby-source-stripe`,
    options: {
        objects: ["Price"],
        secretKey: process.env.STRIPE_SECRET_KEY,
        downloadFiles: true,
        auth: false,
    },
},

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.