> ## Documentation Index
> Fetch the complete documentation index at: https://docs.en.amplopay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Calculate transaction amount

> How to calculate the amount sent to the API

## Our structure

In this API, the total transaction value, sent in the `amount` field, is composed of the following parts:

* `shippingFee`: transaction shipping fee, in BRL.
* `extraFee`: other fees, such as installment fees, in BRL.
* `discount`: transaction discount, in BRL.
* `products[n].price`: product price, in BRL.
* `products[n].quantity`: product quantity.

## How to calculate

To correctly calculate the total order amount, sum each product price multiplied by its quantity, add shipping, add extra fees, and subtract the discount.

```ts theme={null}
// Product list
const products = [
  { price: 10, quantity: 2 },
  { price: 20, quantity: 1 }
]

// Shipping fee
const shippingFee = 5

// Installment or additional fee
const extraFee = 20

// Discount
const discount = 5

// Total product amount
const totalProducts = products.reduce((acc, product) => {
  return acc + product.price * product.quantity
}, 0)
// Product sum = 40

// Total sale amount paid by the customer.
// This is the value you must send in the amount field.
const amount = totalProducts + shippingFee + extraFee - discount

// Final result: BRL 60.00
```

## Formula

```text theme={null}
amount = sum(products[n].price * products[n].quantity) + shippingFee + extraFee - discount
```
