facturama-ipz 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/lib/facturama/facturama_api_multi.rb +29 -0
  3. data/lib/facturama/facturama_api_web.rb +47 -0
  4. data/lib/facturama/models/address.rb +17 -0
  5. data/lib/facturama/models/branch_office.rb +16 -0
  6. data/lib/facturama/models/cfdi.rb +77 -0
  7. data/lib/facturama/models/cfdi_relation.rb +11 -0
  8. data/lib/facturama/models/cfdi_relations.rb +13 -0
  9. data/lib/facturama/models/client.rb +19 -0
  10. data/lib/facturama/models/complement.rb +9 -0
  11. data/lib/facturama/models/connection_info.rb +21 -0
  12. data/lib/facturama/models/csd.rb +14 -0
  13. data/lib/facturama/models/exception/facturama_exception.rb +13 -0
  14. data/lib/facturama/models/exception/model_exception.rb +8 -0
  15. data/lib/facturama/models/globalInformation.rb +15 -0
  16. data/lib/facturama/models/image.rb +12 -0
  17. data/lib/facturama/models/item.rb +29 -0
  18. data/lib/facturama/models/model.rb +68 -0
  19. data/lib/facturama/models/product.rb +25 -0
  20. data/lib/facturama/models/product_tax.rb +14 -0
  21. data/lib/facturama/models/receiver.rb +18 -0
  22. data/lib/facturama/models/serie.rb +15 -0
  23. data/lib/facturama/models/tax.rb +15 -0
  24. data/lib/facturama/models/tax_entity.rb +22 -0
  25. data/lib/facturama/models/tax_stamp.rb +13 -0
  26. data/lib/facturama/models/thirdPartyAccount.rb +14 -0
  27. data/lib/facturama/services/branch_office_service.rb +13 -0
  28. data/lib/facturama/services/catalog_service.rb +39 -0
  29. data/lib/facturama/services/cfdi_multi_service.rb +130 -0
  30. data/lib/facturama/services/cfdi_service.rb +137 -0
  31. data/lib/facturama/services/client_service.rb +13 -0
  32. data/lib/facturama/services/crud_service.rb +33 -0
  33. data/lib/facturama/services/csd_service.rb +13 -0
  34. data/lib/facturama/services/http_service.rb +115 -0
  35. data/lib/facturama/services/product_service.rb +13 -0
  36. data/lib/facturama/version.rb +5 -0
  37. data/lib/facturama-ipz.rb +42 -0
  38. data/lib/samples/sample_api.rb +11 -0
  39. data/lib/samples/sample_api_multi.rb +367 -0
  40. data/lib/samples/sample_api_web.rb +458 -0
  41. metadata +95 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8c394c0c233bddc2b5acadd34cbcaf48be1292386b6c12acb2cf6910b3c6d3c1
