#raf1.

1 messages ยท Page 1 of 1 (latest)

serene hazelBOT
haughty crypt
rigid ivy
#

Alright, will try that in a sec. Wll let you know how it went!

haughty crypt
#

Sure!

rigid ivy
#

So I've been trying to do

      await stripe.prices.update(payload.price_id, {
        active: false,
      })
      const product = await stripe.products.del(payload.product_id)

But I get response with message

This price cannot be archived because it is the default price of its product.

serene hazelBOT
haughty crypt
rigid ivy
#

Hmm, can I use any different approach to avoid doing extra update on product?

#

Create product without default_price_data and then attach it along creating price via stripe.prices.create ?

haughty crypt
#

That is not possible I'm afraid

#

You would need to make a call to upadte the default price of the Product

rigid ivy
#

So Product requires default price to be provided?

#

From the docs I see that only name is required, and then default_price_data.currency but default_price_data is not

haughty crypt
rigid ivy
#

I've created a Product without providing any Price data.

Then create Price with product provided

#

Like so

      const stripeProduct = await stripe.products.create({
        name: payload.name,
      })
      const stripePrice = await stripe.prices.create({
        currency: 'eur',
        unit_amount: payload.price,
        product: stripeProduct.id,
      })
haughty crypt
#

That is right, and if you look at that price it would be the default price of that product now.

rigid ivy
#

It is not, default_price is null

prisma violet
#

๐Ÿ‘‹ stepping in here and catching up

#

Yeah what you stated about the default is expected -- it isn't set on creation.

#

I'm not sure the confusion exactly, but you should be able to pass an empty string to unset the default_price if I remember correctly. Otherwise, just don't set it in the first place if you want to archive.

rigid ivy
#

I did it like my last code snippet states, but while trying to delete the product, response for deleting is

This product cannot be deleted because it has one or more user-created prices.

In Stripe dashboard I can see that the Price that is attached to Product - has been archived successfully

prisma violet
#

Sure, as stated you can't delete Products/Prices that have been used.

#

You just archive them

#

That is the extent that you can action them

rigid ivy
#

How does the dashboard deletes it then?

prisma violet
#

You can delete if it is a Product with a Price that has never been used for a transaction

#

Otherwise you can't

rigid ivy
#

It wasn't used at all

I'm working on CRUD for my app that includes Stripe Products, simply created Product via my app, then I want to delete it to test deletion.

prisma violet
#

Okay give me a sec

#

Okay I just checked and it does look like the Dashboard uses a different path here that allows deletion in this case whereas it is blocked via the API.

#

I can file feedback internally to get this ability added to the API, similar to the Dashboard, but for now this isn't possible via the API

#

You are best off archiving for now

rigid ivy
#

alright

#

And shouldnt stripe.products.list() and stripe.prices.list() return non-archived (active) Products / Prices?

#

I should pass active: true param probably. Might be worth to set it as default.

prisma violet
#

Yeah you would need to pass active: true for that behavior as you noted

rigid ivy
#

Alright, that is all for this topic ๐Ÿ˜„ Thank you for your help @haughty crypt and @prisma violet ! Really appreciated ๐Ÿ™‚

#

Solved my issue.