CFONB.Virement (CFONB v0.2.0)

Copy Markdown View Source

Emits a CFONB 160-character transfer order (ordre de virement) — a file sent to the bank, the counterpart of the 120 statement this library parses.

A remise (batch) is made of one émetteur record (03, the donneur d'ordre), one destinataire record (06) per beneficiary, and one total record (08) carrying the summed amount. Build a %CFONB.Virement{} with its list of %CFONB.Virement.Beneficiaire{} and call encode/1.

This first version supports the ordinary transfer (code opération 02), in euros. Bank coordinates are given either as an IBAN (decomposed and key-checked) or as split RIB components (établissement / guichet / compte) — setting both on the same struct is rejected as ambiguous.

Example

order = %CFONB.Virement{
  numero_emetteur: "123456",
  nom_emetteur: "ACME SARL",
  iban: "FR1420041010050500013M02606",
  beneficiaires: [
    %CFONB.Virement.Beneficiaire{
      nom: "JEAN DUPONT",
      iban: "FR7630004000031234567890143",
      montant: Decimal.new("1250.00"),
      libelle: "SALAIRE JUILLET"
    }
  ]
}

{:ok, %{file: file, total: total}} = CFONB.Virement.encode(order)

See FORMAT-VIREMENT.md for the exact 160-character field layout.

Summary

Functions

Encodes a %CFONB.Virement{} into a CFONB 160 file.

Same as encode/2 but returns the file binary directly and raises ArgumentError on invalid input.

Types

t()

@type t() :: %CFONB.Virement{
  beneficiaires: [CFONB.Virement.Beneficiaire.t()],
  code_operation: String.t(),
  compte: String.t() | nil,
  date: Date.t() | nil,
  etablissement: String.t() | nil,
  guichet: String.t() | nil,
  iban: String.t() | nil,
  nom_emetteur: String.t(),
  numero_emetteur: String.t() | nil,
  reference: String.t() | nil
}

Functions

encode(order, opts \\ [])

@spec encode(
  t(),
  keyword()
) :: {:ok, %{file: binary(), total: Decimal.t()}} | {:error, term()}

Encodes a %CFONB.Virement{} into a CFONB 160 file.

Returns {:ok, %{file: binary, total: Decimal.t()}} where file is the 03/06.../08 records joined by CRLF, or {:error, reason}.

Options

  • :separator — line separator, default "\r\n" (CRLF, the usual banking convention). Pass "\n" for LF.

encode!(order, opts \\ [])

@spec encode!(
  t(),
  keyword()
) :: binary()

Same as encode/2 but returns the file binary directly and raises ArgumentError on invalid input.