#xror_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/1359063350155284521
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi! Looking into this!
Here is my .NET method for the invoice creation (combined):
public async Task InvoiceMeteredUsage(Customer customer)
{
var customerUsages = await GetCustomerDataUsages(customer.Id);
if (customerUsages == null || customerUsages.Count == 0)
{
throw new Exception("No usage to invoice");
}
// Create invoice item from customerUsages, one item per usage
var invoiceItems = new List<InvoiceItemCreateOptions>();
var invoiceItemService = new InvoiceItemService();
foreach (var customerUsage in customerUsages)
{
var invoiceItemOptions = new InvoiceItemCreateOptions
{
Customer = customer.StripeId,
Description = $"Data usage - {customerUsage.MeterDate:yyyy-MM-dd}",
Quantity = customerUsage.UsageCounter,
UnitAmount = 130, // Cents = 1.30 EUR
Currency = "EUR",
TaxBehavior = "exclusive",
};
await invoiceItemService.CreateAsync(invoiceItemOptions);
}
// Create invoice for customer
var invoiceOptions = new InvoiceCreateOptions
{
Customer = customer.StripeId,
CollectionMethod = "charge_automatically",
Description = $"Invoice for data usage - Period: {customer.LastInvoiceDate:yyyy-MM-dd} - {DateTime.Today:yyyy-MM-dd}",
AutoAdvance = true,
AutomaticTax = new InvoiceAutomaticTaxOptions
{
Enabled = true,
},
};
var invoiceService = new InvoiceService();
var invoice = await invoiceService.CreateAsync(invoiceOptions);
if (invoice.Status == "draft")
{
// If invoicing succeeds:
await ResetUsageCounter(customerUsages);
}
}
Here is the request post body of an invoice item:
{
"currency": "EUR",
"customer": "cus_S4Eww8Pyl1SIKD",
"description": "Data usage - 2025-04-04",
"quantity": "2",
"tax_behavior": "exclusive",
"unit_amount": "130"
}
And here is the request post body of the invoice itself:
{
"auto_advance": "True",
"automatic_tax": {
"enabled": "True"
},
"collection_method": "charge_automatically",
"customer": "cus_S4Eww8Pyl1SIKD",
"description": "Invoice for data usage - Period: 2025-03-03 - 2025-04-04"
}
(I don't think it can do any harm posting the customer IDs since it is a test mode-customer)
Thanks for waiting! You should also pass pending_invoice_items_behavior: "include" when creating the Invoice as this parameter defaults to exclude.
https://docs.stripe.com/api/invoices/create#create_invoice-pending_invoice_items_behavior
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.