Class: Facturama::Services::CfdiMultiService
- Inherits:
-
CrudService
- Object
- HttpService
- CrudService
- Facturama::Services::CfdiMultiService
- Defined in:
- lib/facturama/services/cfdi_multi_service.rb
Instance Method Summary collapse
-
#create(model) ⇒ Object
CFDI 3.3.
-
#create3(model) ⇒ Object
CFDI 4.0.
-
#get_file(id, format, type) ⇒ Object
Obtiene un archivo referente a un CFDI del tipo “Issued”.
-
#initialize(connection_info) ⇒ CfdiMultiService
constructor
A new instance of CfdiMultiService.
-
#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) ⇒ 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, motive, uuidReplacement) ⇒ Object
- #retrieve(id) ⇒ 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_LITE) ⇒ Object
- #save_pdf(file_path, id, type = Facturama::InvoiceType::ISSUED_LITE) ⇒ Object
- #save_xml(file_path, id, type = Facturama::InvoiceType::ISSUED_LITE) ⇒ Object
-
#send_by_mail(id, email, subject, type = Facturama::InvoiceType::ISSUED_LITE) ⇒ Object
Envía el CFDI por correo, con el asunto especificado.
Methods inherited from CrudService
Methods inherited from HttpService
Constructor Details
#initialize(connection_info) ⇒ CfdiMultiService
Returns a new instance of CfdiMultiService.
9 10 11 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 9 def initialize(connection_info) super(connection_info, '') end |
Instance Method Details
#create(model) ⇒ Object
CFDI 3.3
16 17 18 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 16 def create(model) post(model, 'api-lite/2/cfdis') end |
#create3(model) ⇒ Object
CFDI 4.0
21 22 23 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 21 def create3(model) post(model, 'api-lite/3/cfdis') end |
#get_file(id, format, type) ⇒ Object
Obtiene un archivo referente a un CFDI del tipo “Issued”
45 46 47 48 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 45 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) ⇒ Object
Listado con todas las opciones posibles
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 93 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}" resource += "&folioStart=#{folio_start}" if folio_start > -1 resource += "&folioEnd=#{folio_end}" if folio_end > -1 resource += "&rfc=#{rfc}" unless rfc.nil? resource += "&taxEntityName=#{tax_entity_name}" unless tax_entity_name.nil? resource += "&dateStart=#{date_start}" unless date_start.nil? resource += "&dateEnd=#{date_end}" unless date_end.nil? resource += "&idBranch=#{id_branch}" unless id_branch.nil? resource += "&serie=#{serie}" unless serie.nil? get(resource) end |
#list_by_keyword(keyword, status = Facturama::CfdiStatus::ACTIVE) ⇒ Object
Listado de Cfdi filtrando por palabra clave
76 77 78 79 80 81 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 76 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) ⇒ Object
Listado de Cfdi filtrando por palabra RFC
84 85 86 87 88 89 90 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 84 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, motive, uuidReplacement) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 25 def remove(id, motive, uuidReplacement) motive = '02' if motive.nil? && motive != '' uuidReplacement = '' if uuidReplacement.nil? && uuidReplacement != '' raise(FacturamaException('El Id del cfdi a eliminar es obligatorio')) unless !id.nil? && id != '' delete("api-lite/cfdis/#{id}?motive=#{motive}&uuidReplacement=#{uuidReplacement}") end |
#retrieve(id) ⇒ Object
34 35 36 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 34 def retrieve(id) get("api-lite/cfdis/#{id}") end |
#save_file(file_path, file_content_base64) ⇒ Object
Decodifica y guarda un archivo base64 en una ruta
51 52 53 54 55 56 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 51 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) ⇒ Object
68 69 70 71 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 68 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) ⇒ Object
58 59 60 61 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 58 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) ⇒ Object
63 64 65 66 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 63 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) ⇒ Object
Envía el CFDI por correo, con el asunto especificado
124 125 126 127 |
# File 'lib/facturama/services/cfdi_multi_service.rb', line 124 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 |