#fiery_hare_68246
1 messages · Page 1 of 1 (latest)
Hi there, so you want to build a usage based subscription and only create an invoice when the amount reaches a threshold ?
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 was using the code below but it does seems to work well.
var pendingInvoiceItems = _stripeAdapter.InvoiceItemListAsync(new Stripe.InvoiceItemListOptions
{
Customer = subscriber.GatewayCustomerId
}).ToList().Where(i => i.InvoiceId == null);
var pendingInvoiceItemsDict = pendingInvoiceItems.ToDictionary(pii => pii.Id);
var upcomingPreview = await _stripeAdapter.InvoiceUpcomingAsync(new Stripe.UpcomingInvoiceOptions
{
Customer = subscriber.GatewayCustomerId,
Subscription = subscriber.GatewaySubscriptionId,
SubscriptionItems = subItemOptions
});
var itemsForInvoice = upcomingPreview.Lines?.Data?
.Where(i => pendingInvoiceItemsDict.ContainsKey(i.Id) || (i.Plan.Id == subItemOptions[0]?.Plan && i.Proration));
var invoiceAmount = itemsForInvoice?.Sum(i => i.Amount) ?? 0;
var invoiceNow = invoiceAmount >= prorateThreshold;
Thanks
You code is about retrieving the upcoming invoice, is this what you want to achieve?
No, I think your suggestion works. What i want to achive is to mutiple all existing subscription and set a billingthreashold mount that will be reached before inovice is generated and send to customer and after which it will be reseted. The problem I am trying to solve is a situation that customer gets invoice for any quanity update in a subscription and most of the time amount are less than a dollar. I will want the amount to get to $5 before the customer will be invoice. And if the customer stops at $4 without any other update, Then the $4 will be Proration and add to customer next bill invoice
Just to clarify, so you want to set up a threshold across multiple subscriptions?
Yes, I have many customer with subscriptions and I want to set the threshold for new subscriptions and existing ones.
I'm afraid you can set a threshold on a subscription, but you can't set a threshold across multiple subscriptions.
each subscription is unique to the customer. So I can only set the threshold on 1 subscription only even when I have 200 customer with 200 different subscriptions
A customer can have many subscriptions. It's just that you can only set a threshold on a subscription.