# Online stores

> Connect Shopify, WooCommerce, Tiendanube, Mercado Libre, Amazon, Mercado Pago, Conekta or Openpay: each paid order becomes a self-invoicing ticket, and whatever nobody invoices goes into the global invoice.

Each paid order from the store becomes a [self-invoicing ticket](https://fiscalisto.com/en/docs/api/autofactura) of the issuer, with the order's folio (`SHOP-1001`, `WEB-1001`, `TN-1001`, `ML-2000001234`, `AMZ-702-1234567-1234567`). Your buyer invoices it on the issuer's portal, and whatever nobody invoices goes on its own into the period's global invoice. A cancelled order, or one fully refunded, cancels its ticket as long as nobody has invoiced it.

| Store | How it connects | Where it runs |
| --- | --- | --- |
| Shopify | `POST /v1/store_connections` with the store app's keys | In Fiscalisto: nothing to install |
| WooCommerce | `POST /v1/store_connections` with a key from the store's REST API, or the **Fiscalisto Autofactura** plugin | In Fiscalisto (or the plugin, on your server) |
| Tiendanube | `POST /v1/store_connections` and the owner authorizes in Tiendanube | In Fiscalisto |
| Mercado Libre | `POST /v1/store_connections` and the seller authorizes in Mercado Libre | In Fiscalisto |
| Amazon | `POST /v1/store_connections` and the seller authorizes in Seller Central | In Fiscalisto: reads its orders every hour |

Whoever invoices without coding connects the same stores in the app, in **Ventas › Tiendas en línea**.

An order arrives only once even if the store sends it several times: the folio is the same ticket. Only orders in pesos with a total above 0 are recorded; the rest end up in the connection's `last_error`.

## Shopify

1. In Shopify's [Dev Dashboard](https://shopify.dev/docs/apps/build/dev-dashboard), create an app in the store's organization with the `read_orders` and `write_orders` scopes, and install it on the store.
2. Connect it with its Client ID and Client secret:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/store_connections \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "shopify",
    "shop": "mi-tienda.myshopify.com",
    "client_id": "8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b",
    "client_secret": "shpss_…",
    "settings": { "product_key": "53101600" }
  }'
```

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

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

const storeConnection = await fiscalisto.storeConnections.create({
  platform: "shopify",
  shop: "mi-tienda.myshopify.com",
  client_id: "8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b",
  client_secret: "shpss_…",
  settings: { product_key: "53101600" },
});
```

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

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

store_connection = fiscalisto.store_connections.create({
    "platform": "shopify",
    "shop": "mi-tienda.myshopify.com",
    "client_id": "8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b",
    "client_secret": "shpss_…",
    "settings": {"product_key": "53101600"},
})
```

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

use Fiscalisto\Fiscalisto;

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

$storeConnection = $fiscalisto->storeConnections->create([
    'platform' => 'shopify',
    'shop' => 'mi-tienda.myshopify.com',
    'client_id' => '8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b',
    'client_secret' => 'shpss_…',
    'settings' => ['product_key' => '53101600'],
]);
```

```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()

	storeConnection, err := client.StoreConnections.Create(ctx, &fiscalisto.CreateStoreConnectionParams{
		Platform:     "shopify",
		Shop:         fiscalisto.String("mi-tienda.myshopify.com"),
		ClientID:     fiscalisto.String("8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b"),
		ClientSecret: fiscalisto.String("shpss_…"),
		Settings: &fiscalisto.CreateStoreConnectionParamsSettings{
			ProductKey: fiscalisto.String("53101600"),
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(storeConnection.ID)
}
```

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

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

var storeConnection = fiscalisto.storeConnections().create(new CreateStoreConnectionParams()
        .setPlatform("shopify")
        .setShop("mi-tienda.myshopify.com")
        .setClientId("8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b")
        .setClientSecret("shpss_…")
        .setSettings(new CreateStoreConnectionParamsSettings()
                .setProductKey("53101600")));
System.out.println(storeConnection.getId());
```

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

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

var storeConnection = await fiscalisto.StoreConnections.CreateAsync(new CreateStoreConnectionParams
{
    Platform = "shopify",
    Shop = "mi-tienda.myshopify.com",
    ClientId = "8c1f0e7a2b3d4e5f6a7b8c9d0e1f2a3b",
    ClientSecret = "shpss_…",
    Settings = new() { ProductKey = "53101600" },
});
```

