Skip to content

Transaction Amount Calculation

This page covers transaction amount calculation endpoints, including the Amount Calculation API and the deprecated Fee Calculation endpoint.

Amount Calculation


Request Method: POST

URL Endpoint: /api/calculate/amounts

NameTypeRequiredDefaultDescription
processor_idstringtrue
subtotaluinttruenull
amountuintif line_items or products not presentnull
currencystringtrue
payment_methodstringtrueCan be 'card' or 'ach'
transaction_typestringtrueCan be 'verification', 'auth', 'sale', 'void', 'refund', 'credit'
productsarrayif amount or line_items not presentnull
products[].idstringtrue
products[].namestringtrue
products[].descriptionstringfalse
products[].pricestringtrue
products[].local_taxstringfalse
products[].national_taxstringfalse
products[].fixed_amountboolfalsefalse
products[].fixed_qtyboolfalsefalse
products[].unit_of_measurestringfalsenull
line_itemsarrayif amount or products not presentnull
line_items[].idstringtrue
line_items[].statusstringtrueCan be 'paid', 'pending', 'rejected'
line_items[].typestringtrueCan be 'flat' or 'percentage'
line_items[].namestringtrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
line_items[].descriptionstringfalsefalseIf true, the calculated amount will be added to the total amount
line_items[].unit_priceinttrue
line_items[].quantityfloat64true
line_items[].quantity_shippedfloat64false
line_items[].product_codestringfalse
line_items[].commodity_codestringfalse
line_items[].unit_of_measurestringfalse
line_items[].alternate_tax_identifierstringfalse
line_items[].taxableboolfalsefalse
line_items[].local_tax_ratestringfalseFormat is 10.25
line_items[].national_tax_ratestringfalseFormat is 10.25
line_items[].tax_ratestringfalseFormat is 10.25
line_items[].discount_amountuintfalse
line_items[].freight_amountuintfalse
line_items[].discount_ratestringfalse
processor_payment_adjustmentobjectfalsenull
processor_payment_adjustment.typestringtrueCan be 'flat' or 'percentage'
processor_payment_adjustment.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
processor_payment_adjustment.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
shipping_amountobjectfalsenull
shipping_amount.typestringtrueCan be 'flat' or 'percentage'
shipping_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
shipping_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
addon_amountarrayfalsenull
addon_amount[].typestringtrueCan be 'flat' or 'percentage'
addon_amount[].valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
addon_amount[].includeboolfalsefalseIf true, the calculated amount will be added to the total amount
discount_amountarrayfalsenull
discount_amount[].typestringtrueCan be 'flat' or 'percentage'
discount_amount[].valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
discount_amount[].includeboolfalsefalseIf true, the calculated amount will be added to the total amount
duty_amountobjectfalsenull
duty_amount.typestringtrueCan be 'flat' or 'percentage'
duty_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
duty_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
tip_amountobjectfalsenull
tip_amount.typestringtrueCan be 'flat' or 'percentage'
tip_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
tip_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
additional_amountsarrayfalsenull
additional_amounts[].typestringtrueCan be 'flat' or 'percentage'
additional_amounts[].valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
additional_amounts[].includeboolfalsefalseIf true, the calculated amount will be added to the total amount
tax_amountobjectfalsenull
tax_amount.typestringtrueCan be 'flat' or 'percentage'
tax_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
tax_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
national_tax_amountobjectfalsenull
national_tax_amount.typestringtrueCan be 'flat' or 'percentage'
national_tax_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
national_tax_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
local_tax_amountobjectfalsenull
local_tax_amount.typestringtrueCan be 'flat' or 'percentage'
local_tax_amount.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
local_tax_amount.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
service_feeobjectfalsenull
service_fee.typestringtrueCan be 'flat' or 'percentage'
service_fee.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
service_fee.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
surchargeobjectfalsenull
surcharge.typestringtrueCan be 'flat' or 'percentage'
surcharge.valueuinttrueIf type is 'flat', round to 2 decimals (ex. $10.00 should be 1000), if 'percentage' round to 3 (ex. %10.000 should be 10000)
surcharge.includeboolfalsefalseIf true, the calculated amount will be added to the total amount
cc_binstringif surcharge allowednull
countrystringif surcharge allowednull
statestringif surcharge allowednull
flagsobjectfalse
flags.skip_cash_discountboolfalsefalseIf true, skips the cash discount calculation
flags.skip_surchargeboolfalsefalseIf true, skips the cash surcharge calculation
flags.skip_service_feeboolfalsefalseIf true, skips the cash service fee calculation
flags.skip_consumer_choiceboolfalsefalseIf true, skips the cash consumer choice calculation
flags.include_default_tax_to_totalboolfalsenullIf true, and tax has not been overridden, the merchant's default tax amount will be added to the total amount
flags.tax_exemptboolfalsenullIf true, sets the national, local and tax amount fields to 0
flags.processor_surcharge_fallbackboolfalsefalseIf true, processor's surcharge fallback will be available
flags.add_tax_to_totalboolfalsenullIf true, the tax will be added to the total amount
sourcestringfalse

