Skip to content

Transaction Amount Calculation

Calculate accurate transaction totals including taxes, fees, surcharges, discounts, and shipping before submitting your transaction. This API handles complex fee programs, processor-specific calculations, and ensures your transaction amounts are correct.

Request Method: POST
URL Endpoint: /api/calculate/amounts

Basic

You must provide one of the following for amount input: amount, line_items, or products. If line_items and products are both empty/null, then subtotal is also required.

NameTypeDefaultRequiredDescription
amountuintnullif line_items or products not presentBase amount in cents (e.g., 1000 = $10.00). Required if not using products or line_items
subtotaluintnullif line_items and products are emptySubtotal amount in cents. Required if line_items and products are both empty/null
processor_idstringProcessor to use for calculation
currencystringISO 4217 currency code (e.g., "USD")
payment_methodstringPayment method: card, ach, etc.
transaction_typestringTransaction type: verification, auth, sale, void, refund, credit
customer_idstringCustomer ID (if using stored customer data)
payment_method_idstringConditional*Payment method ID. Required if customer_id and payment_method are both set
tokenstringPayment token (alternative to customer_id)
cc_binstringCard number digits for surcharge/fee calculation. Minimum 6 digits required. For most accurate results pass the full card number
countrystringCountry code for tax calculation
statestringState code for tax calculation
sourcestringSource identifier for tracking

Card Number for cc_bin

The cc_bin field requires a minimum of 6 digits, but for the most accurate results—especially when determining if a card is surchargeable—you should pass the full card number. The system will extract the necessary BIN information while using the complete number for precise fee and surcharge calculations.

Conditional Requirements

  • Required: You must provide one of: amount, line_items, or products
  • If line_items and products are both empty/null, then subtotal is also required
  • If customer_id is set AND payment_method is set, then payment_method_id is required
  • If customer_id is set AND payment_method_id is set, then payment_method is required

Credit Card with BIN

Calculate amounts for a credit card transaction with BIN for surcharge calculation:

Customer with Payment Method ID

Calculate amounts using a stored customer and specific payment method:

Using Customer ID

When using customer_id, the endpoint automatically:

  • Retrieves the customer's default payment method (if payment_method_id is not provided)
  • Sets the payment method type (card or ach)
  • Extracts BIN from stored card (if applicable)
  • Uses customer's default billing address for tax calculation (country and state)

Products

Use products array to calculate amounts from product definitions. Alternative to providing amount directly.

NameTypeDefaultRequiredDescription
productsarraynullif amount or line_items not presentArray of product objects
products[].idstringRequiredProduct ID
products[].namestringRequiredProduct name
products[].pricestringRequiredProduct price
products[].descriptionstringProduct description
products[].local_taxstringLocal tax amount
products[].national_taxstringNational tax amount
products[].fixed_amountboolfalseWhether amount is fixed
products[].fixed_qtyboolfalseWhether quantity is fixed
products[].unit_of_measurestringnullUnit of measure (e.g., "each", "lb")

Line Items

Use line items for Level 3 data transactions with detailed item information.

NameTypeDefaultRequiredDescription
line_itemsarraynullif amount or products not presentArray of line item objects
line_items[].idstringRequiredLine item identifier
line_items[].statusstringRequiredStatus: paid, pending, rejected
line_items[].typestringRequiredType: flat or percentage
line_items[].namestringRequiredItem name
line_items[].descriptionstringItem description
line_items[].unit_priceintRequiredUnit price in cents
line_items[].quantityfloat64RequiredQuantity
line_items[].quantity_shippedfloat64Quantity shipped
line_items[].product_codestringProduct code
line_items[].commodity_codestringCommodity code
line_items[].unit_of_measurestringUnit of measure
line_items[].alternate_tax_identifierstringAlternate tax identifier
line_items[].taxableboolfalseWhether item is taxable
line_items[].local_tax_ratestringLocal tax rate (format: 10.25)
line_items[].national_tax_ratestringNational tax rate (format: 10.25)
line_items[].tax_ratestringTax rate (format: 10.25)
line_items[].discount_amountuintDiscount amount in cents
line_items[].freight_amountuintFreight amount in cents
line_items[].discount_ratestringDiscount rate

