Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Stripe plugin sync stripeProperty options

default discord avatar
philiposaurus2 years ago
5

I'd like to use the stripe plugin to sync the price of products between the payload ui and stripe. So that you can update the price of a product using the payload ui. The sync option in the stripe plugin looks to be able to do it

https://github.com/payloadcms/plugin-stripe#sync

- but I am getting this error:


Failed to create new 'products' resource in Stripe: Received unknown parameter: price at new ExtendableError

My sync config looks like:


      sync: [
        {
          collection: 'products',
          stripeResourceType: 'products',
          stripeResourceTypeSingular: 'product',
          fields: [
            {
              fieldPath: 'price',
              stripeProperty: 'price',
            },
          ],
        },
      ],

It is not liking the 'price' value there on the stripeProperty. It is typed to be string, what am I able to put in here and how do I know?

  • default discord avatar
    allannnc2 years ago

    You actually want to look at the

    default_price

    linked to a

    product

    https://stripe.com/docs/api/products/object#product_object-default_price
  • discord user avatar
    jacobsfletch
    last year

    Creating prices through the Stripe API is a bit convoluted with all of its options and validations. In an effort to avoid recreating the Stripe dashboard within Payload, we simply send the user to Stripe for that portion of the workflow. That being said, there likely is a way to get prices to sync as expected if you wanted to explore that more, but the level of complexity here is likely out of the scope for the the core plugin— unless this can be done elegantly.



    For this reason, the e-commerce template syncs the price from Stripe as a raw JSON field in Payload using an

    afterChange

    hook. This way the front-end never has to make requests directly to Stripe, even for prices. Check it out

    https://github.com/payloadcms/template-ecommerce/blob/main/src/collections/Products/hooks/beforeChange.ts

    The plugin does auto-generate a link to Stripe, which will allow you to create your products first

    without

    a price, then navigate to Stripe for the remainder of the process. Stripe webhooks can be setup to catch and sync those updates back to Payload, like this:

    https://github.com/payloadcms/template-ecommerce/blob/main/src/stripe/webhooks/priceUpdated.ts
  • default discord avatar
    philiposauruslast year

    Thanks for coming back on this and explaining the setup/goal of the plugin. I realised this is not fully aligned with my project goal. The stripe pricing model is too restrictive for me, I need different prices based on different user roles, as well as having people in the payload admin panel that should manage products that are not supposed/allowed to go into stripe. Therefore I moved to managing everything (prices and so forth) inside of payload. Then I altered the checkout endpoint to create a PaymentIntent in stripe and just have people checkout using the returned token.


    Do you see issues with this approach (other than kind of having recreated the stripe admin panel)?

  • discord user avatar
    jacobsfletch
    last year
    I need different prices based on different user roles

    You could still achieve this by defining multiple prices in Stripe for each product and syncing them all to Payload, then conditionally returning the correct price after reading the user's role from within a Payload hook. If you want to restrict users from interfacing with Stripe, you could simply hide the auto-generated link based on user roles and also not provide them with your Stripe login credentials.

  • default discord avatar
    philiposauruslast year

    Interesting, wasn't aware of this feature in Stripe. The issue is that users inside of Payload are managing product prices but should not go into Stripe.


    Is there a benefit I am missing by only doing payment intents and not doing any product management in Stripe?

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.