Nabat Farsi
Nabat Farsi

Reputation: 982

updating Stripe Price object

I had a question that seems to be easy but apparently is not working. I need to update the price for a Price object, but the following does not work. It gives the error that unit_amount is not known, although we use it to define the Price object initially:

stripe.Price.modify(
    "price_1Hkb5FHdAaIdH7ntvOhZOyFK",
    unit_amount=10,
)

Upvotes: 6

Views: 8152

Answers (1)

koopajah
koopajah

Reputation: 25552

You can not modify the price of a Price in the API. This is not something that is supported as there's no corresponding parameter on the API.

If you want to change the amount associated with a Price, you would create a new Price object and start using it instead. You could also make the old one inactive for example.

Another powerful feature of Stripe's API is the lookup_key on Price (doc). This lets you define a custom alias for your Price in your code. That way instead of hardcoding the price id price_123 in your code and having to update it to use price_abcd, you can transfer the old lookup key from the old price to the new one and have your code seamlessly start using the new one automatically. The idea is that you either cache the Price id associated with a lookup key based on webhooks for example or use the List Prices API and the lookup_keys parameter to quickly find the latest price id associated with a given lookup key!

Upvotes: 15

Related Questions