#elBR

1 messages · Page 1 of 1 (latest)

wanton sirenBOT
split seal
#

hi! if you're using the latest API version, you can create an empty draft invoice, and then directly add items to that invoice; you don't have to create them first and then create the invoice and hope they get pulled in.

warm ingot
#

I will give it a try

#

thank you

#

I am trying to create an invoice by providing only subscription_id and I get an error that says that I must provide customer_id

#

why, since it is optional on the documentation api?

split seal
#

the docs say lots of things are optional that aren't, I wouldn't pay too much attention to that

warm ingot
#

can you please give me a test card that goes in fail?

split seal
warm ingot
#

I want to apply a coupon when I update or create a subscription item

#

how can I do that?

split seal
#

what API call are you making exactly?

warm ingot
#

Stripe::SubscriptionItem.update

#

Stripe::SubscriptionItem.create

split seal
#

both of those endpoints take a coupon parameter

#

ah wait no, sorry, misread

#

tell you what, share the exact full code you have

warm ingot
#

I am checking this one

#

here I don't see any coupon

split seal
#

yeah I know, I said I was wrong

#

can you share the complete code you're using and the overall use case for what you're trying to do?

warm ingot
#

So I am creating a subscription item with payment_behavior: "pending_if_incomplete" and proration_behavior: "always_invoice"

#

and I want to also add a coupon code for that specific invoice

#

is there any way for example to update the invoice created by Stripe::SubscriptionItem.update or Stripe::SubscriptionItem.create before being finalized?

#

can you suggest me any workaround?

split seal
#

I need to see your code, I don't understand you

#

you use Subscription:update to change a subscription usually , you don't directly edit the SubscriptionItems

#

and then you can pass a coupon to that Subscription::update endpoint

#

i.e. use the Subscription Update endpoint and pass items, instead of manually updating the SubscriptionItems directly. It's much easier to work wiht.

warm ingot
#

the problem is that if I use updateSubscription, the coupin will be applied to the entire susbcription and will affect the next billing cycle too. I just want to apply that coupon code to the invoice created by prorations and just for that

#

so if I have a subscription that cost $100/month and in the middle of the month I decide to add a new subscription item that cost $50/month and I apply a $10 coupon I want that to be applied only to the prorated invoice created by the $50 item

#

you understand my situation?

split seal
#

ok, then you need to pass the coupon to Invoice:update

#

i.e. update the sub, use proration_behavior: "always_invoice", I think that results in the creation of a draft invoice, and you can edit that invoice to update the coupon field.

warm ingot
#

I don't think the invoice will be draft because as far as I tested with Stripe::SubscriptionItem.update and passing proration_behavior: "always_invoice" I realised that Stripe automatically creates, finalizes and tries to pay the invoice

#

if the invoice would be draft it would be awesome and my problem could be solved. For me the status of the invoice is the problem. If it is draft than I can solve it

#

but I don't think so because Stripe automatically finalizes it

split seal
#

ok then I'm wrong

#

in that case, use proration_behavior:create_prorations instead

#

and then manually create an Invoice in order to pull in those pending items, and you can pass coupon to that.

warm ingot
#

I thought about this other option too but I want to take advantage of payment_behavior: "pending_if_incomplete"

#

and that cannot be used if I don't pass proration_behavior: "always_invoice"

#

this is what one of your colleagues told me yesterday but I am not sure

split seal
#

worth testing it then

#

I have to run, sorry, another colleague will take over

warm ingot
#

ok thnaks

#

I just tried and "payment_behavior: pending_if_incomplete" seem to not have any effect if proration_behavior is "create_prorations"

#

what I can do in this situation?

#

please let me know if we are still connected

sharp summit
#

Hi! I'm taking over this thread.

warm ingot
#

thank you

sharp summit
#

If I understand correctly your goal is to

  • update an invoice with payment_behavior: "pending_if_incomplete"
  • And have a coupon applied to the new invoice that will be created
    Is this correct?
warm ingot
#

yes, correct

sharp summit
#

Got it! Give me a few minutes to run some tests.

warm ingot
#

sure, thank you very much

sharp summit
#

I found a way to make this work:

#
  • first update the subscription to add the coupon to it
  • then do another update with payment_behavior: "pending_if_incomplete" and if it succeeds, the coupon will be applied to the invoice. if the update fails, then you can remove the coupon from the subscription
warm ingot
#

can you please elaborate a bit more

#

so the first time you siggest to update the subscription with payment_behavior: "create_prorations" and a coupon attached

sharp summit
#
  • First update the subscription, but only pass coupon and nothing else. This coupon will automatically be added to the next invoice.
  • Second, update the subscriptino again, this time with payment_behavior: "pending_if_incomplete" and proration_behavior: "always_invoice". This will generate an invoice and the coupon will be applied.
warm ingot
#

but why we cannot merge these two update in just one update with coupon, payment_behaviour and proration_behaviour?

sharp summit
#

I did a few tests but didn't manage to make it work in one API request:
If I try to update the subscription with payment_behavior: "pending_if_incomplete" and proration_behavior: "always_invoice" and coupon: xxx, I get an error.

#

So my solution is not ideal, but it works.