# Price lists

> Different prices per customer: wholesale, distributor or promotion lists, with quantity and per-box tiers, and customer groups with their list, discount, credit and minimum order.

A price list says how much a certain kind of customer pays. It starts from the catalog price (or another list), lowers or raises it by a percentage and rounds it; on top, each product can have its own price or a discount, per package (a box of 12) and from a certain quantity, which are its wholesale tiers. A customer group gathers those who pay the same: their list, their discount on each line item, their credit days and their minimum order. They're the same as **Ventas › Listas de precios** in the app.

Which list each customer has: their own (the customer's `price_list`), otherwise their group's, otherwise the one with `is_default`, and if there's none, the catalog price. A list outside its dates (`starts_on`, `ends_on`) doesn't count. The customer's discount, otherwise their group's, goes as each line item's discount on the CFDI.

## Create a list

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/price_lists \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Mayoreo", "adjust_percent": -10, "round_to": 0.5, "items": [{ "product": "prd_OufpKqnrvx9p1", "min_quantity": 24, "unit_price": 80 }] }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const { data } = await fiscalisto.priceLists.create({
  name: "Mayoreo",
  adjust_percent: -10,
  round_to: 0.5,
  items: [
    {
      product: "prd_OufpKqnrvx9p1",
      min_quantity: 24,
      unit_price: 80,
    },
  ],
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

data = fiscalisto.price_lists.create({
    "name": "Mayoreo",
    "adjust_percent": -10,
    "round_to": 0.5,
    "items": [
        {
            "product": "prd_OufpKqnrvx9p1",
            "min_quantity": 24,
            "unit_price": 80,
        },
    ],
})["data"]
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$data = $fiscalisto->priceLists->create([
    'name' => 'Mayoreo',
    'adjust_percent' => -10,
    'round_to' => 0.5,
    'items' => [
        [
            'product' => 'prd_OufpKqnrvx9p1',
            'min_quantity' => 24,
            'unit_price' => 80,
        ],
    ],
])['data'];
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	priceList, err := client.PriceLists.Create(ctx, &fiscalisto.CreatePriceListParams{
		Name:          "Mayoreo",
		AdjustPercent: fiscalisto.Float64(-10),
		RoundTo:       fiscalisto.Float64(0.5),
		Items: []fiscalisto.CreatePriceListParamsItem{
			{
				Product:     "prd_OufpKqnrvx9p1",
				MinQuantity: fiscalisto.Float64(24),
				UnitPrice:   fiscalisto.Float64(80),
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(priceList.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreatePriceListParams;
import com.fiscalisto.model.CreatePriceListParamsItem;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var priceList = fiscalisto.priceLists().create(new CreatePriceListParams()
        .setName("Mayoreo")
        .setAdjustPercent(-10)
        .setRoundTo(0.5)
        .setItems(List.of(
                new CreatePriceListParamsItem()
                        .setProduct("prd_OufpKqnrvx9p1")
                        .setMinQuantity(24)
                        .setUnitPrice(80)
        )));
System.out.println(priceList.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var priceList = await fiscalisto.PriceLists.CreateAsync(new CreatePriceListParams
{
    Name = "Mayoreo",
    AdjustPercent = -10,
    RoundTo = 0.5m,
    Items = new()
    {
        new()
        {
            Product = "prd_OufpKqnrvx9p1",
            MinQuantity = 24,
            UnitPrice = 80,
        },
    },
});
```

`adjust_percent` moves the price it starts from (−10 lowers it 10 %). Each row of `items` carries `unit_price` (its unit price before IVA) or `discount_percent` (a discount on the list's price), not both. Several rows of the same product with different `min_quantity` are its tiers: «24 or more at $80», «100 or more at $75». With `unit` (a package of the product, like a box) the price is per box; without its own box price, the box is worth its pieces, and 2 boxes of 12 already reach the «24 or more» tier. Sending `items` in `POST /v1/price_lists/{id}` replaces all the ones it had.

## Customer groups

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/customer_groups \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Mayoristas", "price_list": "prl_OufpKqnrvx9p1", "discount_percent": 3, "credit_days": 30, "min_order": 5000 }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const customerGroup = await fiscalisto.customerGroups.create({
  name: "Mayoristas",
  price_list: "prl_OufpKqnrvx9p1",
  discount_percent: 3,
  credit_days: 30,
  min_order: 5000,
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

customer_group = fiscalisto.customer_groups.create({
    "name": "Mayoristas",
    "price_list": "prl_OufpKqnrvx9p1",
    "discount_percent": 3,
    "credit_days": 30,
    "min_order": 5000,
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$customerGroup = $fiscalisto->customerGroups->create([
    'name' => 'Mayoristas',
    'price_list' => 'prl_OufpKqnrvx9p1',
    'discount_percent' => 3,
    'credit_days' => 30,
    'min_order' => 5000,
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	customerGroup, err := client.CustomerGroups.Create(ctx, &fiscalisto.CreateCustomerGroupParams{
		Name:            "Mayoristas",
		PriceList:       fiscalisto.String("prl_OufpKqnrvx9p1"),
		DiscountPercent: fiscalisto.Float64(3),
		CreditDays:      fiscalisto.Int64(30),
		MinOrder:        fiscalisto.Float64(5000),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(customerGroup.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.CreateCustomerGroupParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var customerGroup = fiscalisto.customerGroups().create(new CreateCustomerGroupParams()
        .setName("Mayoristas")
        .setPriceList("prl_OufpKqnrvx9p1")
        .setDiscountPercent(3)
        .setCreditDays(30)
        .setMinOrder(5000));
System.out.println(customerGroup.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var customerGroup = await fiscalisto.CustomerGroups.CreateAsync(new CreateCustomerGroupParams
{
    Name = "Mayoristas",
    PriceList = "prl_OufpKqnrvx9p1",
    DiscountPercent = 3,
    CreditDays = 30,
    MinOrder = 5000,
});
```

A customer joins a group, or takes their own list or discount, with `POST /v1/customers/{id}`:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/customers/cus_OufpKqnrvx9p1 \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "group": "cgr_OufpKqnrvx9p1" }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const customer = await fiscalisto.customers.update("cus_OufpKqnrvx9p1", { group: "cgr_OufpKqnrvx9p1" });
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

customer = fiscalisto.customers.update("cus_OufpKqnrvx9p1", {"group": "cgr_OufpKqnrvx9p1"})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$customer = $fiscalisto->customers->update('cus_OufpKqnrvx9p1', ['group' => 'cgr_OufpKqnrvx9p1']);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	customer, err := client.Customers.Update(ctx, "cus_OufpKqnrvx9p1", &fiscalisto.UpdateCustomerParams{
		Group: fiscalisto.String("cgr_OufpKqnrvx9p1"),
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(customer.ID)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.UpdateCustomerParams;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var customer = fiscalisto.customers().update("cus_OufpKqnrvx9p1", new UpdateCustomerParams().setGroup("cgr_OufpKqnrvx9p1"));
System.out.println(customer.getId());
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var customer = await fiscalisto.Customers.UpdateAsync("cus_OufpKqnrvx9p1", new UpdateCustomerParams { Group = "cgr_OufpKqnrvx9p1" });
```

The customer's `price_list` and `discount_percent` win over their group's; set to `null` they go back to the group's. `min_order` is the minimum order before IVA to order from the Portal del cliente (customer portal), and `portal_ordering: false` doesn't let them order from there. `portal_changes` says until when they change or cancel from their portal an order they sent there: `none`, `until_confirmed` (until you confirm it; the default) or `until_delivered` (until something is delivered or invoiced). Their delivery terms decide which days the portal offers: `delivery_days` (0 Sunday to 6 Saturday; `null`, any day), `cutoff_hour` (an order after that Mexico City hour counts from the next day) and `prep_days` (days to prepare it). The portal only lets them pick those days, the earliest first.

## What a customer pays

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/prices \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "customer": "cus_OufpKqnrvx9p1", "items": [{ "product": "prd_OufpKqnrvx9p1", "quantity": 10 }] }'
```

```ts tab="TypeScript"
import { Fiscalisto } from "fiscalisto";

// The key comes from FISCALISTO_API_KEY.
const fiscalisto = new Fiscalisto();

const priceQuote = await fiscalisto.prices.quote({
  customer: "cus_OufpKqnrvx9p1",
  items: [
    {
      product: "prd_OufpKqnrvx9p1",
      quantity: 10,
    },
  ],
});
```

```python tab="Python"
from fiscalisto import Fiscalisto

# The key comes from FISCALISTO_API_KEY.
fiscalisto = Fiscalisto()

price_quote = fiscalisto.prices.quote({
    "customer": "cus_OufpKqnrvx9p1",
    "items": [
        {
            "product": "prd_OufpKqnrvx9p1",
            "quantity": 10,
        },
    ],
})
```

```php tab="PHP"
<?php

use Fiscalisto\Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
$fiscalisto = new Fiscalisto();

$priceQuote = $fiscalisto->prices->quote([
    'customer' => 'cus_OufpKqnrvx9p1',
    'items' => [
        [
            'product' => 'prd_OufpKqnrvx9p1',
            'quantity' => 10,
        ],
    ],
]);
```

```go tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	fiscalisto "fiscalisto.com/go"
)

func main() {
	// The key comes from FISCALISTO_API_KEY.
	client, err := fiscalisto.NewClient("")
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()

	priceQuote, err := client.Prices.Quote(ctx, &fiscalisto.QuotePricesParams{
		Customer: "cus_OufpKqnrvx9p1",
		Items: []fiscalisto.QuotePricesParamsItem{
			{
				Product:  "prd_OufpKqnrvx9p1",
				Quantity: fiscalisto.Float64(10),
			},
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%+v\n", *priceQuote)
}
```

```java tab="Java"
import com.fiscalisto.FiscalistoClient;
import com.fiscalisto.model.QuotePricesParams;
import com.fiscalisto.model.QuotePricesParamsItem;
import java.util.List;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var priceQuote = fiscalisto.prices().quote(new QuotePricesParams()
        .setCustomer("cus_OufpKqnrvx9p1")
        .setItems(List.of(
                new QuotePricesParamsItem()
                        .setProduct("prd_OufpKqnrvx9p1")
                        .setQuantity(10)
        )));
System.out.println(priceQuote);
```

```csharp tab="C#"
using Fiscalisto;

// The key comes from FISCALISTO_API_KEY.
var fiscalisto = new FiscalistoClient();

var priceQuote = await fiscalisto.Prices.QuoteAsync(new QuotePricesParams
{
    Customer = "cus_OufpKqnrvx9p1",
    Items = new()
    {
        new()
        {
            Product = "prd_OufpKqnrvx9p1",
            Quantity = 10,
        },
    },
});
```

Returns, per product, its `unit_price` before IVA at that quantity, the `catalog_price`, the customer's `discount_percent` and `next_step`: from how many units it drops and to how much. It stores nothing: use it to show prices in your store or to fill `unit_price` and `discount` on an invoice or an order.

## Orders from the portal

A product with `portal_visible: true` (`POST /v1/products/{id}`) is sold in the Portal del cliente: your customers order it there at their prices, with `min_order_qty` and `order_step` (in steps of 12), and the order arrives in [Orders](https://fiscalisto.com/en/docs/api/pedidos) as a draft, for you to confirm.