Workflow:

  1. Call the Amount calculation endpoint with the properly filled request
  2. Take the response of the Amount calculation and place it into the Transaction Request into the amounts field and fill the other fields of the request
  3. Submit the transaction with the pre-calculated amounts
sh
  ~ curl -H 'Authorization: API_KEY' -H "Content-Type: application/json" -X POST -d '{
    "processor_id": "<processor id>",
    "amount" : 1000,
    "subtotal" : 1000,
    "currency": "USD",
    "payment_method": "card",
    "transaction_type": "sale"
}' { https://sandbox.koipay.io }/api/calculate/amounts

{
  "status": "success",
  "msg": "success",
  "data": {
    "line_items": null,
    "shipping_amount": null,
    "discount_amount": null,
    "freight_amount": null,
    "addon_amount": null,
    "duty_amount": null,
    "tip_amount": null,
    "additional_amounts": null,
    "tax_amount": 180,
    "national_tax_amount": null,
    "local_tax_amount": null,
    "service_fee": 350,
    "surcharge": null,
    "processor_id": "<processor id>",
    "payment_method": "card",
    "included_amounts": {
      "shipping_amount": null,
      "discount_amount": null,
      "duty_amount": null,
      "tip_amount": null,
      "tax_amount": 180,
      "national_tax_amount": null,
      "local_tax_amount": null,
      "service_fee": 350,
      "surcharge": null
    },
    "subtotal": 1000,
    "amount": 1000,
    "additional_total": 0,
    "total": 1530,
    "features": {
      "surcharge": false,
      "cash_discount": false,
      "dual_pricing": false,
      "dual_pricing_v2": false
    },
    "display": {
      "subtotal": {
        "value": 1000,
        "display": true
      },
      "amount": {
        "value": 1000,
        "display": true
      },
      "shipping": {
        "value": 0,
        "display": false
      },
      "freight": {
        "value": 0,
        "display": false
      },
      "duty": {
        "value": 0,
        "display": false
      },
      "discount": {
        "value": 0,
        "display": false
      },
      "service_fee": {
        "value": 350,
        "display": true
      },
      "surcharge": {
        "value": 0,
        "display": false
      },
      "tax": {
        "value": 180,
        "display": true
      },
      "national_tax": {
        "value": 0,
        "display": false
      },
      "local_tax": {
        "value": 0,
        "display": false
      },
      "tip": {
        "value": 0,
        "display": false
      },
      "total": {
        "value": 1530,
        "display": true
      },
      "consumer_choice": {
        "card": 0,
        "ach": 0,
        "display": false
      }
    },
    "disclaimer": {
      "text": "",
      "html": "",
      "display": false
    }
  }
}

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.koipay.io }/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
  }
}