Documentation
¶
Overview ¶
Package sunatlib provides functionality for SUNAT electronic document validation
Package sunatlib defines SUNAT service endpoints ¶
Package sunatlib provides XML digital signature functionality for SUNAT Peru ¶
Package sunatlib provides document validation functionality for SUNAT Peru ¶
Package sunatlib provides functionality for SUNAT voided documents (comunicación de baja)
Index ¶
- Constants
- func GenerateVoidedDocumentsSeries(referenceDate time.Time, sequential int) string
- func GetBillServiceEndpoint(env Environment) string
- func GetGuideServiceEndpoint(env Environment) string
- func GetRetentionServiceEndpoint(env Environment) string
- func GetValidationServiceEndpoint(env Environment) string
- func IsValidCE(ce string) bool
- func IsValidDNI(dni string) bool
- func IsValidRUC(ruc string) bool
- type ConsultationClient
- func (c *ConsultationClient) ConsultCE(ce string) (*DNIResponse, error)
- func (c *ConsultationClient) ConsultDNI(dni string) (*DNIResponse, error)
- func (c *ConsultationClient) ConsultRUC(ruc string) (*RUCBasicResponse, error)
- func (c *ConsultationClient) ConsultRUCFull(ruc string) (*RUCFullResponse, error)
- type DNIData
- type DNIResponse
- type DNIService
- type DocumentValidationClient
- func (c *DocumentValidationClient) CheckDocumentStatus(ruc, documentType, series, number string) (*ValidationResponse, error)
- func (c *DocumentValidationClient) ValidateCreditNote(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
- func (c *DocumentValidationClient) ValidateDebitNote(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
- func (c *DocumentValidationClient) ValidateDocument(req *ValidationRequest) (*ValidationResponse, error)
- func (c *DocumentValidationClient) ValidateInvoice(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
- func (c *DocumentValidationClient) ValidateReceipt(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
- type Environment
- type EsSaludResponse
- type RUCBasicData
- type RUCBasicResponse
- type RUCFullData
- type RUCFullResponse
- type RUCService
- type SUNATClient
- func (c *SUNATClient) BatchQueryTickets(tickets []string) ([]*TicketStatusResponse, error)
- func (c *SUNATClient) Cleanup() error
- func (c *SUNATClient) GenerateVoidedDocumentsXML(request *VoidedDocumentsRequest) ([]byte, error)
- func (c *SUNATClient) GetVoidedDocumentsStatus(ticket string) (*SUNATResponse, error)
- func (c *SUNATClient) QueryVoidedDocumentsTicket(ticket string) (*TicketStatusResponse, error)
- func (c *SUNATClient) SendToSUNAT(signedXML []byte, documentType, seriesNumber string) (*SUNATResponse, error)
- func (c *SUNATClient) SendVoidedDocuments(request *VoidedDocumentsRequest) (*VoidedDocumentsResponse, error)
- func (c *SUNATClient) SetCertificate(privateKeyPath, certificatePath string) error
- func (c *SUNATClient) SetCertificateFromPFX(pfxPath, password, tempDir string) error
- func (c *SUNATClient) SignAndSendInvoice(xmlContent []byte, documentType, seriesNumber string) (*SUNATResponse, error)
- func (c *SUNATClient) SignXML(xmlContent []byte) ([]byte, error)
- func (c *SUNATClient) WaitForTicketProcessing(ticket string, maxWaitTime time.Duration, pollInterval time.Duration) (*TicketStatusResponse, error)
- type SUNATResponse
- type SunatRawResponse
- type TicketStatusResponse
- func (r *TicketStatusResponse) GetApplicationResponse() []byte
- func (r *TicketStatusResponse) GetTicketStatusDescription() string
- func (r *TicketStatusResponse) HasApplicationResponse() bool
- func (r *TicketStatusResponse) HasErrors() bool
- func (r *TicketStatusResponse) IsInProgress() bool
- func (r *TicketStatusResponse) IsProcessed() bool
- func (r *TicketStatusResponse) IsSuccessful() bool
- type ValidationClient
- func (vc *ValidationClient) ValidateDocument(params *ValidationParams) (*ValidationResult, error)
- func (vc *ValidationClient) ValidateInvoice(issuerRUC, seriesNumber, documentNumber, issueDate string, totalAmount float64) (*ValidationResult, error)
- func (vc *ValidationClient) ValidateReceipt(issuerRUC, seriesNumber, documentNumber, issueDate string, totalAmount float64) (*ValidationResult, error)
- type ValidationParams
- type ValidationRequest
- type ValidationResponse
- type ValidationResult
- type ValidationSOAPResponse
- type VoidedDocument
- type VoidedDocumentsRequest
- type VoidedDocumentsResponse
Constants ¶
const ( // Production endpoints for electronic invoicing SUNATProductionBillService = "https://e-factura.sunat.gob.pe/ol-ti-itcpfegem/billService" SUNATProductionRetentionService = "https://e-factura.sunat.gob.pe/ol-ti-itemision-otroscpe-gem/billService" SUNATProductionGuideService = "https://e-factura.sunat.gob.pe/ol-ti-itemision-guia-gem/billService" // Production endpoint for document validation SUNATProductionValidationService = "https://e-factura.sunat.gob.pe/ol-it-wsconsvalidcpe/billValidService" )
SUNAT Production Endpoints
const ( // Beta endpoints for electronic invoicing (testing) SUNATBetaBillService = "https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService" SUNATBetaRetentionService = "https://e-beta.sunat.gob.pe/ol-ti-itemision-otroscpe-gem-beta/billService" SUNATBetaGuideService = "https://e-beta.sunat.gob.pe/ol-ti-itemision-guia-gem-beta/billService" // Beta endpoint for document validation (testing) SUNATBetaValidationService = "https://e-beta.sunat.gob.pe/ol-it-wsconsvalidcpe/billValidService" )
SUNAT Beta/Testing Endpoints
Variables ¶
This section is empty.
Functions ¶
func GenerateVoidedDocumentsSeries ¶ added in v1.3.0
GenerateVoidedDocumentsSeries generates a series number for voided documents Format: RA-YYYYMMDD-### where ### is a sequential number
func GetBillServiceEndpoint ¶ added in v1.3.0
func GetBillServiceEndpoint(env Environment) string
GetBillServiceEndpoint returns the appropriate billService endpoint based on environment
func GetGuideServiceEndpoint ¶ added in v1.3.0
func GetGuideServiceEndpoint(env Environment) string
GetGuideServiceEndpoint returns the appropriate guide service endpoint based on environment
func GetRetentionServiceEndpoint ¶ added in v1.3.0
func GetRetentionServiceEndpoint(env Environment) string
GetRetentionServiceEndpoint returns the appropriate retention/perception service endpoint based on environment
func GetValidationServiceEndpoint ¶ added in v1.3.0
func GetValidationServiceEndpoint(env Environment) string
GetValidationServiceEndpoint returns the appropriate validation service endpoint based on environment
func IsValidDNI ¶ added in v1.2.0
IsValidDNI validates if a DNI number has the correct format
func IsValidRUC ¶ added in v1.2.0
IsValidRUC validates if a RUC number has the correct format
Types ¶
type ConsultationClient ¶ added in v1.2.0
type ConsultationClient struct {
// contains filtered or unexported fields
}
ConsultationClient handles RUC and DNI consultation services independently
func NewConsultationClient ¶ added in v1.2.0
func NewConsultationClient(apiKey string) *ConsultationClient
NewConsultationClient creates a new consultation client with both services apiKey is kept for backward compatibility but optional for RUC since it now uses direct SUNAT API
func NewDNIConsultationClient ¶ added in v1.2.0
func NewDNIConsultationClient() *ConsultationClient
NewDNIConsultationClient creates a client only for DNI/CE consultation (free)
func NewRUCConsultationClient ¶ added in v1.2.0
func NewRUCConsultationClient(apiKey string) *ConsultationClient
NewRUCConsultationClient creates a client only for RUC consultation apiKey is kept for backward compatibility but optional since it now uses direct SUNAT API
func (*ConsultationClient) ConsultCE ¶ added in v1.2.0
func (c *ConsultationClient) ConsultCE(ce string) (*DNIResponse, error)
ConsultCE performs a Carnet de Extranjería consultation
func (*ConsultationClient) ConsultDNI ¶ added in v1.2.0
func (c *ConsultationClient) ConsultDNI(dni string) (*DNIResponse, error)
ConsultDNI performs a DNI consultation
func (*ConsultationClient) ConsultRUC ¶ added in v1.2.0
func (c *ConsultationClient) ConsultRUC(ruc string) (*RUCBasicResponse, error)
ConsultRUC performs a basic RUC consultation
func (*ConsultationClient) ConsultRUCFull ¶ added in v1.2.0
func (c *ConsultationClient) ConsultRUCFull(ruc string) (*RUCFullResponse, error)
ConsultRUCFull performs a complete RUC consultation
type DNIData ¶ added in v1.2.0
type DNIData struct {
DNI string `json:"dni"`
NombreCompleto string `json:"nombre_completo"`
Nombres string `json:"nombres"`
ApellidoPaterno string `json:"apellido_paterno"`
ApellidoMaterno string `json:"apellido_materno"`
FechaNacimiento string `json:"fecha_nacimiento,omitempty"`
Sexo string `json:"sexo,omitempty"`
EstadoCivil string `json:"estado_civil,omitempty"`
}
DNIData contains personal information from RENIEC
type DNIResponse ¶ added in v1.2.0
type DNIResponse struct {
Success bool `json:"success"`
Data *DNIData `json:"data,omitempty"`
Message string `json:"message,omitempty"`
}
DNIResponse represents the response from EsSalud DNI validation service
type DNIService ¶ added in v1.2.0
DNIService handles DNI consultation operations
func NewDNIService ¶ added in v1.2.0
func NewDNIService() *DNIService
NewDNIService creates a new DNI service instance
func (*DNIService) ConsultCE ¶ added in v1.2.0
func (ds *DNIService) ConsultCE(ce string) (*DNIResponse, error)
ConsultCE performs a Carnet de Extranjería consultation
func (*DNIService) ConsultDNI ¶ added in v1.2.0
func (ds *DNIService) ConsultDNI(dni string) (*DNIResponse, error)
ConsultDNI performs a DNI consultation using EsSalud service
type DocumentValidationClient ¶ added in v1.3.0
type DocumentValidationClient struct {
RUC string
Username string
Password string
Endpoint string
Client *http.Client
}
DocumentValidationClient handles document validation requests to SUNAT
func NewDocumentValidationClient ¶ added in v1.3.0
func NewDocumentValidationClient(ruc, username, password string) *DocumentValidationClient
NewDocumentValidationClient creates a new document validation client with credentials (PRODUCTION)
func NewDocumentValidationClientBeta ¶ added in v1.3.0
func NewDocumentValidationClientBeta(ruc, username, password string) *DocumentValidationClient
NewDocumentValidationClientBeta creates a new document validation client for BETA testing
func NewDocumentValidationClientWithCredentials ¶ added in v1.3.0
func NewDocumentValidationClientWithCredentials(ruc, username, password string) *DocumentValidationClient
NewDocumentValidationClientWithCredentials creates a new document validation client with SUNAT credentials (PRODUCTION)
func (*DocumentValidationClient) CheckDocumentStatus ¶ added in v1.3.0
func (c *DocumentValidationClient) CheckDocumentStatus(ruc, documentType, series, number string) (*ValidationResponse, error)
CheckDocumentStatus checks the status of a document using basic parameters
func (*DocumentValidationClient) ValidateCreditNote ¶ added in v1.3.0
func (c *DocumentValidationClient) ValidateCreditNote(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
ValidateCreditNote validates an electronic credit note
func (*DocumentValidationClient) ValidateDebitNote ¶ added in v1.3.0
func (c *DocumentValidationClient) ValidateDebitNote(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
ValidateDebitNote validates an electronic debit note
func (*DocumentValidationClient) ValidateDocument ¶ added in v1.3.0
func (c *DocumentValidationClient) ValidateDocument(req *ValidationRequest) (*ValidationResponse, error)
ValidateDocument validates an electronic document with SUNAT using SOAP
func (*DocumentValidationClient) ValidateInvoice ¶ added in v1.3.0
func (c *DocumentValidationClient) ValidateInvoice(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
ValidateInvoice validates an electronic invoice
func (*DocumentValidationClient) ValidateReceipt ¶ added in v1.3.0
func (c *DocumentValidationClient) ValidateReceipt(ruc, series, number, issueDate, totalAmount string) (*ValidationResponse, error)
ValidateReceipt validates an electronic receipt (boleta)
type Environment ¶ added in v1.3.0
type Environment int
Environment types
const ( Production Environment = iota Beta )
type EsSaludResponse ¶ added in v1.2.0
type EsSaludResponse struct {
Datos string `json:"datos"` // Nombre completo
Apellidos string `json:"apellidos"` // Apellidos completos
Nombres string `json:"nombres"` // Solo nombres
// Campos alternativos por si cambia el formato
NumeroDocumento string `json:"numeroDocumento"`
TipoDocumento string `json:"tipoDocumento"`
ApellidoPaterno string `json:"apellidoPaterno"`
ApellidoMaterno string `json:"apellidoMaterno"`
NombreCompleto string `json:"nombreCompleto"`
}
EsSaludResponse represents the raw response from EsSalud service
type RUCBasicData ¶ added in v1.2.0
type RUCBasicData struct {
RUC string `json:"numero_documento"`
RazonSocial string `json:"razon_social"`
Estado string `json:"estado"`
Condicion string `json:"condicion"`
Direccion string `json:"direccion"`
Ubigeo string `json:"ubigeo"`
Distrito string `json:"distrito"`
Provincia string `json:"provincia"`
Departamento string `json:"departamento"`
EsAgenteRetencion bool `json:"es_agente_retencion"`
EsBuenContribuyente bool `json:"es_buen_contribuyente"`
ViaTipo string `json:"via_tipo"`
ViaNombre string `json:"via_nombre"`
ZonaCodigo string `json:"zona_codigo"`
ZonaTipo string `json:"zona_tipo"`
Numero string `json:"numero"`
Interior string `json:"interior"`
}
RUCBasicData contains basic company information
type RUCBasicResponse ¶ added in v1.2.0
type RUCBasicResponse struct {
Success bool `json:"success"`
Data *RUCBasicData `json:"data,omitempty"`
Message string `json:"message,omitempty"`
}
RUCBasicResponse represents the standard response format
type RUCFullData ¶ added in v1.2.0
type RUCFullData struct {
RUCBasicData
ActividadEconomica string `json:"actividad_economica"`
NumeroTrabajadores string `json:"numero_trabajadores"`
TipoFacturacion string `json:"tipo_facturacion"`
TipoContabilidad string `json:"tipo_contabilidad"`
ComercioExterior string `json:"comercio_exterior"`
FechaInscripcion string `json:"fecha_inscripcion"`
}
RUCFullData contains complete company information
type RUCFullResponse ¶ added in v1.2.0
type RUCFullResponse struct {
Success bool `json:"success"`
Data *RUCFullData `json:"data,omitempty"`
Message string `json:"message,omitempty"`
}
RUCFullResponse represents the response with full data (if available)
type RUCService ¶ added in v1.2.0
RUCService handles RUC consultation operations
func NewRUCService ¶ added in v1.2.0
func NewRUCService(apiKey string) *RUCService
NewRUCService creates a new RUC service instance (apiKey is kept for backward compatibility but unused)
func (*RUCService) ConsultBasic ¶ added in v1.2.0
func (rs *RUCService) ConsultBasic(ruc string) (*RUCBasicResponse, error)
ConsultBasic performs a basic RUC consultation using SUNAT's direct API
func (*RUCService) ConsultFull ¶ added in v1.2.0
func (rs *RUCService) ConsultFull(ruc string) (*RUCFullResponse, error)
ConsultFull performs a RUC consultation (limited data due to simplified API)
type SUNATClient ¶
type SUNATClient struct {
RUC string
Username string
Password string
Endpoint string
// contains filtered or unexported fields
}
SUNATClient handles interactions with SUNAT web services for electronic billing
func NewSUNATClient ¶
func NewSUNATClient(ruc, username, password, endpoint string) *SUNATClient
NewSUNATClient creates a new SUNAT client for electronic billing
func NewVoidedDocumentsClient ¶ added in v1.3.0
func NewVoidedDocumentsClient(ruc, username, password string) *SUNATClient
NewVoidedDocumentsClient creates a new SUNAT client for voided documents (PRODUCTION)
func NewVoidedDocumentsClientBeta ¶ added in v1.3.0
func NewVoidedDocumentsClientBeta(ruc, username, password string) *SUNATClient
NewVoidedDocumentsClientBeta creates a new SUNAT client for voided documents (BETA/Testing)
func (*SUNATClient) BatchQueryTickets ¶ added in v1.4.0
func (c *SUNATClient) BatchQueryTickets(tickets []string) ([]*TicketStatusResponse, error)
BatchQueryTickets queries multiple tickets and returns their status
func (*SUNATClient) Cleanup ¶
func (c *SUNATClient) Cleanup() error
Cleanup cleans up temporary files
func (*SUNATClient) GenerateVoidedDocumentsXML ¶ added in v1.3.0
func (c *SUNATClient) GenerateVoidedDocumentsXML(request *VoidedDocumentsRequest) ([]byte, error)
GenerateVoidedDocumentsXML generates the XML for voided documents communication
func (*SUNATClient) GetVoidedDocumentsStatus ¶ added in v1.3.0
func (c *SUNATClient) GetVoidedDocumentsStatus(ticket string) (*SUNATResponse, error)
GetVoidedDocumentsStatus checks the status of a voided documents communication using the ticket
func (*SUNATClient) QueryVoidedDocumentsTicket ¶ added in v1.4.0
func (c *SUNATClient) QueryVoidedDocumentsTicket(ticket string) (*TicketStatusResponse, error)
QueryVoidedDocumentsTicket queries the status of a voided documents communication ticket This is a more specific and enhanced version of GetVoidedDocumentsStatus
func (*SUNATClient) SendToSUNAT ¶ added in v1.1.0
func (c *SUNATClient) SendToSUNAT(signedXML []byte, documentType, seriesNumber string) (*SUNATResponse, error)
SendToSUNAT sends a signed XML document to SUNAT
func (*SUNATClient) SendVoidedDocuments ¶ added in v1.3.0
func (c *SUNATClient) SendVoidedDocuments(request *VoidedDocumentsRequest) (*VoidedDocumentsResponse, error)
SendVoidedDocuments sends voided documents communication to SUNAT
func (*SUNATClient) SetCertificate ¶
func (c *SUNATClient) SetCertificate(privateKeyPath, certificatePath string) error
SetCertificate configures the XML signer with certificate files
func (*SUNATClient) SetCertificateFromPFX ¶
func (c *SUNATClient) SetCertificateFromPFX(pfxPath, password, tempDir string) error
SetCertificateFromPFX extracts and configures certificate from PFX file
func (*SUNATClient) SignAndSendInvoice ¶
func (c *SUNATClient) SignAndSendInvoice(xmlContent []byte, documentType, seriesNumber string) (*SUNATResponse, error)
SignAndSendInvoice signs an XML invoice and sends it to SUNAT (convenience method)
func (*SUNATClient) SignXML ¶ added in v1.1.0
func (c *SUNATClient) SignXML(xmlContent []byte) ([]byte, error)
SignXML signs an XML document and returns the signed XML
func (*SUNATClient) WaitForTicketProcessing ¶ added in v1.4.0
func (c *SUNATClient) WaitForTicketProcessing(ticket string, maxWaitTime time.Duration, pollInterval time.Duration) (*TicketStatusResponse, error)
WaitForTicketProcessing waits for a ticket to be processed, polling every interval Returns the final status response when processing is complete or timeout is reached
type SUNATResponse ¶
type SUNATResponse struct {
Success bool
Message string
ResponseXML []byte
ApplicationResponse []byte
Error error
}
SUNATResponse represents the response from SUNAT
func (*SUNATResponse) SaveApplicationResponse ¶
func (r *SUNATResponse) SaveApplicationResponse(outputPath string) error
SaveApplicationResponse saves the CDR (Constancia de Recepción) to a file
type SunatRawResponse ¶ added in v1.6.0
type SunatRawResponse struct {
Message string `json:"message"`
Lista []struct {
IdProvincia string `json:"idprovincia"`
IdDistrito string `json:"iddistrito"`
RazonSocial string `json:"apenomdenunciado"`
IdDepartamento string `json:"iddepartamento"`
Direccion string `json:"direstablecimiento"`
DesDistrito string `json:"desdistrito"`
DesProvincia string `json:"desprovincia"`
DesDepartamento string `json:"desdepartamento"`
} `json:"lista"`
}
SunatRawResponse represents the direct response from SUNAT service
type TicketStatusResponse ¶ added in v1.4.0
type TicketStatusResponse struct {
Success bool
Message string
Ticket string
StatusCode string // SUNAT status code
StatusDescription string // SUNAT status description
ProcessDate time.Time // Date when the document was processed
ResponseXML []byte // Full SOAP response
ApplicationResponse []byte // CDR ZIP content if available
Error error
}
TicketStatusResponse represents the response from ticket status query
func (*TicketStatusResponse) GetApplicationResponse ¶ added in v1.4.0
func (r *TicketStatusResponse) GetApplicationResponse() []byte
GetApplicationResponse returns the CDR response data if available
func (*TicketStatusResponse) GetTicketStatusDescription ¶ added in v1.4.0
func (r *TicketStatusResponse) GetTicketStatusDescription() string
GetTicketStatusDescription returns a human-readable description of the ticket status
func (*TicketStatusResponse) HasApplicationResponse ¶ added in v1.4.0
func (r *TicketStatusResponse) HasApplicationResponse() bool
HasApplicationResponse returns true if CDR response data is available
func (*TicketStatusResponse) HasErrors ¶ added in v1.4.0
func (r *TicketStatusResponse) HasErrors() bool
HasErrors returns true if the ticket was processed but with errors
func (*TicketStatusResponse) IsInProgress ¶ added in v1.4.0
func (r *TicketStatusResponse) IsInProgress() bool
IsInProgress returns true if the ticket is still being processed
func (*TicketStatusResponse) IsProcessed ¶ added in v1.4.0
func (r *TicketStatusResponse) IsProcessed() bool
IsProcessed returns true if the ticket has been processed (successfully or with errors)
func (*TicketStatusResponse) IsSuccessful ¶ added in v1.4.0
func (r *TicketStatusResponse) IsSuccessful() bool
IsSuccessful returns true if the ticket was processed successfully
type ValidationClient ¶ added in v1.5.0
type ValidationClient struct {
// contains filtered or unexported fields
}
ValidationClient handles SUNAT document validation with master credentials
func NewValidationClient ¶ added in v1.5.0
func NewValidationClient(masterRUC, masterUsername, masterPassword string) *ValidationClient
NewValidationClient creates a new SUNAT validation client with master credentials
func (*ValidationClient) ValidateDocument ¶ added in v1.5.0
func (vc *ValidationClient) ValidateDocument(params *ValidationParams) (*ValidationResult, error)
ValidateDocument validates a document with SUNAT using master credentials
func (*ValidationClient) ValidateInvoice ¶ added in v1.5.0
func (vc *ValidationClient) ValidateInvoice(issuerRUC, seriesNumber, documentNumber, issueDate string, totalAmount float64) (*ValidationResult, error)
ValidateInvoice is a convenience method for validating invoices
func (*ValidationClient) ValidateReceipt ¶ added in v1.5.0
func (vc *ValidationClient) ValidateReceipt(issuerRUC, seriesNumber, documentNumber, issueDate string, totalAmount float64) (*ValidationResult, error)
ValidateReceipt is a convenience method for validating receipts
type ValidationParams ¶ added in v1.5.0
type ValidationParams struct {
IssuerRUC string // RUC of the document issuer
DocumentType string // Document type code (01=Invoice, 03=Receipt, etc.)
SeriesNumber string // Series of the document (e.g., F001)
DocumentNumber string // Document number (e.g., 00000001)
RecipientDocType string // Recipient document type ("-" for default)
RecipientDocNumber string // Recipient document number ("" for default)
IssueDate string // Issue date in YYYY-MM-DD format
TotalAmount float64 // Total amount of the document
AuthorizationNumber string // Authorization number (usually empty)
}
ValidationParams contains the parameters for document validation
type ValidationRequest ¶ added in v1.3.0
type ValidationRequest struct {
RUC string // Issuer RUC
DocumentType string // Document type code
Series string // Document series
Number string // Document number
IssueDate string // Issue date (DD/MM/YYYY)
TotalAmount string // Total amount
RecipientDocumentType string // Recipient document type (optional, use "-" for empty)
RecipientDocument string // Recipient document number (optional)
AuthorizationNumber string // Authorization number (optional)
}
ValidationRequest represents a document validation request
type ValidationResponse ¶ added in v1.3.0
type ValidationResponse struct {
Success bool
IsValid bool
StatusMessage string
ErrorMessage string
ResponseXML []byte
}
ValidationResponse represents the response from SUNAT validation service
func (*ValidationResponse) GetErrorMessage ¶ added in v1.3.0
func (vr *ValidationResponse) GetErrorMessage() string
GetErrorMessage returns the error message if any
func (*ValidationResponse) GetStatusDescription ¶ added in v1.3.0
func (vr *ValidationResponse) GetStatusDescription() string
GetStatusDescription returns a human-readable status description
func (*ValidationResponse) HasError ¶ added in v1.3.0
func (vr *ValidationResponse) HasError() bool
HasError returns true if there was an error in validation
func (*ValidationResponse) IsDocumentValid ¶ added in v1.3.0
func (vr *ValidationResponse) IsDocumentValid() bool
IsDocumentValid returns true if the document is valid
type ValidationResult ¶ added in v1.5.0
type ValidationResult struct {
Success bool `json:"success"`
IsValid bool `json:"is_valid"`
StatusCode string `json:"status_code"`
StatusMessage string `json:"status_message"`
ErrorDetails string `json:"error_details,omitempty"`
State string `json:"state"` // VALIDO, NO_INFORMADO, ANULADO, RECHAZADO
ResponseXML string `json:"response_xml,omitempty"` // Raw XML response from SUNAT
}
ValidationResult contains the result of SUNAT validation
type ValidationSOAPResponse ¶ added in v1.3.0
type ValidationSOAPResponse struct {
XMLName xml.Name `xml:"Envelope"`
Body struct {
ValidaCDPResponse struct {
StatusCode string `xml:"statusCode"`
StatusMessage string `xml:"statusMessage"`
CDPValidated string `xml:"cdpvalidado"`
} `xml:"validaCDPcriteriosResponse"`
Fault struct {
FaultCode string `xml:"faultcode"`
FaultString string `xml:"faultstring"`
} `xml:"Fault"`
} `xml:"Body"`
}
ValidationSOAPResponse represents the SOAP response structure
type VoidedDocument ¶ added in v1.3.0
type VoidedDocument struct {
DocumentTypeCode string // Document type code (01=Invoice, 03=Receipt, etc.)
DocumentSeries string // Document series (e.g., "F001", "B001")
DocumentNumber string // Document correlative number
VoidedReason string // Reason for voiding the document
}
VoidedDocument represents a document to be voided
func (*VoidedDocument) Validate ¶ added in v1.3.0
func (doc *VoidedDocument) Validate() error
Validate validates a single voided document
type VoidedDocumentsRequest ¶ added in v1.3.0
type VoidedDocumentsRequest struct {
RUC string // Company RUC
CompanyName string // Company name/reason social
SeriesNumber string // Voided document series number (RA-YYYYMMDD-###)
IssueDate time.Time // Issue date
ReferenceDate time.Time // Reference date (date of voided documents)
Documents []VoidedDocument // List of documents to void
Description string // Description of the voiding communication
}
VoidedDocumentsRequest represents a voided documents communication request
func (*VoidedDocumentsRequest) Validate ¶ added in v1.3.0
func (req *VoidedDocumentsRequest) Validate() error
Validate validates the voided documents request
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package main demonstrates the correct usage of the library following best practices The library provides data, users decide what to do with it
|
Package main demonstrates the correct usage of the library following best practices The library provides data, users decide what to do with it |
|
Package signer provides XML digital signature functionality for SUNAT Peru
|
Package signer provides XML digital signature functionality for SUNAT Peru |
|
Package utils provides certificate and utility functions for SUNAT XML signing
|
Package utils provides certificate and utility functions for SUNAT XML signing |