facturapi_ruby 1.1.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab0caea89362d23d2923e2c672d65ba7e46db5f7cd7074fc0fef9eb770f54c36
4
- data.tar.gz: 15060598f91e6b48b395529a4f631900e057394b7f930dad0aa5cab5598f63d0
3
+ metadata.gz: 1722b0098ee0ef6f187c3b3cb441513a415b388297ef4536ae4635d851254a39
4
+ data.tar.gz: 2ad3ee1d392a64bdade337461b896dd990339ed001af02afc0e7cf9ddb4151b9
5
5
  SHA512:
6
- metadata.gz: 5be6592e81eaa321eef0c1d8f86b3cadcfe4877f36173b40721334b64d9ff0329d6a48eb224b761acf47375095bcdc9db92f010bc8456d7f12ae365bba6a753b
7
- data.tar.gz: 35da256d672fda82e32b4d932863848d553dda0da5083885895db697f6170c18c4b32da23fce5b723be16a9a7fe7a89f6007fb97c569258e8018ede5173a32a1
6
+ metadata.gz: f9b1155dd14026c3aaece114fda81239aa156c5f8ff5c3cf7a2637ab3b5db620ae24c3f0fb7f429e9a89d31a92c588b1ce956e5344a68e35f22fc3af8c76402a
7
+ data.tar.gz: 208890f3f4a05ea90f494e35bfcb3a505788510e8e365dcb84d0b09e56419900ba6b6fb08f54bf2ed6b3d3ab524771c00b230c4fc841a8f2ef50abdb8e75b212
@@ -1,9 +1,10 @@
1
1
  module FacturapiRuby
2
2
  class Configuration
3
- attr_accessor :api_key
3
+ attr_accessor :api_key, :debug_output
4
4
 
5
5
  def initialize
6
6
  @api_key = ''
7
+ @debug_output = true
7
8
  end
8
9
  end
9
10
  end
@@ -101,4 +101,42 @@ module FacturapiRuby
101
101
  ENAJENACION_DE_ACCIONES_EN_BOLSA_DE_VALORES: "630",
102
102
  REGIMEN_DE_LOS_INGRESOS_POR_OBTENCION_DE_PREMIOS: "615"
103
103
  }
104
+
105
+ REGIMEN_FISCAL = {
106
+ '603': 'Personas Morales con Fines no Lucrativos',
107
+ '605': 'Sueldos y Salarios e Ingresos Asimilados a Salarios',
108
+ '606': 'Arrendamiento',
109
+ '608': 'Demás ingresos',
110
+ '609': 'Consolidación',
111
+ '610': 'Residentes en el Extranjero sin Establecimiento Permanente en México',
112
+ '611': 'Ingresos por Dividendos (socios y accionistas)',
113
+ '612': 'Personas Físicas con Actividades Empresariales y Profesionales',
114
+ '614': 'Ingresos por intereses',
115
+ '616': 'Sin obligaciones fiscales',
116
+ '620': 'Sociedades Cooperativas de Producción que optan por diferir sus ingresos',
117
+ '621': 'Incorporación Fiscal',
118
+ '622': 'Actividades Agrícolas, Ganaderas, Silvícolas y Pesqueras',
119
+ '623': 'Opcional para Grupos de Sociedades',
120
+ '624': 'Coordinados',
121
+ '628': 'Hidrocarburos',
122
+ '607': 'Régimen de Enajenación o Adquisición de Bienes',
123
+ '629': 'De los Regímenes Fiscales Preferentes y de las Empresas Multinacionales',
124
+ '630': 'Enajenación de acciones en bolsa de valores',
125
+ '615': 'Régimen de los ingresos por obtención de premios',
126
+ '625': 'Régimen de las Actividades Empresariales con ingresos a través de Plataformas Tecnológicas',
127
+ '626': 'Régimen Simplificado de Confianza',
128
+ }.freeze
129
+
130
+ CANCELACION_FISCAL = {
131
+ '01': 'Comprobante emitido con errores con relación',
132
+ '02': 'Comprobante emitido con errores sin relación',
133
+ '03': 'No se llevó a cabo la operación',
134
+ '04': 'Operación nominativa relacionada en la factura global',
135
+ }.freeze
136
+
137
+ TAXABILITY = {
138
+ '01': 'No objeto de impuesto',
139
+ '02': 'Sí objeto de impuesto',
140
+ '03': 'Sí objeto de impuesto, pero no obligado a desglose',
141
+ }.freeze
104
142
  end
@@ -5,7 +5,14 @@ module FacturapiRuby
5
5
  class << self
6
6
  def create(options)
