class Facturama::Services::CfdiMultiService

Public Class Methods

new( connection_info ) click to toggle source
Calls superclass method
# File lib/facturama/services/cfdi_multi_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_multi_service.rb, line 17
def create(model)
    post(model, "api-lite/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_multi_service.rb, line 46
def get_file(id, format, type)
    resource = "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_multi_service.rb, line 104
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 = "api-lite/cfdis?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) click to toggle source

Listado de Cfdi filtrando por palabra clave

# File lib/facturama/services/cfdi_multi_service.rb, line 82
def list_by_keyword(keyword,
         status = Facturama::CfdiStatus::ACTIVE)

    resource = "api-lite/cfdis?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_multi_service.rb, line 92
def list_by_rfc(rfc,
        status = Facturama::CfdiStatus::ACTIVE,
        type = Facturama::InvoiceType::ISSUED)

    resource = "api-lite/cfdis?status=" + status + "&rfc=" + rfc
    get(resource)
end
remove(id) click to toggle source
# File lib/facturama/services/cfdi_multi_service.rb, line 22
def remove(id)

    if !id.nil? && id != ""
        delete("api-lite/cfdis/" + id )
    else
        raise( FacturamaException("El Id del cfdi a eliminar es obligatorio") )
    end
end
retrieve(id) click to toggle source
# File lib/facturama/services/cfdi_multi_service.rb, line 32
def retrieve(id)
    get("api-lite/cfdis/" + id )
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_multi_service.rb, line 53
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_LITE) click to toggle source
# File lib/facturama/services/cfdi_multi_service.rb, line 71
def save_html(file_path, id, type = Facturama::InvoiceType::ISSUED_LITE)
    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_LITE) click to toggle source
# File lib/facturama/services/cfdi_multi_service.rb, line 61
def save_pdf(file_path, id, type = Facturama::InvoiceType::ISSUED_LITE)
    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_LITE) click to toggle source
# File lib/facturama/services/cfdi_multi_service.rb, line 66
def save_xml(file_path, id, type = Facturama::InvoiceType::ISSUED_LITE)
    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_LITE) click to toggle source

Envía el CFDI por correo, con el asunto especificado

# File lib/facturama/services/cfdi_multi_service.rb, line 154
def send_by_mail(id, email, subject, type = Facturama::InvoiceType::ISSUED_LITE)
    response = post(nil,"cfdi?cfdiType=#{type}&cfdiId=#{id}&email=#{email}&subject=#{subject}")
    !!response['success']
end