#karls_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1328468432529920124
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Can you share a subscription id where this happened? Not sure I understand what you mean
Right, here is the pending invoice.
in_1QguXcDOnh5qjbu12sCibfAg
Pending, because it was never charged and was suppose to attach to the subscription invoice. I honestly thought I had this working.
That's a one-off invoice you created for the same customer
Separately from the subscription
Yes
What's unexpected?
I created the invoice with these line-items, but never invoked a Pay, I then created the subscription invoice and expected the draft invoice to be paid at the same time I paid it.
Why would you expect that?
The invoice you created is entirely separate from the subscription
You need to explicitly pay it separately
Isn't there a stripe methodology similar to this that you can have pending items that are attached and paid in a final invoice? Looking for my code sample.
If you add the invoice items before creating the subscription, you can have them added to the subscription's invoice I believe.
^ this
Basically you just don't want to create the invoice separately if you want the invoice items on the subscription invoice
Or you can create the subscription and the one time invoice items separately with the add_invoice_items parameter https://docs.stripe.com/api/subscriptions/create#create_subscription-add_invoice_items
Yes, AutoAdvance = true, when I'm creating my invoice.
Here it looks like you created the invoice just before the subscription. Basically what happens is that the invoice items exist on the customer until some invoice claims them while being created, if you hadn't created that other invoice, I think the subscription's first invoice would have picked them up
I've done it this way before, adding invoice items to the subscription creation. I was hoping to exploit more feature from the invoice as there are some limitations to the add line item request on the subscription class.
So create the subscription invoice first, then create the line-items 2nd (resulting in a draft invoice) and 3rd, Pay the subscription invoice and all line items from draft will be included in this final invoice?
No I don't think that would work. The first invoice on a subscription will finalize immediately if collection_method is set to charge_automatically and you can't invoke invoice payment yourself if you use send_invoice for collection method.
So it sounds like you want to:
- Create invoice items on the Customer
- Create a subscription with
collection_method=charge_automatically, this creates an invoice that picks up the invoice items - The invoice should immediately finalize and attempt to charge the customer
Yes, that sounds right. I think I'm doing that. Aren't I?
9BA6C037-DRAFT, is assigned to same customer as the sub_1QguXfDOnh5qjbu12jOdpXLO, customer
In the example that you sent earlier, you had just created a separate one-off invoice three seconds earlier
https://dashboard.stripe.com/test/logs/req_1u0LmkADUCPFEL
OK, your pseudo code above, step 1, Create invoice items on the Customer. I'm confused, isn't that what I did?
What is a "one-off" invoice, vs. creating invoice items on the customer?
You mean, create invoice-tems without creating an actuall invoice?
The request that I linked to is what I am talking about. You had already created invoice items, but that call told us to create an invoice that isn't linked to a subscription. That invoice picked up the existing invoice items that you had already created
If you remove the call to /v1/invoices but keep your calls to /v1/invioceitems you should have the behavior that you are going for
OK, I'm going to mess with this. Leave this open please. I'll be back maybe with questions.
Stepping in for my teammate. We typically leave threads open for ~20 mins. If you don't have any new questions within that time frame, I'll archive the thread. You can still return to #help should any new questions come up
All right. I'm testing now..
OK, I see that I am adding promo and discount codes to the original invoice I created. I guess I can't add promo and discount codes without an invoice to attachem them to, or do I have to attach them to the invoice which is ultimately my subscription invoie?
You can add promo/coupons (via the discounts hash) when creating the Subscription: https://docs.stripe.com/api/subscriptions/create#create_subscription-discounts
So you can still work with the pseudo code above:
- Create invoice items on the Customer
- Create a subscription with collection_method=charge_automatically and add any discounts. This creates an invoice that picks up the invoice items
- The invoice should immediately finalize and attempt to charge the customer
OK. The logic in my code was: Create and invoice, attach line items, apply promo and discounts, leave it as a draft, pay everything in the next invoice, the subscription invoice.
That doesn't work??
You shouldn't create an Invoice directly. Creating the Subscription will automatically create an Invoice and pull in any pending invoice items for a customer
OK, it is just that I tested this a couple of weeks earlier and I thought it was working.. I will rework my code.
Question: if you are just creating Items, so now Invoice, how is this associated with a customer?
Nevermind, I see a customer id on the invoice item create request.
You'll create items for a specific customer then create a Subscription for that same customer
Yep, testing new code now...
Think I got it, although I need to improve my line item descriptions: in_1QgwE7DOnh5qjbu1pVWIs09t
Yep, this looks like you're on the right track. That Invoice was created automatically after you created a Subscription for this customer
OK, onto the subscription now. I need to add both promo code(one) and discount(1-many)
If you know these values up front, these should be added to the discounts hash when creating the Subscription: https://docs.stripe.com/api/subscriptions/create#create_subscription-discounts
@abstract shadow do you still need help? I can close this thread if you're done testing for the day. You can always return to #help if you have any more questions.
No worries!