7
7
  HttpClient.post(
8
- endpoint: '/customers',
8
+ endpoint: '/v1/customers',
9
+ api_options: options
10
+ )
11
+ end
12
+
13
+ def update(customer_id, options)
14
+ HttpClient.put(
15
+ endpoint: "/v1/customers/#{customer_id}",
9
16
  api_options: options
10
17
  )
11
18
  end
@@ -5,14 +5,14 @@ module FacturapiRuby
5
5
  class << self
6
6
  def pdf(options)
7
7
  HttpClient.get_file(
8
- endpoint: "/invoices/#{options[:invoice_id]}/pdf",
8
+ endpoint: "/v1/invoices/#{options[:invoice_id]}/pdf",
9
9
  file_ext: '.pdf'
10
10
  )
11
11
  end
12
12
 
13
13
  def xml(options)
14
14
  HttpClient.get_file(
15
- endpoint: "/invoices/#{options[:invoice_id]}/xml",
15
+ endpoint: "/v1/invoices/#{options[:invoice_id]}/xml",
16
16
  file_ext: '.xml'
17
17
  )
18
18
  end
@@ -14,48 +14,77 @@ module FacturapiRuby
14
14
  module HttpClient
15
15
 
16
16
  class << self
17
- BASE_URL = 'https://www.facturapi.io/v1'
17
+ BASE_URL = 'https://www.facturapi.io'
18
18
 
19
19
  def get_file(options)
20
- uri = URI(BASE_URL + options[:endpoint])
21
-
22
- http = Net::HTTP.new(uri.host, uri.port)
23
- http.use_ssl = true
24
- request = Net::HTTP::Get.new(uri.request_uri)
25
- request.basic_auth(FacturapiRuby.configuration.api_key, '')
20
+ response = request(Net::HTTP::Get, options)
26
21
 
27
- response = http.request(request)
28
22
  file = Tempfile.open(['my', options[:file_ext]])
29
23
  file.binmode
30
24
  file.write(response.body)
31
25
 
32
- if response.code == '200'
26
+ if response.code.start_with? '20'
33
27
  file
34
28
  else
35
29
  raise FacturapiRubyError.new(JSON.parse(response.body))
36
30
  end
37
31
  end
38
32
 
33
+ def get(options)
34
+ response = request(Net::HTTP::Get, options)
35
+
36
+ json_response(response)
37
+ end
38
+
39
39
  def post(options)
40
- uri = URI(BASE_URL + options[:endpoint])
40
+ response = request(Net::HTTP::Post, options) do |request|
41
+ request.body = options[:api_options].to_json
42
+ end
43
+
44
+ json_response(response)
45
+ end
41
46
 
42
- http = Net::HTTP.new(uri.host, uri.port)
43
- http.use_ssl = true
47
+ def put(options)
48
+ response = request(Net::HTTP::Put, options) do |request|
49
+ request.body = options[:api_options].to_json
50
+ end
44
51
 
45
- request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
46
- request.body = options[:api_options].to_json
47
- request.basic_auth(FacturapiRuby.configuration.api_key, '')
52
+ json_response(response)
53
+ end
54
+
55
+ def delete(options)
56
+ response = request(Net::HTTP::Delete, options)
57
+
58
+ json_response(response)
59
+ end
48
60
 
49
- http.set_debug_output($stdout)
61
+ private
50
62
 
51
- response = http.request(request)
52
- puts response.code
63
+ def json_response(response)
53
64
  if response.code.start_with? '20'
54
65
  JSON.parse(response.body)
55
66
  else
56
67
  raise FacturapiRubyError.new(JSON.parse(response.body))
57
68
  end
58
69
  end
70
+
71
+ def request(request_method, options)
72
+ uri = URI(BASE_URL + options[:endpoint])
73
+
74
+ http = Net::HTTP.new(uri.host, uri.port)
75
+ http.use_ssl = true
76
+
77
+ request = request_method.new(uri.request_uri, 'Content-Type' => 'application/json')
78
+ # request.body = options[:api_options].to_json
79
+
80
+ yield(request) if block_given?
81
+
82
+ request.basic_auth(FacturapiRuby.configuration.api_key, '')
83
+
84
+ http.set_debug_output($stdout) if FacturapiRuby.configuration.debug_output
85
+
86
+ http.request(request)
87
+ end
59
88
  end
60
89
  end
61
90
  end
@@ -5,7 +5,21 @@ module FacturapiRuby
5
5
  class << self
6
6
  def create(options)
