https://github.com/thegreenter/gre-api
API Rest para envió de Guías de Remisión
https://github.com/thegreenter/gre-api
Last synced: 5 months ago
JSON representation
API Rest para envió de Guías de Remisión
- Host: GitHub
- URL: https://github.com/thegreenter/gre-api
- Owner: thegreenter
- License: mit
- Created: 2022-12-30T20:33:32.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-01-13T21:01:40.000Z (over 3 years ago)
- Last Synced: 2025-10-01T11:53:15.783Z (8 months ago)
- Language: PHP
- Size: 52.7 KB
- Stars: 5
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Greenter GRE Api
PLATAFORMA NUEVA GRE.
### Requerimientos
- PHP 7.4 o posterior.
- `curl` extension
### Instalacion
Instalar via [Composer](https://getcomposer.org/):
```bash
composer require greenter/gre-api
```
## Uso
Primero es necesario obtener el client_id, client_secret desde el portal de SUNAT, puedes seguir la [guía oficial](https://cpe.sunat.gob.pe/sites/default/files/inline-files/Manual_Servicios_GRE.pdf).
```php
+
$password = 'password_example'; // Contraseña SOL
try {
$result = $apiInstance->getToken($grant_type, $scope, $client_id, $client_secret, $username, $password);
print_r($result);
} catch (Exception $e) {
echo 'Excepcion cuando invocaba AuthApi->getToken: ', $e->getMessage(), PHP_EOL;
}
```
Enviar comprobante
```php
$config = Greenter\Sunat\GRE\Configuration::getDefaultConfiguration()
->setAccessToken($token);
$cpeApi = new Greenter\Sunat\GRE\Api\CpeApi(
new GuzzleHttp\Client(),
$config->setHost('https://api.sunat.gob.pe/v1')
);
$greZip = file_get_contents('20161515648-09-T001-124.zip');
$doc = (new Greenter\Sunat\GRE\Model\CpeDocument())
->setArchivo((new Greenter\Sunat\GRE\Model\CpeDocumentArchivo())
->setNomArchivo('20161515648-09-T001-124.zip')
->setArcGreZip(base64_encode($greZip))
->setHashZip(hash('sha256', $greZip))
);
$result = $cpeApi->enviarCpe('20161515648-09-T001-124', $doc);
$ticket = $result->getNumTicket();
```
## Doc Models
- [ApiToken](docs/Model/ApiToken.md)
- [CpeDocument](docs/Model/CpeDocument.md)
- [CpeDocumentArchivo](docs/Model/CpeDocumentArchivo.md)
- [CpeError](docs/Model/CpeError.md)
- [CpeErrorValidation](docs/Model/CpeErrorValidation.md)
- [CpeResponse](docs/Model/CpeResponse.md)
- [StatusResponse](docs/Model/StatusResponse.md)
- [StatusResponseError](docs/Model/StatusResponseError.md)