4
+ data.tar.gz: daeb67f028981bb38d7f6350492f7a643324fdf9e4a37767d18832f0f7edbed7
5
+ SHA512:
6
+ metadata.gz: 7c8471782d8a0b4c9a75da07dce161e23f0670e6907f97a2116b7df604d9f0e866744932586cd6952e638667533fb985856c531647e0883bd8293f4ba50fe7b3
7
+ data.tar.gz: 48ed6db07737923171cdf81af85e517699852ba2279135962274d1e649915fb17fcd79e48b91b8967021be30d1449de0c5ad2fdc3729228ea941ed1f9e628e35
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'models/connection_info'
4
+
5
+ module Facturama
6
+ require 'logger'
7
+ require 'base64'
8
+ require 'rest-client'
9
+ require 'uri'
10
+
11
+ class FacturamaApiMulti
12
+ def initialize(facturama_user, facturama_password, is_development = true)
13
+ @connection_info = Facturama::Models::ConnectionInfo.new(facturama_user, facturama_password, is_development)
14
+
15
+ @cfdi_service = Facturama::Services::CfdiMultiService.new(@connection_info)
16
+ @csd_service = Facturama::Services::CsdService.new(@connection_info)
17
+ end
18
+
19
+ # CSD
20
+ def csds
21
+ @csd_service
22
+ end
23
+
24
+ # CFDI (Facturas)
25
+ def cfdis
26
+ @cfdi_service
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'models/connection_info'
4
+
5
+ module Facturama
6
+ require 'logger'
7
+ require 'base64'
8
+ require 'rest-client'
9
+ require 'uri'
10
+
11
+ class FacturamaApiWeb
12
+ def initialize(facturama_user, facturama_password, is_development = true)
13
+ @connection_info = Facturama::Models::ConnectionInfo.new(facturama_user, facturama_password, is_development)
14
+
15
+ @client_service = Facturama::Services::ClientService.new(@connection_info)
16
+ @product_service = Facturama::Services::ProductService.new(@connection_info)
17
+ @catalog_service = Facturama::Services::CatalogService.new(@connection_info)
18
+ @branch_office_service = Facturama::Services::BranchOfficeService.new(@connection_info)
19
+ @cfdi_service = Facturama::Services::CfdiService.new(@connection_info)
20
+ end
21
+
22
+ # Clientes
23
+ def clients
24
+ @client_service
25
+ end
26
+
27
+ # Artículos ( Productos o servicios para los conceptos )
28
+ def products
29
+ @product_service
30
+ end
31
+
32
+ # Catálogo
33
+ def catalog
34
+ @catalog_service
35
+ end
36
+
37
+ # Lugares de expedición (Sucursales)
38
+ def branch_office
39
+ @branch_office_service
40
+ end
41
+
42
+ # CFDI (Facturas)
43
+ def cfdis
44
+ @cfdi_service
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Address < Model
6
+ attr_accessor :Street,
7
+ :ExteriorNumber,
8
+ :InteriorNumber,
9
+ :Neighborhood,
10
+ :ZipCode,
11
+ :Locality,
12
+ :Municipality,
13
+ :State,
14
+ :Country
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class BranchOffice < Model
6
+ attr_accessor :Id,
7
+ :Name,
8
+ :Description
9
+
10
+ # :Address
11
+
12
+ validates :Name, :Description, :Address, presence: true
13
+ has_one_object :Address
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ # CFDI de emisión (una factura)
4
+
5
+ module Facturama
6
+ module CfdiType
7
+ INGRESO = 'I'
8
+ EGRESO = 'E'
9
+ TRASLADO = 'T'
10
+ PAGO = 'P'
11
+ end
12
+
13
+ module CfdiStatus
14
+ ALL = 'All'
15
+ ACTIVE = 'Active'
16
+ CANCEL = 'Cancel'
17
+ end
18
+
19
+ module InvoiceType
20
+ ISSUED = 'Issued'
21
+ RECEIVED = 'Received'
22
+ PAYROLL = 'Payroll'
23
+ ISSUED_LITE = 'issuedLite'
24
+ end
25
+
26
+ module FileFormat
27
+ XML = 'Xml'
28
+ PDF = 'Pdf'
29
+ HTML = 'Html'
30
+ end
31
+
32
+ module Models
33
+ class Cfdi < Model
34
+ attr_accessor :Id, # Solo Response
35
+ :Folio, # Solo Response
36
+ :CertNumber, # Solo Response
37
+ :NameId,
38
+ :Date,
39
+ :Serie,
40
+ :PaymentAccountNumber,
41
+ :CurrencyExchangeRate,
42
+ :Currency,
43
+ :ExpeditionPlace,
44
+ :PaymentConditions,
45
+ # :Relations,
46
+ :CfdiType,
47
+ :PaymentForm,
48
+ :PaymentMethod,
49
+ :Exportation,
50
+ :GlobalInformation,
51
+ # :Receiver,
52
+ :Items,
53
+ # :Complemento, _jr_* Complemento no se considera para eso
54
+ :Observations,
55
+ :OrderNumber,
56
+ :PaymentTerms, # Solo Response
57
+ :ExchangeRate, # Solo Response - puede ser el mismo que CurrencyExchangeRate
58
+ :Subtotal, # Solo Response
59
+ :Discount, # Solo Response
60
+ :Total, # Solo Response
61
+ # :Issuer, # Solo Response - Es una entidad fiscal
62
+ :Discount
63
+
64
+ # Taxes # Solo Response
65
+ # :Complement # Solo Response
66
+
67
+ validates :Email, :Rfc, :Name, presence: true
68
+ has_many_objects :Relations, :CfdiRelation
69
+ has_one_object :Receiver
70
+ has_many_objects :Issuer, :TaxEntity
71
+ # has_many_objects :Items, :Item
72
+ has_many_objects :Taxes, :Tax
73
+ has_one_object :Complement
74
+ # has_one_object :GlobalInformation
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class CfdiRelation < Model
6
+ attr_accessor :Uuid
7
+
8
+ validates :Uuid, presence: true
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class CfdiRelations < Model
6
+ attr_accessor :Type,
7
+ :Cfdis
8
+
9
+ validates :Type, :Cfdis, presence: true
10
+ has_many_objects :Cfdis, :CfdiRelation
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Client < Model
6
+ attr_accessor :Email,
7
+ :EmailOp1,
8
+ :EmailOp2,
9
+ :Rfc,
10
+ :Name,
11
+ :CfdiUse,
12
+ :TaxResidence,
13
+ :NumRegIdTrib
14
+
15
+ has_one_object :Address
16
+ validates :Email, :Rfc, :Name, presence: true
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Complement < Model
6
+ attr_accessor :TaxStamp
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class ConnectionInfo
6
+ # API Endpoints
7
+ URL_DEV = 'https://apisandbox.facturama.mx'
8
+ URL_PROD = 'https://api.facturama.mx'
9
+
10
+ def initialize(facturama_user, facturama_password, is_development = true)
11
+ @facturama_user = facturama_user
12
+ @facturama_password = facturama_password
13
+ @is_development = is_development
14
+
15
+ @uri_base = is_development ? URL_DEV : URL_PROD
16
+ end
17
+
18
+ attr_reader :uri_base, :facturama_user, :facturama_password, :is_development
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Csd < Model
6
+ attr_accessor :Rfc,
7
+ :Certificate,
8
+ :PrivateKey,
9
+ :PrivateKeyPassword
10
+
11
+ validates :Certificate, :PrivateKey, :PrivateKeyPassword, presence: true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'model_exception'
4
+
5
+ class FacturamaException < StandardError
6
+ def initialize(exception_message, exception_details = nil)
7
+ super exception_message
8
+
9
+ @details = exception_details
10
+ end
11
+
12
+ attr_reader :details
13
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ModelException
4
+ def initialize
5
+ @message = ''
6
+ @details = ''
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Facturama
3
+ module Models
4
+ class GlobalInformation < Model
5
+ attr_accessor :Periodicity,
6
+ :Months,
7
+ :Year
8
+
9
+
10
+
11
+ validates :Periodicity, :Months, :Year presence: true
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Image < Model
6
+ attr_accessor :Image,
7
+ :Type
8
+
9
+ validates :Image, presence: true
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Item < Model
6
+ attr_accessor :ProductCode,
7
+ :IdentificationNumber,
8
+ :Description,
9
+ :Unit,
10
+ :UnitCode,
11
+ :UnitPrice,
12
+ :Quantity,
13
+ :Subtotal,
14
+ :Discount,
15
+ # :Taxes,
16
+ :CuentaPredial,
17
+ :Total,
18
+ :TaxObject,
19
+ :ThirdPartyAccount,
20
+ :Taxes,
21
+ :UnitValue # solo Response
22
+
23
+ # :Complement _jr_* por el momento, no se consideran los complementos
24
+
25
+ validates :ProductCode, :Description, :UnitCode, :UnitPrice, :Quantity, :Subtotal, :Total, presence: true
26
+ # has_many_objects :Taxes, :Tax
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_model'
4
+
5
+ module Facturama
6
+ module Models
7
+ class Model
8
+ include ActiveModel::Validations
9
+ include ActiveModel::Serializers::JSON
10
+
11
+ attr_accessor :all_errors
12
+
13
+ def initialize(values)
14
+ values.each_pair do |k, v|
15
+ send("#{k}=", v)
16
+ end
17
+ after_initialize
18
+ end
19
+
20
+ def after_initialize; end
21
+
22
+ def attributes
23
+ instance_values
24
+ end
25
+
26
+ def prepare_data
27
+ prepare_keys.to_json
28
+ end
29
+
30
+ def get_instance_values
31
+ instance_values.delete_if do |k, _v|
32
+ %w[all_errors errors validation_context].include?(k)
33
+ end
34
+ end
35
+
36
+ class << self
37
+ def has_many_objects(association, class_name)
38
+ define_writer(association, class_name)
39
+ define_reader(association)
40
+ end
41
+
42
+ def has_one_object(association)
43
+ define_writer(association, association)
44
+ define_reader(association)
45
+ end
46
+
47
+ def define_writer(association, class_name)
48
+ class_eval <<-CODE, __FILE__, __LINE__ + 1
49
+ def #{association}=(value)
50
+ @#{association} =
51
+ if value.class.name == "Array"
52
+ value.collect do |val|
53
+ #{class_name.to_s.camelize}.new(val)
54
+ end
55
+ else
56
+ #{class_name.to_s.camelize}.new(value)
57
+ end
58
+ end
59
+ CODE
60
+ end
61
+
62
+ def define_reader(association)
63
+ attr_reader association
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ require_relative 'product_tax'
6
+
7
+ class Product < Model
8
+ attr_accessor :Unit,
9
+ :UnitCode,
10
+ :IdentificationNumber,
11
+ :Name,
12
+ :Description,
13
+ :Price,
14
+ :CodeProdServ,
15
+ :CuentaPredial,
16
+ :Complement,
17
+ :Id,
18
+ :Taxes
19
+
20
+ validates :Unit, :Name, :Description, :Price, presence: true
21
+ # has_many_objects , :ProductTax
22
+ # has_many_objects :Taxes, ProductTax
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class ProductTax < Model
6
+ attr_accessor :Name,
7
+ :Rate,
8
+ :IsRetention,
9
+ :IsFederalTax,
10
+ :IsQuota,
11
+ :Total
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Receiver < Model
6
+ attr_accessor :Id,
7
+ :Rfc,
8
+ :Name,
9
+ :CfdiUse,
10
+ :TaxResidence,
11
+ :TaxRegistrationNumber,
12
+ :TaxZipCode,
13
+ :FiscalRegime
14
+
15
+ validates :Rfc, presence: true
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Serie < Model
6
+ attr_accessor :IdBranchOffice,
7
+ :Name,
8
+ :Description
9
+
10
+ :Folio
11
+
12
+ validates :IdBranchOffice, :Name, presence: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class Tax < Model
6
+ attr_accessor :Total,
7
+ :Name,
8
+ :Base,
9
+ :Rate,
10
+ :Type,
11
+ :IsRetention,
12
+ :IsQuota
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class TaxEntity < Model
6
+ attr_accessor :FiscalRegime,
7
+ :ComercialName,
8
+ :Rfc,
9
+ :TaxName,
10
+ :Email,
11
+ :Phone,
12
+ # :TaxAddress,
13
+ :PasswordSat,
14
+ :UrlLogo # solo Response
15
+
16
+ validates :FiscalRegime, :Rfc, :TaxName, :Email, presence: true
17
+ has_many_objects :TaxAddress, :Address # solo Response
18
+ has_many_objects :IssuedIn, :Address # solo Response
19
+ has_many_objects :Csd, :Csd # solo Response
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facturama
4
+ module Models
5
+ class TaxStamp < Model
6
+ attr_accessor :Uuid,
7
+ :Date,
8
+ :CfdiSign,
9
+ :SatCertNumber,
10
+ :SatSign
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Facturama
3
+ module Models
4
+ class ThirdPartyAccount < Model
5
+ attr_accessor :Rfc,
6
+ :Name,
7
+ :FiscalRegime,
8
+ :TaxZipCode
9
+
10
+ validates :Rfc, :Name, :FiscalRegime, :TaxZipCode presence: true
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'crud_service'
4
+
5
+ module Facturama
6
+ module Services
7
+ class BranchOfficeService < CrudService
8
+ def initialize(connection_info)
9
+ super(connection_info, 'BranchOffice')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'crud_service'
4
+
5
+ module Facturama
6
+ module Services
7
+ class CatalogService < CrudService
8
+ def initialize(connection_info)
9
+ super(connection_info, 'catalogs')
10
+ end
11
+
12
+ def units(keyword = nil)
13
+ parameters = keyword.to_s.empty? ? '' : "?keyword=#{keyword}"
14
+ get("units#{parameters}")
15
+ end
16
+
17
+ def name_ids
18
+ get('NameIds')
19
+ end
20
+
21
+ def products_or_services(keyword)
22
+ get("ProductsOrServices?keyword=#{keyword}")
23
+ end
24
+
25
+ def currencies(keyword = nil)
26
+ parameters = keyword.to_s.empty? ? '' : "?keyword=#{keyword}"
27
+ get("currencies#{parameters}")
28
+ end
29
+
30
+ def payment_forms
31
+ get('paymentforms')
32
+ end
33
+
34
+ def payment_methods
35
+ get('paymentmethods')
36
+ end
37
+ end
38
+ end
39
+ end