#xror_api

1 messages ¡ Page 1 of 1 (latest)

left fernBOT
#

👋 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.

simple fractal
#

Hi! Looking into this!

pure totem
#

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)

simple fractal