Skip to main content
The Exchange Component (billing.exchange) manages the exchange of electronic tax documents between trading parties, including sending to SII and trading partners.

Overview

This component handles the complete document exchange workflow, supporting multiple delivery channels and strategies for both sending and receiving documents.

Workers

The Exchange Component contains the following workers:

Sender Worker

Sends documents to recipients using various strategies (SII, email, API)

Receiver Worker

Receives and processes incoming documents from trading partners

Main Methods

send

Sends one or more documents to their recipients.
bag
ExchangeBagInterface
required
Exchange bag containing the documents to send and delivery configuration
return
array
Returns an array with the results of the send operation for each document
use libredte\lib\Core\Package\Billing\Component\Exchange\ExchangeComponent;

// Send documents
$results = $exchangeComponent->send($exchangeBag);

receive

Receives and processes incoming documents.
bag
ExchangeBagInterface
required
Exchange bag configured for receiving documents
return
array
Returns an array of received and processed documents
// Receive documents
$documents = $exchangeComponent->receive($exchangeBag);

handle

Intelligently handles an exchange bag, automatically determining whether to send or receive based on the bag contents.
bag
ExchangeBagInterface
required
Exchange bag to process
return
array
Returns results from either send or receive operation
// Automatically handle the exchange
$results = $exchangeComponent->handle($exchangeBag);

Worker Access Methods

getSenderWorker

Returns the sender worker for sending documents.
return
SenderWorkerInterface
Returns the sender worker instance

getReceiverWorker

Returns the receiver worker for receiving documents.
return
ReceiverWorkerInterface
Returns the receiver worker instance

getWorkers

Returns all available workers.
return
array
Returns an associative array with worker names as keys:
  • sender: SenderWorkerInterface
  • receiver: ReceiverWorkerInterface

Sending Strategies

The sender worker supports multiple strategies for document delivery:
Sends regular DTE (Documento Tributario Electrónico) documents to SII.Strategy: DteSenderStrategyLocation: /workspace/source/src/Package/Billing/Component/Exchange/Worker/Sender/Strategy/Sii/DteSenderStrategy.php
Sends boletas (electronic receipts) to SII using the specific boleta endpoint.Strategy: BoletaSenderStrategyLocation: /workspace/source/src/Package/Billing/Component/Exchange/Worker/Sender/Strategy/Sii/BoletaSenderStrategy.php

Exchange Entities

The component works with the following entities:

Sender

Represents the party sending documents with authentication and configuration. Entity: libredte\lib\Core\Package\Billing\Component\Exchange\Entity\Sender

Receiver

Represents the party receiving documents with endpoint configuration. Entity: libredte\lib\Core\Package\Billing\Component\Exchange\Entity\Receiver

PartyIdentifier

Identifies a party in the exchange (RUT, email, etc.). Entity: libredte\lib\Core\Package\Billing\Component\Exchange\Entity\PartyIdentifier

PartyEndpoint

Defines an endpoint for document delivery (URL, email, etc.). Entity: libredte\lib\Core\Package\Billing\Component\Exchange\Entity\PartyEndpoint

Usage Example

use libredte\lib\Core\Package\Billing\Component\Exchange\ExchangeComponent;

// Get the exchange component
$exchangeComponent = $billingPackage->getExchangeComponent();

// Prepare an exchange bag with documents
// The bag contains envelopes with documents to send

// Option 1: Explicitly send
$sendResults = $exchangeComponent->send($exchangeBag);

// Option 2: Explicitly receive
$receivedDocs = $exchangeComponent->receive($receiveBag);

// Option 3: Let the component decide
$results = $exchangeComponent->handle($exchangeBag);

Document Flow

When handling an exchange:
  1. The handle() method checks if the bag has envelopes
  2. If envelopes exist, it routes to the sender worker
  3. If no envelopes, it routes to the receiver worker
  4. The appropriate worker processes the documents using the configured strategy
  5. Results are returned to the caller

Source Reference

Namespace: libredte\lib\Core\Package\Billing\Component\Exchange\ExchangeComponent Location: /workspace/source/src/Package/Billing/Component/Exchange/ExchangeComponent.php:40

Build docs developers (and LLMs) love