1e90ff/cfdi-helper

A library for data extraction and validation of status and integrity of mexican CFDI.

dev-main 2022-03-27 22:58 UTC

This package is auto-updated.

Last update: 2024-04-28 03:56:51 UTC


README

A library for data extraction and validation of status and integrity of mexican CFDI.

Usage

Initialization

<?php

use _1e90ff\CfdiHelper\Cfdi;

$cfdi = new Cfdi($element); // accepts a SimpleXMLElement object
$cfdiFromFile = Cfdi::loadFromFile('cfdi.xml');
$cfdiFromString = Cfdi::loadFromString('<?xml ...');

General data access

$cfdi->version();
// returns declared CFDI version (like 3.3 or 4.0)

$cfdi->valid();
// returns true or false depending on a signature integrity check success

$cfdi->type();
// returns I (Ingreso), E (Egreso), T (Traslado), P (Pago) or N (Nómina)

$cfdi->date();
// returns date of issue

$cfdi->total();
// returns total amount of the CFDI

$cfdi->currency();
// returns currency code of the total amount

$cfdi->exchangeRate();
// returns exchange rate of the currency in mexican peso (MXN)

$cfdi->signature();
// returns base64-encoded signature

$cfdi->certificate();
// returns base64-encoded certificate

Issuer data access

$cfdi->issuer()->rfc();
// returns RFC (Registro Federal del Contribuyente) of the issuer

$cfdi->issuer()->name();
// returns name of the issuer

Receiver data access

$cfdi->receiver()->rfc();
// returns RFC (Registro Federal del Contribuyente) of the receiver

$cfdi->receiver()->name();
// returns name of the receiver

Digital tax stamp data access (if present)

$cfdi->digitalTaxStamp()->uuid();
// returns unique identifier of the CFDI

$cfdi->digitalTaxStamp()->date();
// returns date of stamp

$cfdi->digitalTaxStamp()->signature();
// returns base64-encoded signature

Getting the current CFDI status (if digital tax stamp data is present)

<?php

use _1e90ff\CfdiHelper\Cfdi;
use _1e90ff\CfdiHelper\Utils\CfdiStatusRequest;

$cfdi = new Cfdi($element);

$request = new CfdiStatusRequest();

$cfdi = $request->update($cfdi);

// Helper functions

$cfdi->status->isValid();
// returns true or false depending if the CFDI is still valid for tax purposes

$cfdi->status->isCancelable();
// returns true or false depending if the CFDI is cancelable

$cfdi->status->isCancelableWithConfirmation();
// returns true or false depending if the cancelation requires receiver confirmation

$cfdi->status->isBlacklistedIssuer();
// returns true or false depending if the issuer is marked as EFOS (Empresa que Factura Operaciones Simuladas)

// Raw data

$cfdi->status->date();
// returns request date

$cfdi->status->status();
// returns Vigente (valid), Cancelado (cancelled) or No encontrado (not found)

$cfdi->status->cancelable();
// returns Cancelable (cancelable), No cancelable (not cancelable), Cancelable con aceptación (cancelable with confirmation)

$cfdi->status->issuerStatus();
// returns 100 (EFOS code) or 200 (good issuer)