7
7
  HttpClient.post(
8
- endpoint: '/invoices',
8
+ endpoint: '/v1/invoices',
9
+ api_options: options
10
+ )
11
+ end
12
+
13
+ def cancel(invoice_id, options={})
14
+ HttpClient.delete(
15
+ endpoint: "/v1/invoices/#{invoice_id}",
16
+ api_options: options
17
+ )
18
+ end
19
+
20
+ def get(invoice_id, options={})
21
+ HttpClient.get(
22
+ endpoint: "/v1/invoices/#{invoice_id}",
9
23
  api_options: options
10
24
  )
11
25
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'facturapi_ruby/http_client'
4
+
5
+ module FacturapiRuby
6
+ module V2
7
+ module Customers
8
+ class << self
9
+ def create(options)
10
+ HttpClient.post(
11
+ endpoint: '/v2/customers',
12
+ api_options: options
13
+ )
14
+ end
15
+
16
+ def update(customer_id, options)
17
+ HttpClient.put(
18
+ endpoint: "/v2/customers/#{customer_id}",
19
+ api_options: options
20
+ )
21
+ end
22
+
23
+ def validate(customer_id)
24
+ HttpClient.get(
25
+ endpoint: '/v2/customers/{customer_id}/tax-info-validation'
26
+ )
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'facturapi_ruby/http_client'
4
+
5
+ module FacturapiRuby
6
+ module V2
7
+ module Files
8
+ class << self
9
+ def pdf(options)
10
+ HttpClient.get_file(
11
+ endpoint: "/v2/invoices/#{options[:invoice_id]}/pdf",
12
+ file_ext: '.pdf'
13
+ )
14
+ end
15
+
16
+ def xml(options)
17
+ HttpClient.get_file(
18
+ endpoint: "/v2/invoices/#{options[:invoice_id]}/xml",
19
+ file_ext: '.xml'
20
+ )
21
+ end
22
+
23
+ def zip(options)
24
+ HttpClient.get_file(
25
+ endpoint: "/v2/invoices/#{options[:invoice_id]}/zip",
26
+ file_ext: '.zip'
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'facturapi_ruby/http_client'
4
+
5
+ module FacturapiRuby
6
+ module V2
7
+ module Invoices
8
+ class << self
9
+ def create(options)
10
+ HttpClient.post(
11
+ endpoint: '/v2/invoices',
12
+ api_options: options
13
+ )
14
+ end
15
+
16
+ def cancel(invoice_id, motive, substitution=nil, options={})
17
+ path = "/v2/invoices/#{invoice_id}?motive=#{motive}"
18
+ path += "&substitution=#{substitution}" if substitution
19
+ HttpClient.delete(
20
+ endpoint: path,
21
+ api_options: options
22
+ )
23
+ end
24
+
25
+ def get(invoice_id, options={})
26
+ HttpClient.get(
27
+ endpoint: "/v2/invoices/#{invoice_id}",
28
+ api_options: options
29
+ )
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module FacturapiRuby
2
- VERSION = "1.1.2"
4
+ VERSION = "2.0.0"
3
5
  end
@@ -4,6 +4,10 @@ require 'facturapi_ruby/customers'
4
4
  require 'facturapi_ruby/files'
5
5
  require 'facturapi_ruby/invoices'
6
6
  require 'facturapi_ruby/version'
7
+ require 'facturapi_ruby/v2/customers'
8
+ require 'facturapi_ruby/v2/files'
9
+ require 'facturapi_ruby/v2/invoices'
10
+
7
11
 
8
12
  module FacturapiRuby
9
13
  class << self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facturapi_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego Llamas Velasco
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-05 00:00:00.000000000 Z
11
+ date: 2022-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,12 +78,15 @@ files:
78
78
  - lib/facturapi_ruby/files.rb
79
79
  - lib/facturapi_ruby/http_client.rb
80
80
  - lib/facturapi_ruby/invoices.rb
81
+ - lib/facturapi_ruby/v2/customers.rb
82
+ - lib/facturapi_ruby/v2/files.rb
83
+ - lib/facturapi_ruby/v2/invoices.rb
81
84
  - lib/facturapi_ruby/version.rb
82
85
  homepage: https://github.com/diegollams/facturapi_ruby
83
86
  licenses:
84
87
  - MIT
85
88
  metadata: {}
86
- post_install_message:
89
+ post_install_message:
87
90
  rdoc_options: []
88
91
  require_paths:
89
92
  - lib
@@ -98,9 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
101
  - !ruby/object:Gem::Version
99
102
  version: '0'
100
103
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.7.5
103
- signing_key:
104
+ rubygems_version: 3.1.2
105
+ signing_key:
104
106
  specification_version: 4
105
107
  summary: Crea Facturas Electrónicas válidas lo más fácil posible (CFDI) https://facturapi.io
106
108
  test_files: []