stripe / stripe-cli

A command-line tool for Stripe
https://stripe.com/docs/stripe-cli
Apache License 2.0
1.57k stars 362 forks source link

Ability to specify an existing product/price/subscription/etc when triggering events #1093

Closed hades200082 closed 1 year ago

hades200082 commented 1 year ago

Problem

I'm planning to use the Stripe pricing table & checkout functionality to allow customers to sign up to my new SaaS product.

In development locally I'm triggering a checkout.session.completed using the CLI. Each time I do this it creates an entirely new set of customer, product and price data (among other things) in my test account.

For my integration, the products that make up the subscription plans need to hold some metadata that will inform my app what tier the user has subscribed to and any quotas/limits that need to be applied.

The test products the CLI creates don't have this information and so I can't use them for testing.

Feature

When calling stripe trigger checkout.session.completed I'd like the ability to set the product/price that should be used for the event.

i.e. stripe trigger checkout.session.completed --product-id "prod_O8v4cuwbwv66Md" --price-id "price_1NMdEWKEw4pGkvDe2Tt0bdmL"

The CLI should then use the specified product/price to create the rest of what it needs for the event.

jsteele-stripe commented 1 year ago

The CLI already has a handful of existing flags that should help you trigger specific events with pre-existing API objects.

For example, using the --override flag with the pre-existing checkout.session.completed fixture to use an existing Price object on your account:

stripe trigger checkout.session.completed --override "checkout_session:line_items[0].price=price_1NMdEWKEw4pGkvDe2Tt0bdmL"

This won't prevent the fixture from creating the unused Price object, for example. If that's something you'd prefer to prevent, then creating and using your own fixture is likely the better option.

Hope this helps!

ericski commented 12 months ago

For anyone else that comes here in the future off a google search, the override should be checkout_session: not checkout_session.

Thanks for that super helpful tip!

jsteele-stripe commented 12 months ago

@ericski Oops, thanks for pointing that out! I just fixed the typo.