Fiscalisto registers the webhooks for paid orders, cancellations and refunds, and verifies each one's signature with the Client secret, which is stored encrypted and never shown. The app's keys only work for stores in the same Shopify organization (`store_connection_failed` otherwise). An old custom app, made in the store's admin, connects with its `shpat_…` token in `access_token` and its API secret key in `client_secret`.

Each order carries its self-invoicing link in the `fiscalisto.autofactura_url` metafield. To show it on the order status page and in the confirmation email, add it to your templates:

```liquid
{% if order.metafields.fiscalisto.autofactura_url %}
  <a href="{{ order.metafields.fiscalisto.autofactura_url }}">Facturar mi compra</a>
{% endif %}
```

## Mercado Libre

Create the connection without keys. It stays `pending` with `authorize_url`: send the seller there to authorize Fiscalisto on their Mercado Libre account. On return it's `active` (and, if you sent `return_url`, it goes back to your page with `store_connection` and `status`). `return_url` is followed only once: if the seller opens the same link again, they see Fiscalisto's page with the result.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/store_connections \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "mercadolibre",
    "return_url": "https://su-plataforma.com/tiendas",
    "settings": { "product_key": "43211500" }
  }'
```

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

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

const storeConnection = await fiscalisto.storeConnections.create({
  platform: "mercadolibre",
  return_url: "https://su-plataforma.com/tiendas",
  settings: { product_key: "43211500" },
});
```

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

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

store_connection = fiscalisto.store_connections.create({
    "platform": "mercadolibre",
    "return_url": "https://su-plataforma.com/tiendas",
    "settings": {"product_key": "43211500"},
})
```

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

use Fiscalisto\Fiscalisto;

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

$storeConnection = $fiscalisto->storeConnections->create([
    'platform' => 'mercadolibre',
    'return_url' => 'https://su-plataforma.com/tiendas',
    'settings' => ['product_key' => '43211500'],
]);
```

```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()

	storeConnection, err := client.StoreConnections.Create(ctx, &fiscalisto.CreateStoreConnectionParams{
		Platform:  "mercadolibre",
		ReturnURL: fiscalisto.String("https://su-plataforma.com/tiendas"),
		Settings: &fiscalisto.CreateStoreConnectionParamsSettings{
			ProductKey: fiscalisto.String("43211500"),
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(storeConnection.ID)
}
```

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

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

var storeConnection = fiscalisto.storeConnections().create(new CreateStoreConnectionParams()
        .setPlatform("mercadolibre")
        .setReturnUrl("https://su-plataforma.com/tiendas")
        .setSettings(new CreateStoreConnectionParamsSettings()
                .setProductKey("43211500")));
System.out.println(storeConnection.getId());
```

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

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

var storeConnection = await fiscalisto.StoreConnections.CreateAsync(new CreateStoreConnectionParams
{
    Platform = "mercadolibre",
    ReturnUrl = "https://su-plataforma.com/tiendas",
    Settings = new() { ProductKey = "43211500" },
});
```

- If the buyer left their tax data in Mercado Libre (RFC, name, regime and postal code), the invoice is stamped when the order is paid. If it's missing, the ticket waits on the portal. With `"auto_invoice": false` it always waits.
- Each invoice of an order (the buyer's, stamped here or on the portal) is uploaded to Mercado Libre as the order's tax document, with its XML and PDF.
- A Mercado Libre account connects to only one issuer at a time.

The ticket's total is the items' (`total_amount`): the shipping Mercado Libre charges isn't included.

## How each order becomes a ticket

`settings` decides the ticket's line item and keys. It changes with `POST /v1/store_connections/{id}` and applies from the next order.

| Field | What it does |
| --- | --- |
| `product_key` | The c_ClaveProdServ of what you sell. Required, unless every item in your orders is in your catalog by SKU. |
| `unit_key`, `iva` | The c_ClaveUnidad and the IVA rate included in prices (16 % if you don't say). |
| `description` | A fixed line item. If you don't set it, the order and its items: «Pedido 1001: Playera (2), Gorra». |
| `folio_prefix` | What goes before the order number: `SHOP-`, `WEB-`, `TN-`, `ML-` or `AMZ-` if you don't set it. |
| `payment_forms` | The c_FormaPago for each gateway (`shopify_payments`, `paypal`…), WooCommerce payment method (`bacs`, `cod`, `stripe`…) or Tiendanube one (`credit_card`, `wire_transfer`…), or Mercado Libre payment type (`credit_card`, `debit_card`, `account_money`, `ticket`…). |
| `notify_buyer` | WooCommerce and Tiendanube: send the buyer their invoicing link (WooCommerce, as a customer note on the order; Tiendanube, by email). `true` if you don't say. |
| `payment_form` | The one used when the order's isn't in `payment_forms`. |

An item whose SKU (`sku` in Shopify, WooCommerce and Tiendanube; `seller_sku` in Mercado Libre; `SellerSKU` in Amazon) is the `sku` of one of your products (`POST /v1/products`) goes as its own line item in `lines`, with the `product` (`prd_…`), its keys, its IVA and its withholdings. The order's other items go with `product_key`, each with its name. The order's total is split among the line items by each item's price, to the cent. If no SKU is in the catalog, the ticket carries one line item, as before.

Without `payment_forms`, a Shopify card is 04, PayPal and Mercado Pago 31, cash on delivery 01 and deposit 03. In Mercado Libre, credit 04, debit 28, account money 06, cash 01 and transfer 03; anything else, 31 (payment intermediary). In WooCommerce, transfer (`bacs`) 03, cash on delivery 01, card 04 and PayPal or Mercado Pago 31. In Amazon, 31 (Amazon collects for you), except cash on delivery, 01. Shopify's tip goes in `tip` and isn't part of the invoice.

## Orders that didn't arrive

If you connected the store after selling, or a webhook got lost, `POST /v1/store_connections/{id}/import_orders` brings the paid orders since `since` (up to 31 days back, 200 at a time). An order that was already a ticket isn't repeated.

## Disconnect

`DELETE /v1/store_connections/{id}` deletes its webhooks and keys, and orders stop arriving. The tickets it already made remain and can be invoiced.

## WooCommerce

In WordPress, open **WooCommerce › Ajustes › Avanzado › API REST** (Settings › Advanced › REST API), press **Añadir clave** (Add key) with **Lectura/Escritura** (Read/Write) permissions and connect it:

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/store_connections \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "woocommerce",
    "site": "https://mitienda.com",
    "consumer_key": "ck_…",
    "consumer_secret": "cs_…",
    "settings": { "product_key": "52151600" }
  }'
```

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

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

const storeConnection = await fiscalisto.storeConnections.create({
  platform: "woocommerce",
  site: "https://mitienda.com",
  consumer_key: "ck_…",
  consumer_secret: "cs_…",
  settings: { product_key: "52151600" },
});
```

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

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

store_connection = fiscalisto.store_connections.create({
    "platform": "woocommerce",
    "site": "https://mitienda.com",
    "consumer_key": "ck_…",
    "consumer_secret": "cs_…",
    "settings": {"product_key": "52151600"},
})
```

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

use Fiscalisto\Fiscalisto;

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

$storeConnection = $fiscalisto->storeConnections->create([
    'platform' => 'woocommerce',
    'site' => 'https://mitienda.com',
    'consumer_key' => 'ck_…',
    'consumer_secret' => 'cs_…',
    'settings' => ['product_key' => '52151600'],
]);
```

```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()

	storeConnection, err := client.StoreConnections.Create(ctx, &fiscalisto.CreateStoreConnectionParams{
		Platform:       "woocommerce",
		Site:           fiscalisto.String("https://mitienda.com"),
		ConsumerKey:    fiscalisto.String("ck_…"),
		ConsumerSecret: fiscalisto.String("cs_…"),
		Settings: &fiscalisto.CreateStoreConnectionParamsSettings{
			ProductKey: fiscalisto.String("52151600"),
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(storeConnection.ID)
}
```

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

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

var storeConnection = fiscalisto.storeConnections().create(new CreateStoreConnectionParams()
        .setPlatform("woocommerce")
        .setSite("https://mitienda.com")
        .setConsumerKey("ck_…")
        .setConsumerSecret("cs_…")
        .setSettings(new CreateStoreConnectionParamsSettings()
                .setProductKey("52151600")));
System.out.println(storeConnection.getId());
```

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

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

var storeConnection = await fiscalisto.StoreConnections.CreateAsync(new CreateStoreConnectionParams
{
    Platform = "woocommerce",
    Site = "https://mitienda.com",
    ConsumerKey = "ck_…",
    ConsumerSecret = "cs_…",
    Settings = new() { ProductKey = "52151600" },
});
```

Fiscalisto checks that the store sells in pesos and registers its webhooks (`order.created` and `order.updated`), signed with a secret of its own. An order in **Procesando** (Processing) or **Completado** (Completed) is a ticket; a **Cancelado** (Cancelled) or **Reembolsado** (Refunded) one cancels its own. The invoicing link stays on the order (`_fiscalisto_autofactura_url`) and, with `notify_buyer`, as a customer note, which WooCommerce emails them. The store must be at a public `https` address.

If you'd rather have everything run on your server, the **Fiscalisto Autofactura** plugin does the same with one of your API keys (Desarrolladores › Llaves): it records each paid order with `POST /v1/tickets`, shows the self-invoicing link on the thank-you page, in **Mi cuenta** (My account) and in the order emails, and cancels the ticket if the order is cancelled or fully refunded. If Fiscalisto doesn't answer, it retries on its own. It's configured in **WooCommerce › Ajustes › Fiscalisto**. Install it from WordPress, in **Plugins › Añadir nuevo plugin** (Add new plugin): search for «Fiscalisto Autofactura» ([on WordPress.org](https://wordpress.org/plugins/fiscalisto-autofactura/)).

## Tiendanube

Like Mercado Libre: create the connection without keys (`"platform": "tiendanube"`), send the store owner to `authorize_url` and, once authorized, it's `active` with its webhooks (`order/paid`, `order/cancelled`, `order/voided` and `app/uninstalled`). A paid order is a ticket; a cancelled or voided one cancels its own. With `notify_buyer`, the buyer gets the invoicing link by email, in the store's name. If the app is uninstalled in Tiendanube, the connection becomes `disconnected`. A store connects to only one issuer at a time.

## Amazon

Create the connection without keys (`"platform": "amazon"`) and send the seller to `authorize_url`, in Amazon.com.mx's Seller Central. Amazon doesn't notify by webhook: Fiscalisto reads the orders that changed every hour. An **Unshipped**, **PartiallyShipped** or **Shipped** order is a ticket; a **Canceled** one cancels its own; **Pending** ones wait to be paid. Amazon doesn't allow writing to its buyers outside its messaging, so you give them the invoicing link (for example, in the shipping message); whatever nobody invoices goes into the global invoice. A seller account connects to only one issuer at a time.

## Mercado Pago, Conekta and Openpay

Your payment gateway's charges connect too: each paid charge is a ticket (`MP-`, `CK-`, `OP-`), a refunded or cancelled one cancels its own, and with `notify_buyer` the customer gets the invoicing link by email when the charge carries their email. Fiscalisto never uses a notification's body: it reads the charge again with your key.

- **Mercado Pago:** the production `access_token` (`APP_USR-…`). Mercado Pago doesn't allow registering webhooks by API, so Fiscalisto reads the approved payments every hour.
- **Conekta:** `private_key` (`key_…`). Fiscalisto registers the orders webhook.
- **Openpay:** `merchant_id`, `private_key` (`sk_…`) and `sandbox` for your test merchant. Fiscalisto registers the webhook; if Openpay asks to verify it, the code shows in `last_error`.

```bash tab="cURL"
curl https://api.fiscalisto.com/v1/store_connections \
  -H "Authorization: Bearer $FISCALISTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "conekta",
    "private_key": "key_…",
    "settings": { "product_key": "86121700" }
  }'
```

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

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

const storeConnection = await fiscalisto.storeConnections.create({
  platform: "conekta",
  private_key: "key_…",
  settings: { product_key: "86121700" },
});
```

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

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

store_connection = fiscalisto.store_connections.create({
    "platform": "conekta",
    "private_key": "key_…",
    "settings": {"product_key": "86121700"},
})
```

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

use Fiscalisto\Fiscalisto;

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

$storeConnection = $fiscalisto->storeConnections->create([
    'platform' => 'conekta',
    'private_key' => 'key_…',
    'settings' => ['product_key' => '86121700'],
]);
```

```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()

	storeConnection, err := client.StoreConnections.Create(ctx, &fiscalisto.CreateStoreConnectionParams{
		Platform:   "conekta",
		PrivateKey: fiscalisto.String("key_…"),
		Settings: &fiscalisto.CreateStoreConnectionParamsSettings{
			ProductKey: fiscalisto.String("86121700"),
		},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(storeConnection.ID)
}
```

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

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

var storeConnection = fiscalisto.storeConnections().create(new CreateStoreConnectionParams()
        .setPlatform("conekta")
        .setPrivateKey("key_…")
        .setSettings(new CreateStoreConnectionParamsSettings()
                .setProductKey("86121700")));
System.out.println(storeConnection.getId());
```

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

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

var storeConnection = await fiscalisto.StoreConnections.CreateAsync(new CreateStoreConnectionParams
{
    Platform = "conekta",
    PrivateKey = "key_…",
    Settings = new() { ProductKey = "86121700" },
});
```
