#elBR
1 messages · Page 1 of 1 (latest)
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.
if you're not using the latest version you can use https://stripe.com/docs/api/invoices/create#create_invoice-pending_invoice_items_behavior with exclude to opt into that behaviour
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?
the docs say lots of things are optional that aren't, I wouldn't pay too much attention to that
can you please give me a test card that goes in fail?
depends why you mean but I usually use the "decline after attaching" 4000000000000341 one at https://stripe.com/docs/testing#declined-payments in the second table
I want to apply a coupon when I update or create a subscription item
how can I do that?
what API call are you making exactly?
both of those endpoints take a coupon parameter
ah wait no, sorry, misread
tell you what, share the exact full code you have
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I am checking this one
here I don't see any coupon
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?
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?
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
I suggest using this guide https://stripe.com/docs/billing/subscriptions/upgrade-downgrade#changing
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.
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?
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.
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
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.
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
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
Hi! I'm taking over this thread.
thank you
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?
yes, correct
Got it! Give me a few minutes to run some tests.
sure, thank you very much
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
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
- First update the subscription, but only pass
couponand 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"andproration_behavior: "always_invoice". This will generate an invoice and the coupon will be applied.
but why we cannot merge these two update in just one update with coupon, payment_behaviour and proration_behaviour?