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

Afip Bundle Laravel Package

eesnaola/afip-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require eesnaola/afip-bundle
    

    Publish the configuration file (if needed):

    php artisan vendor:publish --provider="Eesnaola\AfipBundle\AfipServiceProvider" --tag="config"
    
  2. First Use Case: CAE Request Register the service in your config/app.php under providers:

    Eesnaola\AfipBundle\AfipServiceProvider::class,
    

    Bind the AFIP client in a service provider or use the facade:

    use Eesnaola\AfipBundle\Facades\Afip;
    
    $response = Afip::cae()->request([
        'cuit' => '20123456789',
        'descripcion' => 'Mi producto',
        'importe' => 1000.00,
    ]);
    
  3. Configuration Update .env with AFIP credentials (e.g., AFIP_CERT_PATH, AFIP_CERT_PASSWORD, AFIP_CUIT). Example .env entries:

    AFIP_CERT_PATH=/path/to/cert.pem
    AFIP_CERT_PASSWORD=your_password
    AFIP_CUIT=20123456789
    AFIP_ENV=production  # or 'test'
    

Implementation Patterns

Workflows

  1. Request-Response Cycle Use the fluent interface for AFIP services (e.g., CAE, Comprobante, WSME):

    $cae = Afip::cae()
        ->setCuit($cuit)
        ->setConcept(1) // e.g., 'Mantenimiento'
        ->setImpTotal(1000.00)
        ->request();
    
  2. Comprobante (Invoice) Management Generate, sign, and send invoices:

    $comprobante = Afip::comprobante()
        ->setType('A') // Factura A
        ->setPtoVta(1)
        ->setCbteNro(1)
        ->setFecha(new \DateTime())
        ->addItem($item1, $item2)
        ->sign()
        ->send();
    
  3. Web Services (WSME) For real-time validations (e.g., CUIT, IBAN):

    $response = Afip::wsme()->validateCuit('20123456789');
    

Integration Tips

  • Laravel Events Trigger custom events post-AFIP response for logging/auditing:
    event(new AfipResponseEvent($response));
    
  • Queue Jobs Offload AFIP requests to queues (e.g., AfipRequestJob):
    dispatch(new AfipRequestJob($requestData));
    
  • API Resources Transform AFIP responses into API-friendly formats:
    return new AfipResource($response->toArray());
    

Gotchas and Tips

Pitfalls

  1. Certificate Handling

    • Ensure AFIP_CERT_PATH points to a valid PEM file (not .key or .crt).
    • Test locally with a self-signed cert for development:
      openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
      
    • Error: openssl_error_string() may return error:0906A068:PEM routines:PEM_do_header:bad password read if the password is incorrect.
  2. Environment Mismatch

    • The package lacks explicit test/production logic. Override the getEnvironment() method in your service provider:
      $this->app->bind('afip.environment', function() {
          return env('AFIP_ENV') === 'test' ? 'test' : 'production';
      });
      
  3. Deprecated PHP 7.4 Features

    • Avoid create_function() or call_user_func_array() with dynamic arguments (use closures instead).
    • Fix: Update any legacy code calling call_user_func() with static arrays.
  4. CUIT Validation

    • AFIP’s CUIT validation is strict. Use Afip::wsme()->validateCuit() before processing:
      if (!Afip::wsme()->validateCuit($cuit)) {
          throw new \InvalidArgumentException("CUIT inválido");
      }
      

Debugging

  • Enable Logging Add to config/afip.php:

    'debug' => env('AFIP_DEBUG', false),
    'log_path' => storage_path('logs/afip.log'),
    

    Logs will include raw requests/responses for troubleshooting.

  • SoapClient Errors If you see SOAP-ERROR: Encoding: object has no '...' property, ensure your request DTO matches AFIP’s WSDL schema. Use Afip::wsdl() to inspect:

    dd(Afip::wsdl()->getTypes());
    

Extension Points

  1. Custom Services Extend the base AfipService class to add domain-specific methods:

    class CustomAfipService extends \Eesnaola\AfipBundle\Services\AfipService {
        public function customRequest(array $data) {
            return $this->client->__soapCall('CustomMethod', [$data]);
        }
    }
    
  2. Middleware Add AFIP-specific middleware to validate requests before processing:

    public function handle($request, Closure $next) {
        if ($request->afip_required && !Afip::wsme()->validateCuit($request->cuit)) {
            abort(403, 'CUIT no válido');
        }
        return $next($request);
    }
    
  3. Testing Mock the AFIP client in tests:

    $mock = Mockery::mock('\Eesnaola\AfipBundle\Services\AfipService');
    $mock->shouldReceive('cae->request')->andReturn(['result' => 'ok']);
    $this->app->instance('afip', $mock);
    
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.
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
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui