class Facturama::Services::CfdiService
Public Class Methods
new( connection_info )
click to toggle source
Calls superclass method
# File lib/facturama/services/cfdi_service.rb, line 9 def initialize( connection_info ) super(connection_info, "") end
Public Instance Methods
create(model)
click to toggle source
———————— CRUD ————————
# File lib/facturama/services/cfdi_service.rb, line 17 def create(model) post(model, "2/cfdis") end
get_file(id, format, type)
click to toggle source
Obtiene un archivo referente a un CFDI del tipo “Issued” @param id Identificador del CFDI @param format Formato deseado ( pdf | html | xml ) @param type Tipo de comprobante ( payroll | received | issued ) @return Archivo en cuestion
# File lib/facturama/services/cfdi_service.rb, line 53 def get_file(id, format, type) resource = "api/cfdi/" + format + "/" + type + "/" + id get(resource) end
list(folio_start = -1, folio_end = -1, rfc = nil, tax_entity_name = nil, date_start = nil, date_end = nil, id_branch = nil, serie = nil, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED)
click to toggle source
Listado con todas las opciones posibles
# File lib/facturama/services/cfdi_service.rb, line 112 def list(folio_start = -1, folio_end = -1, rfc = nil, tax_entity_name = nil, date_start = nil, date_end = nil, id_branch = nil, serie = nil, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED) resource = "cfdi?type=" + type + "&status=" + status if folio_start > -1 resource += "&folioStart=" + folio_start end if folio_end > -1 resource += "&folioEnd=" + folio_end end if rfc != nil resource += "&rfc=" + rfc end if tax_entity_name != nil resource += "&taxEntityName=" + tax_entity_name end if date_start != nil resource += "&dateStart=" + date_start end if date_end != nil resource += "&dateEnd=" + date_end end if id_branch != nil resource += "&idBranch=" + id_branch end if serie != nil resource += "&serie=" + serie end get(resource) end
list_by_keyword(keyword, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED)
click to toggle source
Listado de Cfdi filtrando por palabra clave
# File lib/facturama/services/cfdi_service.rb, line 89 def list_by_keyword(keyword, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED) resource = "cfdi?type=" + type + "&status=" + status + "&keyword=" + keyword get(resource) end
list_by_rfc(rfc, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED)
click to toggle source
Listado de Cfdi filtrando por palabra RFC
# File lib/facturama/services/cfdi_service.rb, line 100 def list_by_rfc(rfc, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED) resource = "cfdi?type=" + type + "&status=" + status + "&rfc=" + rfc get(resource) end
remove(id)
click to toggle source
# File lib/facturama/services/cfdi_service.rb, line 22 def remove(id) if !id.nil? && id != "" delete("cfdi/" + id + "?type=issued") else raise( FacturamaException("El Id del cfdi a eliminar es obligatorio") ) end end
retrieve(id, type = nil)
click to toggle source
# File lib/facturama/services/cfdi_service.rb, line 32 def retrieve(id, type = nil) if type.nil? str_type = "Issued" else str_type = type end get("cfdi/" + id + "?type=#{str_type}") end
save_file(file_path, file_content_base64)
click to toggle source
Decodifica y guarda un archivo base64 en una ruta
# File lib/facturama/services/cfdi_service.rb, line 60 def save_file(file_path, file_content_base64) file_content_decoded = Base64.decode64(file_content_base64) File.open(file_path, "wb") do |f| f.write(file_content_decoded) end end
save_html(file_path, id, type = Facturama::InvoiceType::ISSUED)
click to toggle source
# File lib/facturama/services/cfdi_service.rb, line 78 def save_html(file_path, id, type = Facturama::InvoiceType::ISSUED) file_content = get_file(id, Facturama::FileFormat::HTML, type) save_file(file_path, file_content['Content']) end
save_pdf(file_path, id, type = Facturama::InvoiceType::ISSUED)
click to toggle source
# File lib/facturama/services/cfdi_service.rb, line 68 def save_pdf(file_path, id, type = Facturama::InvoiceType::ISSUED) file_content = get_file(id, Facturama::FileFormat::PDF, type) save_file(file_path, file_content['Content']) end
save_xml(file_path, id, type = Facturama::InvoiceType::ISSUED)
click to toggle source
# File lib/facturama/services/cfdi_service.rb, line 73 def save_xml(file_path, id, type = Facturama::InvoiceType::ISSUED) file_content = get_file(id, Facturama::FileFormat::XML, type) save_file(file_path, file_content['Content']) end
send_by_mail(id, email, subject, type = Facturama::InvoiceType::ISSUED)
click to toggle source
Envía el CFDI por correo, con el asunto especificado
# File lib/facturama/services/cfdi_service.rb, line 162 def send_by_mail(id, email, subject, type = Facturama::InvoiceType::ISSUED) response = post(nil,"cfdi?cfdiType=#{type}&cfdiId=#{id}&email=#{email}&subject=#{subject}") !!response['success'] end