anglemx / mexico-rfc
PHP utility to handle Mexico SAT's (Tax Authority) RFC (Tax ID)
Installs: 2 275
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:git
Requires
- php: >=7.2
- ext-bcmath: *
- ext-intl: *
- ext-json: *
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^7.5
README
PHP utility to handle Mexico SAT's (Tax Authority) RFC (Tax ID)
RFC
What is RFC? Registro Federal de Contribuyentes for the Mexican Tax Authority: SAT Servicio de Administración Tributaria and SHCP Secretaría de Hacienda y Crédito Público.
How to Use
Calculate a Person's RFC from their Name and Date of Birth data
This calculates the Homoclave , which is a __
However, do note this is only a baseline ___ and SAT can always change this __ code
specially the last 3 digits called homoclave.
The whole purpose of this is to prevent __
If two individuals were to have the exact same name born on the same date __ then they would be homonyms __ sharing the same base __
SAT would then change the homoclave for one or both of them.
More testing and validation is still required, RFCs have a lot of exceptions and edge cases that must be considered.
$dob = \DateTime::createFromFormat('Y-m-d', '1989-07-15'); $rfc = RFC::createForNaturalPerson('Jose Ramiro', 'Gutierrez', 'Hernández', $dob); echo $rfc->getRfc(); // GUHR890715 echo $rfc->getRfcComplete(); // GUHR890715G54
Validate existing RFC strings
The utility can also be used to validate an existing RFC string and infer some metadata from it.
echo (RFC::isValid('INVALID_12313') ? 'Yes' : 'No'); // No echo (RFC::isValid('GUHR890715G54') ? 'Yes' : 'No'); // Yes echo (RFC::isValidWithoutHomoclave('GUHR890715') ? 'Yes' : 'No'); // Yes
Extract metadata from valid RFC strings
Validate and infer some metadata from the RFC string, such as type of legal entity.
TODO: infer date of birth.
$rfc = RFC::createFromRfcString('GUHR890715G54'); if ($rfc === null) { die('Invalid RFC string'); } echo ($rfc->isGeneric() ? 'Yes' : 'No'); // No echo ($rfc->isNaturalPerson() ? 'Yes' : 'No'); // Yes
Tests
php vendor/bin/phpunit tests/BuildTest.php php vendor/bin/phpunit tests/ValidationTest.php
TO-DO
- Finish writing up this README
- Cleanup the RFC class, it's very messy right now. Also clean up the Tests for RFC verifications. Implement some way of testing private / protected methods ?
- Find a big list of Person Names, Date of Births and RFCs to test against.
References
https://cec.cele.unam.mx/include/howToRFC.php https://solucionfactible.com/sfic/capitulos/timbrado/rfc-clave-direfenciadora-homonimia.jsp https://solucionfactible.com/sfic/capitulos/timbrado/rfc-digito-verificador.jsp https://solucionfactible.com/sfic/capitulos/timbrado/rfc-anexos.jsp https://solucionfactible.com/sfic/resources/files/palabrasInconvenientes-rfc.pdf