#jerryshen

1 messages · Page 1 of 1 (latest)

elder dockBOT
lusty garnet
#

You can't do that with Prices, but you can create an Invoice Item with an amount that is negative

#

You just have to not specify a Price

unkempt aurora
#

thanks for the quick response. let me try

#

am I still able to specify what product it is?

for example:
invoice_item = stripe.InvoiceItem.create(
customer=i,
invoice=invoice.id,
amount= amount (negative one),
currency=currency,
price_data={
'product':j
}
)

lusty garnet
#

No, because that will create a Price in-line

unkempt aurora
#

so in order to achieve something like this in invoice line item, I cannot use product association, and I can only hardcode in strings in descriptions?

Its weird that I saw in other created invoices, there is negative amount, and there is product/ price level information attached to it

lusty garnet
#

Do you have a Price ID I can look at for the one included in your screenshots?

unkempt aurora
#

price_1MyMZSJ4hxLnVVDuXVLjlhjB

lusty garnet
#

Hmmmm, let me check in with a colleague, I din't. think this was allowed

#

Okay, so apparently unit_amount_decimal on the Price object can be negative

#

But not unit_amount

#

Not sure why

unkempt aurora
#

alright I'll just use that field then 🙂

#

hmm, its still yelling at me:
This value must be greater than or equal to 0 (it currently is '-0.4212e4')

req_KxFGlMoPbz923S

lusty garnet
#

Ah, apologies. That was an error on my end. I created an Invoice item rather than a Price.

#

So I think what is happening under the hood is: when you create an Invoice Item with a negative amount or unit_amount_decimal, it will create a Price on the backend that is negative. So even though we disallow it when directly creating a Price via the API, you can still create a negative Price indirectly via the Invoice Item API

#

Does that make sense?

unkempt aurora
#

I think req_KxFGlMoPbz923S is trying to create a negative Price indirectly via the Invoice Item API (which it doesn't allow) looks like

basically as long as I'm able to achieve in line item

  1. negative amount
  2. being able to link it to an existing product (so that it is easier to manage)

The code that Im using that gave me: req_KxFGlMoPbz923S
invoice_item = stripe.InvoiceItem.create(
customer=i,
invoice=invoice.id,
price_data={
'currency':currency,
'unit_amount_decimal':unit_amount_decimal (negative amount now),
'product':j
}
)

Any suggestions of how to change it? (btw really appreciate your help!

lusty garnet
#

Use this:
invoice_item = stripe.InvoiceItem.create( customer=i, invoice=invoice.id, 'unit_amount_decimal':unit_amount_decimal (negative amount now), )

unkempt aurora
#

and in that case, Im still able to attach a product id?

lusty garnet
#

No

unkempt aurora
#

got it, so I just cannot associate a product to a negative invoice line item, the best way to show information to customers are just do

invoice_item = stripe.InvoiceItem.create(
customer=i,
invoice=invoice.id,
description= "a string that I manage"
'unit_amount_decimal':unit_amount_decimal (negative amount now),
)

right?

lusty garnet
#

Correct