Valdyr

Invoices

Read the final invoices of a customer, their charges, and the payment that collects each invoice

An invoice bills a customer for one month. It holds the charges of the month and the totals. When a payment provider of the platform collects the invoice, the invoice also holds the state of that payment.

Which invoices the API shows

The API shows only final invoices. The platform makes the invoice of a month again each day while the month is open, so its charges and totals change. When the month becomes final, the invoice stops changing and the API starts to show it.

An invoice is in the API when all of these conditions are true:

  • It comes from the final run of its month
  • The platform bills it
  • It is not hidden

The platform does not bill an invoice that has no charge to bill, or the invoice of a customer that another company invoices.

createdAt is the time when the invoice became final. Until the month becomes final, GET /invoices returns no invoice for it.

The invoice number

The invoiceNumber identifies an invoice. The customer sees this number on the invoice. The number is a string of digits, not a quantity.

Use the number to get one invoice with GET /invoices/{invoiceNumber}, and to get its charges with GET /invoices/{invoiceNumber}/charges. An invoice of a customer that your API key cannot see gives a 404, the same as a number that does not exist.

The month and the period

month is the month that the invoice bills, in the format YYYY-MM. periodFrom and periodUntil are the first and the last day that the charges cover. A customer can pay in advance. Then the invoice also covers days after its month, and periodUntil is in a later month.

Amounts and tax

All amounts are integers in the minor unit of currency, for example cents or öre.

FieldValue
subtotalMinorThe sum of the charges, without tax
taxAmountMinorThe tax of the invoice
totalMinorsubtotalMinor and taxAmountMinor together

The totals are the totals that the platform bills. A brand can calculate a tax rate for each charge. Then each charge has a taxRate and a taxAmountMinor. A charge of the type USAGE gets the tax rate of the customer only when the platform bills the invoice. Thus a USAGE charge has no taxRate and no taxAmountMinor, but the taxAmountMinor of the invoice includes its tax.

A brand can also calculate the tax for each jurisdiction, as in the US. Then the charges carry no tax, and taxRate and taxAmountMinor are absent on each charge. The tax of the invoice comes from its payment. If the payment has no tax, taxAmountMinor and totalMinor are absent on the invoice.

The payment

payment is the record of the payment provider that collects the invoice. The payment gives the status, the due date, the amounts that are due, paid and remaining, and the page where the customer pays.

payment is absent when no payment provider of the platform collects the invoice. For example, an external partner can collect the invoices of a brand. Then the API gives no payment state.

FieldValue
providerThe payment provider, for example BILLOGRAM or STRIPE
statusThe state of the collection
referenceThe number or the payment reference that the provider gives
dueDateThe date when the payment is due
issuedAt, paidAtWhen the provider issued the payment, and when it became paid
amountDueMinorThe amount that the provider collects
amountPaidMinorThe amount that the customer paid
amountRemainingMinorThe amount that is not paid
hostedUrlThe page of the provider where the customer reads and pays
pdfUrlThe PDF of the provider. Absent for BILLOGRAM.
invoiceNumbersEach invoice that the payment collects

The amounts of the payment come from the provider. They can differ from totalMinor, for example when the payment collects more than one invoice.

The invoice is settled when status is PAID or CREDITED. OVERDUE means that the due date is in the past and the payment is not paid.

One payment for more than one invoice

A provider can collect more than one invoice with one payment. Then each of these invoices shows the same payment, and invoiceNumbers gives all of them. The amounts are the amounts of the whole payment, not of one invoice.

Do not add amountDueMinor over the invoices of one payment. Count each payment one time, by its invoiceNumbers.

The charges

GET /invoices/{invoiceNumber}/charges gives the charges of one invoice, in the order of the invoice. The list is paginated, because the invoice of a large business customer can have thousands of charges. The invoice object does not hold its charges.

The charges show the invoice after each correction. A charge that a correction removed is not in the list. A charge with a warning or an error is not in the list, because the platform does not bill it. A charge that an administrator added has the type MANUAL.

FieldValue
chargeIdThe identifier of the charge. It is absent when the charge has none.
typeThe type of the charge, for example SUBSCRIPTION or USAGE
subscriptionIdThe subscription that the charge bills
licenseIdThe license that the charge bills
productOfferingIdThe product offering that the charge bills
startDate, endDateThe first and the last day that the charge covers
oneTimetrue when the charge does not repeat each month
amountMinorThe amount without tax

A charge of the customer has no subscriptionId and no licenseId. chargeId stays the same on each run of the month. Use it as the key of a charge when you store the charges. A charge without chargeId has no key.

List the invoices of a period

  1. Call GET /invoices with fromMonth and toMonth in the format YYYY-MM. The API includes both months.
  2. To get the invoices of some customers only, add a customerId for each customer.
  3. To get some invoices by their number, add an invoiceNumber for each invoice.
  4. If pagination.nextCursor is not null, call again with that value as cursor.

The list gives the newest month first. In one month, the highest invoice number comes first. Without customerId, the list includes all customers that your API key can see.

Access for an end user

The End-User API lists and gets the invoices of the customers that the user manages. It has no operation for the charges of an invoice.

  • Customers: The customer that an invoice bills
  • Subscriptions: The subscription that a charge bills
  • Licenses: The license that a charge bills
  • Payments: The payment intents that collect a prepaid renewal, a topup or an order
  • Tags: A tag that adds a manual charge to each invoice

Next steps