Invoice Discount Calculator

Invoice Discount Calculator API

Finance

Find the discount that brings an invoice to a target grand total, after taxes and fees. Add line items, fees and taxes, enter the total you need, and get the exact % and amount.

Authentication

Send your API key as a Bearer token in the Authorization header (Authorization: Bearer YOUR_API_KEY), or in an X-API-Key header.

Rate Limit

120 requests per minute

Endpoints

1 endpoint available

Overview

Works backwards from the grand total you need. Send the line items, any fees and taxes, and a targetTotal. It returns the discount, as an amount and as a percentage of the discountable items, and the full invoice breakdown.

How the invoice is built

  • Each line is quantity times unit price, rounded to the cent. The discount comes off the items marked discountable (default true), before tax. Mark delivery or fixed charges as not discountable.
  • The share of the discount that comes off taxable items lowers the taxable amount.
  • Fees are fixed (a dollar amount), percent-subtotal (a percentage of the subtotal after the discount) or percent-total (a percentage of the total after fees and tax, like a card surcharge, never taxed). Fees are taxable by default, except percent-total.
  • Taxes are percentages. A compound tax is charged on the taxable amount plus the taxes listed before it. Send taxes or a taxPreset, not both. Presets: none, gst, hst-on, hst-ns, hst-15, qc, bc, mb, sk, vat-20. Rates change, so check them.
  • Every amount is rounded to the cent the way an invoice shows it, so the numbers match invoicing software.

Status

  • exact: a discount gives exactly the target. discountPercent has just enough decimals that applying it to the discountable total and rounding to the cent gives back discountAmount.
  • nearest: rounding makes the exact total impossible. You get the smallest discount at or under the target, and nextSmallerDiscount, which lands just over it.
  • no-discount-needed: the invoice is already at or under the target (increaseNeeded says by how much).
  • impossible: even a full discount of every discountable item leaves the total above the target (lowestPossibleTotal).
  • nothing-discountable: no item can be discounted.

Limits: 200 items, 20 fees, 10 taxes. Quantity up to 100,000 and unit price up to 1,000,000.

Endpoints

POST
https://opentools.ca/api/v1/tools/invoice-discount-calculator
Find the discount that brings an invoice to a target grand total

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
items
array
Required
Line items, 1 to 200.
items[].description
string
OptionalDescription, for your own reference.
items[].quantity
number
Required
Quantity, 0 to 100,000.
items[].unitPrice
number
Required
Unit price in dollars, 0 to 1,000,000.
items[].taxable
boolean
OptionalWhether tax applies to this item.Default: true
items[].discountable
boolean
OptionalWhether the discount may come off this item.Default: true
fees
array
OptionalFees, up to 20.Default: []
fees[].name
string
OptionalFee name.Default: Fee
fees[].kind
string
Enum: fixed, percent-subtotal, percent-total
OptionalHow the fee is worked out.Default: fixed
fees[].value
number
Required
Dollars for a fixed fee, a percentage (3 for 3%) for the others.
fees[].taxable
boolean
OptionalWhether tax applies to this fee. Ignored for percent-total.Default: true
taxes
array
OptionalTaxes, up to 10.
taxes[].name
string
OptionalTax name.Default: Tax
taxes[].rate
number
Required
Percentage, 0 to 100.
taxes[].compound
boolean
OptionalCharge this tax on the taxable amount plus the taxes before it.Default: false
taxPreset
string
Enum: none, gst, hst-on, hst-ns, hst-15, qc, bc, mb, sk, vat-20
OptionalA ready-made set of taxes. Use instead of taxes.
targetTotal
number
Required
The grand total you want, in dollars.

Response Example

{
  "success": true,
  "status": "exact",
  "targetTotal": 1000,
  "withoutDiscount": {
    "itemsTotal": 1190,
    "discountableTotal": 1150,
    "discount": 0,
    "subtotal": 1190,
    "fees": [],
    "taxableAmount": 1190,
    "taxes": [
      {
        "name": "HST",
        "rate": 13,
        "amount": 154.7
      }
    ],
    "surcharges": [],
    "total": 1344.7
  },
  "discountAmount": 305.04,
  "discountPercent": 26.525,
  "invoice": {
    "itemsTotal": 1190,
    "discountableTotal": 1150,
    "discount": 305.04,
    "subtotal": 884.96,
    "fees": [],
    "taxableAmount": 884.96,
    "taxes": [
      {
        "name": "HST",
        "rate": 13,
        "amount": 115.04
      }
    ],
    "surcharges": [],
    "total": 1000
  }
}

Error Codes

400
Bad Request - A field is missing or invalid. The response lists each problem.
401
Unauthorized - Missing or invalid API key
403
Forbidden - The API key is inactive or expired, or the request IP is not allowed
405
Method Not Allowed - This endpoint accepts POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error

Code Examples

# Discount an invoice down to $1,000
curl -X POST https://opentools.ca/api/v1/tools/invoice-discount-calculator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "items": [
    {
      "description": "Design work",
      "quantity": 10,
      "unitPrice": 85
    },
    {
      "description": "Printing",
      "quantity": 250,
      "unitPrice": 1.2
    },
    {
      "description": "Delivery",
      "quantity": 1,
      "unitPrice": 40,
      "discountable": false
    }
  ],
  "taxes": [
    {
      "name": "HST",
      "rate": 13
    }
  ],
  "targetTotal": 1000
}'

Ready to get started?

Create an API key to start using the Invoice Discount Calculator API.

Rather use it in your browser? Open the Invoice Discount Calculator