stripe-node
stripe-node copied to clipboard
Typescript `PriceUpdateParams` doesn't respect `currency_options.<currency>` properties on update
Describe the bug
When trying to update a Stripe.Price I'm not able to set the new unit_amount using a "top-level param". The PriceUpdateParams interface only allows for unit_amount to be updated using the currency_options.<currency> structure. However, when following this pattern, I get an error of:
message: 'You are specifying an update to a currency option that matches the top-level currency for this price. Please remove this currency option and update the top-level params instead.',
param: 'currency_options[usd]',
type: 'invalid_request_error',
To Reproduce
- Retrieve price via
stripe.prices.retrieve( price.id ) - Update the price via
stripe.prices.update( price.id, { currency_options: { usd: { unit_amount: <some number> } } } )
Expected behavior
It would be nice to update a price amount directly instead of specifying the detailed currency_options.<currency> object. In the event this isn't possible, I expect to be able to provide the currency_options.<currency> object when updating a price's unit_amount without error.
Code snippets
const price = await stripe.prices.retrieve(product.default_price);
await stripe.prices.update(price.id, {
// No other option but to use currency_options :(
currency_options: {
usd: { unit_amount: price.unit_amount * 10 } // Change the amount
}
})
OS
alpine:3.16
Node version
Node v18.9
Library version
stripe 10.6.0
API version
2022-08-01
Additional context
raw: {
message: 'You are specifying an update to a currency option that matches the top-level currency for this price. Please remove this currency option and update the top-level params instead.',
param: 'currency_options[usd]',
type: 'invalid_request_error',
headers: {
server: 'nginx',
date: 'Tue, 20 Sep 2022 02:56:02 GMT',
'content-type': 'application/json',
'content-length': '291',
connection: 'keep-alive',
'access-control-allow-credentials': 'true',
'access-control-allow-methods': 'GET, POST, HEAD, OPTIONS, DELETE',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required',
'access-control-max-age': '300',
'cache-control': 'no-cache, no-store',
'idempotency-key': '<<REDACTED>>',
'original-request': '<<REDACTED>>',
'request-id': '<<REDACTED>>',
'stripe-should-retry': 'false',
'stripe-version': '2022-08-01',
'strict-transport-security': 'max-age=63072000; includeSubDomains; preload'
},
statusCode: 400,
requestId: '<<REDACTED>>'
},
A price update is not allowed as long as it was in use in any transaction. You have to create a new price from scratch. You can check it from Dashboard UI.
Does setting a price as the default price for a product count as a transaction? I'm creating a product with price details, which auto creates the price object as the default price for the product. Then attempting to update the unit_amount of the new price. No other actions have happened.
Hi @BMO-tech, thanks for the report!
This is actually expected behavior -- unit_amount cannot be updated once it's set. Sorry about that! I'd recommend creating a new price, and optionally archiving the old one if you don't want it anymore.
I'm closing this issue out since it's not a bug with the stripe-node library itself. If you have further integration questions, please reach out to support at https://support.stripe.com/.