Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Gre Api Laravel Package

greenter/gre-api

View on GitHub
Deep Wiki
Context7

Greenter GRE Api

PLATAFORMA NUEVA GRE.

Requerimientos

  • PHP 7.4 o posterior.
  • curl extension

Instalacion

Instalar via Composer:

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.

<?php
$apiInstance = new Greenter\Sunat\GRE\Api\AuthApi(
    new GuzzleHttp\Client()
);
$client_id = 'client_id_example'; // El client_id generado en menú sol
$grant_type = 'password';
$scope = 'https://api-cpe.sunat.gob.pe';
$client_secret = 'client_secret_example'; // client_secret generado en menú sol
$username = 'username_example'; // <Numero de RUC> + <Usuario SOL>
$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

$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

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle