Class: Facturama::Services::CfdiService
- Inherits:
-
CrudService
- Object
- HttpService
- CrudService
- Facturama::Services::CfdiService
- Defined in:
- lib/facturama/services/cfdi_service.rb
Instance Method Summary collapse
- #create(model) ⇒ Object
-
#get_file(id, format, type) ⇒ Object
Obtiene un archivo referente a un CFDI del tipo “Issued”.
-
#initialize(connection_info) ⇒ CfdiService
constructor
A new instance of CfdiService.
-
#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) ⇒ Object
Listado con todas las opciones posibles.
-
#list_by_keyword(keyword, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED) ⇒ Object
Listado de Cfdi filtrando por palabra clave.
-
#list_by_rfc(rfc, status = Facturama::CfdiStatus::ACTIVE, type = Facturama::InvoiceType::ISSUED) ⇒ Object
Listado de Cfdi filtrando por palabra RFC.
- #remove(id) ⇒ Object
- #retrieve(id, type = nil) ⇒ Object
-
#save_file(file_path, file_content_base64) ⇒ Object
Decodifica y guarda un archivo base64 en una ruta.
- #save_html(file_path, id, type = Facturama::InvoiceType::ISSUED) ⇒ Object
- #save_pdf(file_path, id, type = Facturama::InvoiceType::ISSUED) ⇒ Object
- #save_xml(file_path, id, type = Facturama::InvoiceType::ISSUED) ⇒ Object
-
#send_by_mail(id, email, subject, type = Facturama::InvoiceType::ISSUED) ⇒ Object
Envía el CFDI por correo, con el asunto especificado.
Methods inherited from CrudService
Methods inherited from HttpService
Constructor Details
#initialize(connection_info) ⇒ CfdiService
Returns a new instance of CfdiService.
9 10 11 |
# File 'lib/facturama/services/cfdi_service.rb', line 9 def initialize( connection_info ) super(connection_info, "") end |
Instance Method Details
#create(model) ⇒ Object
17 18 19 |
# File 'lib/facturama/services/cfdi_service.rb', line 17 def create(model) post(model, "2/cfdis") end |
#get_file(id, format, type) ⇒ Object
Obtiene un archivo referente a un CFDI del tipo “Issued”
53 54 55 56 |
# 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) ⇒ Object
Listado con todas las opciones posibles
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# 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) ⇒ Object
Listado de Cfdi filtrando por palabra clave
89 90 91 92 93 94 95 |
# 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) ⇒ Object
Listado de Cfdi filtrando por palabra RFC
100 101 102 103 104 105 106 |
# 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) ⇒ Object
22 23 24 25 26 27 28 29 |
# 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) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
Decodifica y guarda un archivo base64 en una ruta
60 61 62 63 64 65 |
# 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) ⇒ Object
78 79 80 81 |
# 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) ⇒ Object
68 69 70 71 |
# 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) ⇒ Object
73 74 75 76 |
# 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) ⇒ Object
Envía el CFDI por correo, con el asunto especificado
162 163 164 165 |
# 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 |