Taxes

Configure tax amounts. All tax objects support type (flat or percentage), value, and include (adds to total).

NameTypeDefaultRequiredDescription
tax_amountobjectnullGeneral tax amount
national_tax_amountobjectnullNational tax amount
local_tax_amountobjectnullLocal tax amount

Tax Object Fields:

  • type (string, required): flat or percentage
  • value (uint, required): Amount in cents (flat) or rate (percentage, e.g., 10000 = 10.000%)
  • include (bool, default: false): If true, adds calculated amount to total

Fees

Configure service fees, surcharges, and payment adjustments.

NameTypeDefaultRequiredDescription
service_feeobjectnullService fee amount
surchargeobjectnullSurcharge amount
processor_payment_adjustmentobjectnullProcessor-specific payment adjustment

Fee Object Fields:

  • type (string, required): flat or percentage
  • value (uint, required): Amount in cents (flat) or rate (percentage, e.g., 10000 = 10.000%)
  • include (bool, default: false): If true, adds calculated amount to total

Shipping & Other Amounts

Configure shipping, discounts, add-ons, duty, tips, and additional amounts.

NameTypeDefaultRequiredDescription
shipping_amountobjectnullShipping cost
discount_amountarraynullDiscount amounts
addon_amountarraynullAdd-on amounts
duty_amountobjectnullDuty amount
tip_amountobjectnullTip amount
additional_amountsarraynullAdditional custom amounts

Amount Object Fields:

  • type (string, required): flat or percentage
  • value (uint, required): Amount in cents (flat) or rate (percentage, e.g., 10000 = 10.000%)
  • include (bool, default: false): If true, adds calculated amount to total

Payment Details

Fields for payment method identification and location-based calculations.

NameTypeDefaultRequiredDescription
cc_binstringFirst 6-11 digits of card number (BIN) for surcharge/fee calculation
countrystringCountry code for tax calculation
statestringState code for tax calculation
cc_typestringCard type (e.g., "visa", "mastercard")

Flags

Control calculation behavior and fee program processing.

NameTypeDefaultRequiredDescription
flags.skip_cash_discountboolfalseSkip cash discount calculation
flags.skip_surchargeboolfalseSkip surcharge calculation
flags.skip_service_feeboolfalseSkip service fee calculation
flags.skip_consumer_choiceboolfalseSkip consumer choice calculation
flags.include_default_tax_to_totalboolnullInclude merchant's default tax in total if tax not overridden
flags.tax_exemptboolnullSet all tax amounts to 0
flags.processor_surcharge_fallbackboolfalseEnable processor's surcharge fallback
flags.add_tax_to_totalboolnullAdd tax to total amount

Use the data object from the response in your transaction request's amounts field.

Fee Calculation

DEPRECATED - Use Amount Calculation

Details

Using this endpoint will calculate any applicable fees that should be applied to the transaction. This includes Surcharge, Cash Discount Fees and Payment Adjustment, if applicable.

Request Method: POST

URL Endpoint: /api/lookup/fees

NameTypeRequiredDescription
typestringyesType of request, "integrations"
statestringnoBilling address state
binstringno6 - 19 digits of a card
customer_idstringnoCustomer ID
payment_idstringnoPayment method ID for a customer
payment_methodstringyesThe method of payment, i.e 'card' or 'ach'
base_amountuintyesAmount in lowest form of currency. $1.00 = 100
json
➜  ~ curl -H 'Authorization: API_KEY' -H "Content-Type: application/json" -X POST -d '{
        "type": "integrations",
        "type_id":"",
        "state": "IL",
        "bin": "517246700",
        "payment_method": "card",
        "base_amount": 1000
}' { https://sandbox.gosparrowone.com }/api/api/lookup/fees

{
  "status": "success",
  "msg": "success",
  "data": {
    "service_fee": 0,
    "payment_adjustment": {
      "value": 0,
      "type": ""
    },
    "requested_amount": 1350,
    "discount_amount": null,
    "surcharge": 350
  }
}