sunat_cpe_dart 1.0.1
sunat_cpe_dart: ^1.0.1 copied to clipboard
Umbrella package and intelligent CPE router for Peruvian Electronic Invoicing (SUNAT Direct SOL + 9 OSE/PSE adapters) in pure Dart.
sunat_cpe_dart #
Umbrella package and intelligent CPE router (SunatCpeRouter) for Peruvian Electronic Invoicing (SUNAT CPE) in pure Dart.
Allows applications and multi-tenant ERPs to dynamically route electronic documents between direct SUNAT emission (sunat_cpe_direct) and any of the 9 OSE/PSE providers (Nubefact, EFACT, Mifact, Bizlinks, Digiflow, Sovos, FacturaloPeru, TCI, Cavali).
Features #
- Single Umbrella Import: Re-exports
sunat_cpe_core,sunat_cpe_direct, and all 9 OSE/PSE adapters. - Content-Based Routing (
routesByDocumentType): Route specificCpeDocumentTypevalues to dedicated providers (e.g., send Invoices01and Boletas03via an OSE/PSE while sending Despatch Advices09/31directly to SUNAT's REST OAuth2 API viasunat_cpe_direct). - Circuit-Safe Fallback (
fallbackProvider): Automatically fails over to a backup provider only when the document has not been registered (OseTransportExceptionorSunatExceptionErrorcodes0100–1999), never on local validation errors or formal SUNAT business rejections (2000–3999). - Automatic Ticket Origin Tracking: Remembers which provider issued each asynchronous ticket (
RC,RA,RR,09,31) socheckTicketandpollTicketUntilDonequery the exact originating provider. - Declarative Factory (
SunatProviderDescriptor&SunatProviderFactory): Instantiate single providers or fullSunatCpeRoutertopologies from typed descriptors.
Usage #
import 'package:sunat_cpe_dart/sunat_cpe_dart.dart';
void main() async {
final router = SunatCpeRouter.fromDescriptors(
primaryDescriptor: NubefactDescriptor(
NubefactConfig(
routeUri: Uri.parse('https://api.nubefact.com/api/v1/...'),
apiToken: 'NUBEFACT_TOKEN',
),
),
routeDescriptorsByDocumentType: {
CpeDocumentType.guiaRemisionRemitente: DirectSunatDescriptor(
SunatDirectConfig.beta(),
),
},
);
// Invoices route to Nubefact; Despatch Advices route to SunatDirectProvider!
}