PaybookDocsv1
Docs/Guías

Pólizas contables y envío a SAP

Convierte cada cobro en una póliza cuadrada, entrégala a SAP por API o por archivo y registra el acuse del ERP.

Cómo se genera una póliza#

Cada hecho con efecto contable (un pago, un reembolso, una factura, una liquidación) dispara una regla contable. La regla decide la sociedad, el tipo de documento, las cuentas, los centros de costo y de beneficio, y produce una póliza cuadrada: cargos igual a abonos.

acknowledgeenvío o loteEventopago · reembolso · CFDIRegla contablecuentas y centrosPólizaaccounting_entrySAPcontabilizaAcusedocumento o rechazo

Las reglas se configuran por institución con su catálogo de cuentas. Puedes leerlas y administrarlas con GET/v1/accounting_rules.

Dos modelos de entrega#

ModeloCómo funcionaCuándo conviene
Por APITu capa de integración lee las pólizas, las contabiliza en SAP y registra el acuse en HUB+.Ya tienes una capa de integración hacia SAP.
Por lote de archivoHUB+ genera un archivo con el layout de SAP para un rango de fechas. Tu proceso lo carga.Cargas programadas por la noche o por cierre.
  1. Lee las pólizas pendientes#

    Filtra por sociedad, campus, fecha de contabilización y estado ante el ERP.

    GET/v1/accounting_entries
    curl "https://api.sandbox.hubplus.example/v1/accounting_entries?company_code=AN01&posting_date=2026-11-05&erp_status=pending" \
      -H "Authorization: Bearer $HUB_ACCESS_TOKEN" \
      -H "X-Tenant-Id: $HUB_TENANT_ID"
    const params = new URLSearchParams({
      "company_code": "AN01",
      "posting_date": "2026-11-05",
      "erp_status": "pending"
    });
    
    const res = await fetch(`https://api.sandbox.hubplus.example/v1/accounting_entries?${params}`, {
      headers: {
        "Authorization": "Bearer " + process.env.HUB_ACCESS_TOKEN,
        "X-Tenant-Id": process.env.HUB_TENANT_ID,
      },
    });
    
    if (!res.ok) throw new Error(`HUB+ respondió ${res.status}`);
    const data = await res.json();
    import os
    import requests
    
    res = requests.get(
        "https://api.sandbox.hubplus.example/v1/accounting_entries",
        headers={
            "Authorization": f"Bearer {os.environ['HUB_ACCESS_TOKEN']}",
            "X-Tenant-Id": os.environ["HUB_TENANT_ID"],
        },
        params={
            "company_code": "AN01",
            "posting_date": "2026-11-05",
            "erp_status": "pending",
        },
        timeout=30,
    )
    res.raise_for_status()
    data = res.json()
    <?php
    $ch = curl_init("https://api.sandbox.hubplus.example/v1/accounting_entries" . "?" . http_build_query([
        "company_code" => "AN01",
        "posting_date" => "2026-11-05",
        "erp_status" => "pending",
    ]));
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("HUB_ACCESS_TOKEN"),
            "X-Tenant-Id: " . getenv("HUB_TENANT_ID"),
        ],
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($status >= 400) {
        throw new RuntimeException("HUB+ respondió $status");
    }
    $data = json_decode($body, true);
    HttpClient client = HttpClient.newHttpClient();
    
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.sandbox.hubplus.example/v1/accounting_entries?company_code=AN01&posting_date=2026-11-05&erp_status=pending"))
        .header("Authorization", "Bearer " + System.getenv("HUB_ACCESS_TOKEN"))
        .header("X-Tenant-Id", System.getenv("HUB_TENANT_ID"))
        .GET()
        .build();
    
    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());

    Cada póliza trae su encabezado y sus partidas, con el origen que la generó en source:

    Póliza (abreviada)
    {
      "id": "59a3162a-ff93-4a07-835a-f42ee2e140f2",
      "object": "accounting_entry",
      "number": "AN01-I-2026-11-004821",
      "entry_type": "income",
      "status": "posted",
      "document_date": "2026-11-05",
      "posting_date": "2026-11-05",
      "company_code": "AN01",
      "document_type": "DZ",
      "currency": "mxn",
      "reference": "0045187220261104",
      "header_text": "Cobranza HUB+ 2026-11",
      "source": {
        "trigger": "payment.succeeded",
        "type": "payment",
        "id": "8920caef-a5bc-44b1-848e-97718177602b"
      },
      "lines": [
        {
          "line_number": 1,
          "side": "debit",
          "account": "1102010015",
          "account_name": "Bancos · cuenta concentradora adquirente",
          "amount": 1261538,
          "cost_center": null,
          "profit_center": "PC-ING-NTE",
          "tax_code": null,
          "text": "Cobro 0045187220261104 mat. 00451872",
          "assignment": "0045187220261104"
        },
        {
          "line_number": 2,
          "side": "debit",
          "account": "6105020003",
          "account_name": "Comisiones por cobranza con tarjeta",
          "amount": 25830,
          "cost_center": "CC-TES-NTE",
          "profit_center": null,
          "tax_code": null,
          "text": "Comisión cobro 0045187220261104",
          "assignment": "0045187220261104"
        },
        {
          "line_number": 3,
          "side": "debit",
          "account": "1107010001",
          "account_name": "IVA acreditable pagado",
          "amount": 4132,
          "cost_center": null,
          "profit_center": null,
          "tax_code": "V2",
          "text": "IVA comisión 0045187220261104",
          "assignment": "0045187220261104"
        },
        {
          "line_number": 4,
          "side": "credit",
          "account": "1105010001",
          "account_name": "Cuentas por cobrar · colegiaturas",
          "amount": 1291500,
          "cost_center": null,
          "profit_center": "PC-ING-NTE",
          "tax_code": null,
          "text": "Colegiatura licenciatura mat. 00451872",
          "assignment": "00451872"
        }
      ]
    }
  2. Entrega la póliza a SAP#

    Por API: contabiliza la póliza en SAP con tu capa de integración. Si HUB+ opera el envío, lo solicitas o lo reintentas con:

    POST/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp
    curl -X POST "https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp" \
      -H "Authorization: Bearer $HUB_ACCESS_TOKEN" \
      -H "X-Tenant-Id: $HUB_TENANT_ID" \
      -H "Content-Type: application/json" \
      -d '{
      "note": "Reenvío tras alta del centro de costo CC-TES-NTE en SAP."
    }'
    const res = await fetch("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp", {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + process.env.HUB_ACCESS_TOKEN,
        "X-Tenant-Id": process.env.HUB_TENANT_ID,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        "note": "Reenvío tras alta del centro de costo CC-TES-NTE en SAP."
      }),
    });
    
    if (!res.ok) throw new Error(`HUB+ respondió ${res.status}`);
    const data = await res.json();
    import os
    import requests
    
    res = requests.post(
        "https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp",
        headers={
            "Authorization": f"Bearer {os.environ['HUB_ACCESS_TOKEN']}",
            "X-Tenant-Id": os.environ["HUB_TENANT_ID"],
        },
        json={
            "note": "Reenvío tras alta del centro de costo CC-TES-NTE en SAP.",
        },
        timeout=30,
    )
    res.raise_for_status()
    data = res.json()
    <?php
    $ch = curl_init("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("HUB_ACCESS_TOKEN"),
            "X-Tenant-Id: " . getenv("HUB_TENANT_ID"),
            "Content-Type: application/json",
        ],
        CURLOPT_POSTFIELDS => json_encode([
            "note" => "Reenvío tras alta del centro de costo CC-TES-NTE en SAP.",
        ]),
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($status >= 400) {
        throw new RuntimeException("HUB+ respondió $status");
    }
    $data = json_decode($body, true);
    HttpClient client = HttpClient.newHttpClient();
    
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/send_to_erp"))
        .header("Authorization", "Bearer " + System.getenv("HUB_ACCESS_TOKEN"))
        .header("X-Tenant-Id", System.getenv("HUB_TENANT_ID"))
        .header("Content-Type", "application/json")
        .method("POST", HttpRequest.BodyPublishers.ofString("""
            {
              "note": "Reenvío tras alta del centro de costo CC-TES-NTE en SAP."
            }
            """))
        .build();
    
    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());

    Por lote: pide el archivo de un rango de fechas. Es asíncrono. Cuando termina, descárgalo.

    POST/v1/accounting_entry_batches
    curl -X POST "https://api.sandbox.hubplus.example/v1/accounting_entry_batches" \
      -H "Authorization: Bearer $HUB_ACCESS_TOKEN" \
      -H "X-Tenant-Id: $HUB_TENANT_ID" \
      -H "Idempotency-Key: $(uuidgen)" \
      -H "Content-Type: application/json" \
      -d '{
      "delivery": "file",
      "format": "sap_csv_zip",
      "filters": {
        "company_code": "AN01",
        "campus": "4903bcca-ca3f-403a-860a-2f65f42d9987",
        "posting_date_from": "2026-11-05",
        "posting_date_to": "2026-11-05",
        "erp_status": [
          "pending",
          "rejected"
        ]
      },
      "mark_as_sent": true,
      "metadata": {
        "sap_run": "HUB-20261105-NTE"
      }
    }'
    const res = await fetch("https://api.sandbox.hubplus.example/v1/accounting_entry_batches", {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + process.env.HUB_ACCESS_TOKEN,
        "X-Tenant-Id": process.env.HUB_TENANT_ID,
        "Idempotency-Key": crypto.randomUUID(),
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        "delivery": "file",
        "format": "sap_csv_zip",
        "filters": {
          "company_code": "AN01",
          "campus": "4903bcca-ca3f-403a-860a-2f65f42d9987",
          "posting_date_from": "2026-11-05",
          "posting_date_to": "2026-11-05",
          "erp_status": [
            "pending",
            "rejected"
          ]
        },
        "mark_as_sent": true,
        "metadata": {
          "sap_run": "HUB-20261105-NTE"
        }
      }),
    });
    
    if (!res.ok) throw new Error(`HUB+ respondió ${res.status}`);
    const data = await res.json();
    import os
    import uuid
    import requests
    
    res = requests.post(
        "https://api.sandbox.hubplus.example/v1/accounting_entry_batches",
        headers={
            "Authorization": f"Bearer {os.environ['HUB_ACCESS_TOKEN']}",
            "X-Tenant-Id": os.environ["HUB_TENANT_ID"],
            "Idempotency-Key": str(uuid.uuid4()),
        },
        json={
            "delivery": "file",
            "format": "sap_csv_zip",
            "filters": {
                "company_code": "AN01",
                "campus": "4903bcca-ca3f-403a-860a-2f65f42d9987",
                "posting_date_from": "2026-11-05",
                "posting_date_to": "2026-11-05",
                "erp_status": ["pending", "rejected"],
            },
            "mark_as_sent": True,
            "metadata": {
                "sap_run": "HUB-20261105-NTE",
            },
        },
        timeout=30,
    )
    res.raise_for_status()
    data = res.json()
    <?php
    $ch = curl_init("https://api.sandbox.hubplus.example/v1/accounting_entry_batches");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("HUB_ACCESS_TOKEN"),
            "X-Tenant-Id: " . getenv("HUB_TENANT_ID"),
            "Idempotency-Key: " . bin2hex(random_bytes(16)),
            "Content-Type: application/json",
        ],
        CURLOPT_POSTFIELDS => json_encode([
            "delivery" => "file",
            "format" => "sap_csv_zip",
            "filters" => [
                "company_code" => "AN01",
                "campus" => "4903bcca-ca3f-403a-860a-2f65f42d9987",
                "posting_date_from" => "2026-11-05",
                "posting_date_to" => "2026-11-05",
                "erp_status" => ["pending", "rejected"],
            ],
            "mark_as_sent" => true,
            "metadata" => [
                "sap_run" => "HUB-20261105-NTE",
            ],
        ]),
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($status >= 400) {
        throw new RuntimeException("HUB+ respondió $status");
    }
    $data = json_decode($body, true);
    HttpClient client = HttpClient.newHttpClient();
    
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.sandbox.hubplus.example/v1/accounting_entry_batches"))
        .header("Authorization", "Bearer " + System.getenv("HUB_ACCESS_TOKEN"))
        .header("X-Tenant-Id", System.getenv("HUB_TENANT_ID"))
        .header("Idempotency-Key", UUID.randomUUID().toString())
        .header("Content-Type", "application/json")
        .method("POST", HttpRequest.BodyPublishers.ofString("""
            {
              "delivery": "file",
              "format": "sap_csv_zip",
              "filters": {
                "company_code": "AN01",
                "campus": "4903bcca-ca3f-403a-860a-2f65f42d9987",
                "posting_date_from": "2026-11-05",
                "posting_date_to": "2026-11-05",
                "erp_status": [
                  "pending",
                  "rejected"
                ]
              },
              "mark_as_sent": true,
              "metadata": {
                "sap_run": "HUB-20261105-NTE"
              }
            }
            """))
        .build();
    
    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());
    GET/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download
    curl "https://api.sandbox.hubplus.example/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download" \
      -H "Authorization: Bearer $HUB_ACCESS_TOKEN" \
      -H "X-Tenant-Id: $HUB_TENANT_ID"
    const res = await fetch("https://api.sandbox.hubplus.example/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download", {
      headers: {
        "Authorization": "Bearer " + process.env.HUB_ACCESS_TOKEN,
        "X-Tenant-Id": process.env.HUB_TENANT_ID,
      },
    });
    
    if (!res.ok) throw new Error(`HUB+ respondió ${res.status}`);
    const data = await res.json();
    import os
    import requests
    
    res = requests.get(
        "https://api.sandbox.hubplus.example/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download",
        headers={
            "Authorization": f"Bearer {os.environ['HUB_ACCESS_TOKEN']}",
            "X-Tenant-Id": os.environ["HUB_TENANT_ID"],
        },
        timeout=30,
    )
    res.raise_for_status()
    data = res.json()
    <?php
    $ch = curl_init("https://api.sandbox.hubplus.example/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("HUB_ACCESS_TOKEN"),
            "X-Tenant-Id: " . getenv("HUB_TENANT_ID"),
        ],
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($status >= 400) {
        throw new RuntimeException("HUB+ respondió $status");
    }
    $data = json_decode($body, true);
    HttpClient client = HttpClient.newHttpClient();
    
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.sandbox.hubplus.example/v1/accounting_entry_batches/6dd9ea3a-9c4c-43c0-8ad6-5ea32fa5af4b/download"))
        .header("Authorization", "Bearer " + System.getenv("HUB_ACCESS_TOKEN"))
        .header("X-Tenant-Id", System.getenv("HUB_TENANT_ID"))
        .GET()
        .build();
    
    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());
  3. Registra el acuse de SAP#

    Cuando SAP contabiliza, registra el número de documento. Así cada póliza de HUB+ queda ligada a su documento en el ERP.

    POST/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge
    curl -X POST "https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge" \
      -H "Authorization: Bearer $HUB_ACCESS_TOKEN" \
      -H "X-Tenant-Id: $HUB_TENANT_ID" \
      -H "Idempotency-Key: $(uuidgen)" \
      -H "Content-Type: application/json" \
      -d '{
      "result": "posted",
      "document_number": "1400052817",
      "fiscal_year": 2026,
      "company_code": "AN01",
      "posted_at": 1793941241
    }'
    const res = await fetch("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge", {
      method: "POST",
      headers: {
        "Authorization": "Bearer " + process.env.HUB_ACCESS_TOKEN,
        "X-Tenant-Id": process.env.HUB_TENANT_ID,
        "Idempotency-Key": crypto.randomUUID(),
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        "result": "posted",
        "document_number": "1400052817",
        "fiscal_year": 2026,
        "company_code": "AN01",
        "posted_at": 1793941241
      }),
    });
    
    if (!res.ok) throw new Error(`HUB+ respondió ${res.status}`);
    const data = await res.json();
    import os
    import uuid
    import requests
    
    res = requests.post(
        "https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge",
        headers={
            "Authorization": f"Bearer {os.environ['HUB_ACCESS_TOKEN']}",
            "X-Tenant-Id": os.environ["HUB_TENANT_ID"],
            "Idempotency-Key": str(uuid.uuid4()),
        },
        json={
            "result": "posted",
            "document_number": "1400052817",
            "fiscal_year": 2026,
            "company_code": "AN01",
            "posted_at": 1793941241,
        },
        timeout=30,
    )
    res.raise_for_status()
    data = res.json()
    <?php
    $ch = curl_init("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge");
    curl_setopt_array($ch, [
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_HTTPHEADER => [
            "Authorization: Bearer " . getenv("HUB_ACCESS_TOKEN"),
            "X-Tenant-Id: " . getenv("HUB_TENANT_ID"),
            "Idempotency-Key: " . bin2hex(random_bytes(16)),
            "Content-Type: application/json",
        ],
        CURLOPT_POSTFIELDS => json_encode([
            "result" => "posted",
            "document_number" => "1400052817",
            "fiscal_year" => 2026,
            "company_code" => "AN01",
            "posted_at" => 1793941241,
        ]),
    ]);
    $body = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    if ($status >= 400) {
        throw new RuntimeException("HUB+ respondió $status");
    }
    $data = json_decode($body, true);
    HttpClient client = HttpClient.newHttpClient();
    
    HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://api.sandbox.hubplus.example/v1/accounting_entries/59a3162a-ff93-4a07-835a-f42ee2e140f2/acknowledge"))
        .header("Authorization", "Bearer " + System.getenv("HUB_ACCESS_TOKEN"))
        .header("X-Tenant-Id", System.getenv("HUB_TENANT_ID"))
        .header("Idempotency-Key", UUID.randomUUID().toString())
        .header("Content-Type", "application/json")
        .method("POST", HttpRequest.BodyPublishers.ofString("""
            {
              "result": "posted",
              "document_number": "1400052817",
              "fiscal_year": 2026,
              "company_code": "AN01",
              "posted_at": 1793941241
            }
            """))
        .build();
    
    HttpResponse<String> response =
        client.send(request, HttpResponse.BodyHandlers.ofString());

    Si SAP rechaza la póliza, registra el rechazo con sus mensajes. La póliza queda marcada para corrección y recibes accounting_entry.rejected.

  4. Corrige y reenvía#

    Los rechazos más comunes son un centro de costo inexistente, un periodo contable cerrado o una cuenta bloqueada. Corrige la causa (en SAP o en la regla contable) y reenvía con send_to_erp.

Eventos#

EventoÚsalo para
accounting_entry.createdQue el ERP lea la póliza en cuanto nace.
accounting_entry.sent_to_erpSaber que la póliza se entregó y espera acuse.
accounting_entry.acknowledgedCerrar el ciclo: trae el documento de SAP.
accounting_entry.rejectedAlertar a contabilidad con los mensajes del ERP.

Cuadre diario#

Para un cierre limpio, compara por sociedad y por día tres totales: lo cobrado (GET/v1/data/payment-history), lo contabilizado (pólizas con acuse) y lo depositado (liquidaciones). La guía de conciliación cubre el tercer lado.

La conexión con SAP se configura con cada institución

El catálogo de cuentas, los centros de costo, el layout y el calendario de envío son propios de cada red. Lee la integración con SAP.

HUB+ by Paybook · Documentación para desarrolladores · API v1
Los hosts, llaves e identificadores de los ejemplos son ficticios.