sw_fac 0.3.59 → 0.3.62

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: 347b392ace1548f025a63fa45beb0cfc8ecd2749afdf7d1a5f0133174cc9ecf8
4
- data.tar.gz: 7e84946f2550ee05d05ed540d2de2c5f4ff985d60c36451cacad9f1039fd95d2
3
+ metadata.gz: 33d61f419dde54d73f680114a9784046d689271cc4b3e662a7cdb42fe6c1967e
4
+ data.tar.gz: 5b395feeed206cb98d58c7feeb5188a28acbfa4917d14e97f09c5495072b3a2a
5
5
  SHA512:
6
- metadata.gz: 3f850d4c0fdf39f994a75951c5fd729653bc8bebb2aaf47d177422f9e5fa90bcdb0fd4619a084ee9697b486e5e6f69e7014e1db2f3fed299fb7f6deb2591fd87
7
- data.tar.gz: 9db87eda9e488da71e07efc3fd1564bc0f306a825b2797e5c0b76a0b40ee2be2dfe3942654aaae73f7128b937a4d23c34a99d3a388289682899672baf0dcda6d
6
+ metadata.gz: 63e1b5f8b105e7151c4652a9bdbcac84762a7f995695d3e5919983d60da53066b699baeb5bcd9468a5de7326b76300d1e50ac1cedcffff45613b55e10bcdd055
7
+ data.tar.gz: dfb86927d6bea35ba34826705dfc297b49dc4befe0d35f9ba765b718046a6208e8ea7a4cc53bc48f8a59c722b145d68c853f9b7fe4ee306537894a4ccc2c8280
data/lib/sw_fac/config.rb CHANGED
@@ -25,7 +25,10 @@ module SwFac
25
25
  def key_to_pem
26
26
  puts "---- SwFacturacion:config:key_to_pem"
27
27
 
28
+ puts "-- 1"
28
29
  @pem = %x[openssl pkcs8 -inform DER -in #{@doc_key_path} -passin pass:#{@key_pass}]
30
+ # @pem = %x[openssl rsa -inform DER -in #{@doc_key_path} -passin pass:#{@key_pass}]
31
+ puts "-- 2"
29
32
  @pem_cadena = @pem.clone
30
33
  @pem_cadena.slice!("-----BEGIN PRIVATE KEY-----")
31
34
  @pem_cadena.slice!("-----END PRIVATE KEY-----")
@@ -74,6 +77,9 @@ module SwFac
74
77
  <cfdi:Receptor /><cfdi:Conceptos></cfdi:Conceptos>
75
78
  <cfdi:Impuestos></cfdi:Impuestos></cfdi:Comprobante>)
76
79
 
80
+ DocBaseCero = %(<?xml version="1.0" encoding="utf-8"?><cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd" Version="3.3" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><cfdi:Emisor />
81
+ <cfdi:Receptor /><cfdi:Conceptos></cfdi:Conceptos></cfdi:Comprobante>)
82
+
77
83
  Doc_concepto = %(<cfdi:Concepto ClaveProdServ="25172504" NoIdentificacion="COST37125R17" Cantidad="1" ClaveUnidad="H87" Unidad="Pieza" Descripcion="Producto de prueba" ValorUnitario="1000.00" Importe="1000.00"><cfdi:Impuestos><cfdi:Traslados><cfdi:Traslado Base="1000.00" Impuesto="002" TipoFactor="Tasa" TasaOCuota="0.160000" Importe="160.00" /></cfdi:Traslados></cfdi:Impuestos></cfdi:Concepto>)
78
84
 
79
85
 
@@ -736,6 +736,207 @@ module SwFac
736
736
 
737
737
 
738
738
 
739
+ end
740
+
741
+ def timbra_doc_cero(params={})
742
+ puts "---- SwFacturacion:facturacion:timbra_doc_cero"
743
+ # params = {
744
+ # moneda: 'MXN',
745
+ # series: 'FA',
746
+ # folio: '003',
747
+ # forma_pago: '',
748
+ # metodo_pago: 'PUE',
749
+ # cp: '47180',
750
+ # receptor_razon: 'Car zone',
751
+ # receptor_rfc: '',
752
+ # uso_cfdi: 'G03',
753
+ # time: "%Y-%m-%dT%H:%M:%S",
754
+ # line_items: [
755
+ # {
756
+ # clave_prod_serv: '78181500',
757
+ # clave_unidad: 'E48',
758
+ # unidad: 'Servicio',
759
+ # sku: 'serv001',
760
+ # cantidad: 1,
761
+ # descripcion: 'Servicio mano de obra',
762
+ # valor_unitario: 100.00,
763
+ # # Optional parameters
764
+ # },
765
+ # ]
766
+
767
+ # }
768
+
769
+ uri = @production ? URI("#{SwFac::UrlProduction}cfdi33/stamp/customv1/b64") : URI("#{SwFac::UrlDev}cfdi33/stamp/customv1/b64")
770
+ token = @production ? @production_token : @dev_token
771
+ time = params.fetch(:time, (Time.now).strftime("%Y-%m-%dT%H:%M:%S"))
772
+
773
+ xml = Nokogiri::XML(SwFac::DocBaseCero)
774
+ comprobante = xml.at_xpath("//cfdi:Comprobante")
775
+ comprobante['TipoCambio'] = '1'
776
+ comprobante['TipoDeComprobante'] = 'I'
777
+ comprobante['Serie'] = params.fetch(:series, 'FA').to_s
778
+ comprobante['Folio'] = params.fetch(:folio, '1').to_s
779
+ comprobante['Fecha'] = time.to_s
780
+ comprobante['FormaPago'] = params.fetch(:forma_pago, '01')
781
+ comprobante['MetodoPago'] = params.fetch(:metodo_pago, 'PUE')
782
+ comprobante['LugarExpedicion'] = params.fetch(:cp, '55555')
783
+ comprobante['NoCertificado'] = @serial
784
+ comprobante['Certificado'] = @cadena
785
+
786
+ emisor = xml.at_xpath("//cfdi:Emisor")
787
+ emisor['Nombre'] = @razon
788
+ emisor['RegimenFiscal'] = @regimen_fiscal
789
+ emisor['Rfc'] = @rfc
790
+
791
+ receptor = xml.at_xpath("//cfdi:Receptor")
792
+ receptor['Nombre'] = params.fetch(:receptor_razon, '')
793
+ receptor['Rfc'] = params.fetch(:receptor_rfc, 'XAXX010101000')
794
+ receptor['UsoCFDI'] = params.fetch(:uso_cfdi, 'G03')
795
+
796
+
797
+ # impuestos = xml.at_xpath("//cfdi:Impuestos")
798
+ # traslados = Nokogiri::XML::Node.new "cfdi:Traslados", xml
799
+
800
+
801
+ puts '--- sw_fac time -----'
802
+ puts time
803
+ puts '--------'
804
+
805
+ conceptos = xml.at_xpath("//cfdi:Conceptos")
806
+
807
+ line_items = params[:line_items]
808
+
809
+ suma_total = 0.00
810
+
811
+ line_items.each do |line|
812
+
813
+ valor_unitario = line[:valor_unitario].to_f
814
+ cantidad = line[:cantidad].to_f
815
+ total_line = cantidad * valor_unitario
816
+
817
+ suma_total += total_line
818
+
819
+ ## Creando y poblando CFDI:CONCEPTO
820
+ child_concepto = Nokogiri::XML::Node.new "cfdi:Concepto", xml
821
+ child_concepto['ClaveProdServ'] = line[:clave_prod_serv].to_s
822
+ child_concepto['NoIdentificacion'] = line[:sku].to_s
823
+ child_concepto['ClaveUnidad'] = line[:clave_unidad].to_s
824
+ child_concepto['Unidad'] = line[:unidad].to_s
825
+ child_concepto['Descripcion'] = line[:descripcion].to_s
826
+ child_concepto['Cantidad'] = cantidad.to_s
827
+ child_concepto['ValorUnitario'] = valor_unitario.round(4).to_s
828
+ child_concepto['Importe'] = total_line.round(4).to_s
829
+
830
+
831
+ # Joining all up
832
+ conceptos.add_child(child_concepto)
833
+
834
+
835
+ end
836
+
837
+ puts '------ Totales -----'
838
+ puts "Subtotal = #{suma_total}"
839
+ puts "Total = #{suma_total}"
840
+
841
+ comprobante['Moneda'] = params.fetch(:moneda, 'MXN')
842
+ comprobante['SubTotal'] = suma_total.round(2).to_s
843
+ comprobante['Total'] = suma_total.round(2).to_s
844
+
845
+
846
+
847
+ path = File.join(File.dirname(__FILE__), *%w[.. tmp])
848
+ id = SecureRandom.hex
849
+
850
+ FileUtils.mkdir_p(path) unless File.exist?(path)
851
+ File.write("#{path}/tmp_#{id}.xml", xml.to_xml)
852
+ xml_path = "#{path}/tmp_#{id}.xml"
853
+ cadena_path = File.join(File.dirname(__FILE__), *%w[.. cadena cadena33.xslt])
854
+
855
+ # puts File.read(cadena_path)
856
+ File.write("#{path}/pem_#{id}.pem", @pem)
857
+ key_pem_url = "#{path}/pem_#{id}.pem"
858
+ sello = %x[xsltproc #{cadena_path} #{xml_path} | openssl dgst -sha256 -sign #{key_pem_url} | openssl enc -base64 -A]
859
+ comprobante['Sello'] = sello
860
+
861
+ File.delete("#{xml_path}")
862
+ File.delete("#{key_pem_url}")
863
+
864
+ puts '---- SW GEM comprobante sin timbrar ------'
865
+ puts xml.to_xml
866
+ puts '-------------------------'
867
+
868
+ base64_xml = Base64.encode64(xml.to_xml)
869
+ request = Net::HTTP::Post.new(uri)
870
+ request.basic_auth(token, "")
871
+ request.content_type = "application/json"
872
+ request["cache-control"] = 'no-cache'
873
+ request.body = JSON.dump({
874
+ "credentials" => {
875
+ "id" => params.fetch(:folio).to_s,
876
+ "token" => token
877
+ },
878
+ "issuer" => {
879
+ "rfc" => emisor['Rfc']
880
+ },
881
+ "document" => {
882
+ "ref-id": params.fetch(:folio).to_s,
883
+ "certificate-number": comprobante['NoCertificado'],
884
+ "section": "all",
885
+ "format": "xml",
886
+ "template": "letter",
887
+ "type": "application/xml",
888
+ "content": base64_xml
889
+ }
890
+ })
891
+
892
+ req_options = {
893
+ use_ssl: false,
894
+ }
895
+
896
+ json_response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
897
+ http.request(request)
898
+ end
899
+
900
+ puts "-- SW API reponse..."
901
+ puts "-- Response code: #{json_response.code} --"
902
+ puts "-- Response body: #{json_response.body} --"
903
+ puts "-- Response message: #{json_response.message} --"
904
+
905
+ response = JSON.parse(json_response.body)
906
+
907
+ if json_response.code == '200'
908
+ decoded_xml = Nokogiri::XML(Base64.decode64(response['content']))
909
+ timbre = decoded_xml.at_xpath("//cfdi:Complemento").children.first
910
+
911
+ response = {
912
+ status: 200,
913
+ message_error: '',
914
+ xml: decoded_xml.to_xml,
915
+ uuid: response['uuid'],
916
+ fecha_timbrado: timbre['FechaTimbrado'],
917
+ sello_cfd: timbre['SelloCFD'],
918
+ sello_sat: timbre['SelloSAT'],
919
+ no_certificado_sat: timbre['NoCertificadoSAT'],
920
+ }
921
+
922
+ return response
923
+ else
924
+
925
+ response ={
926
+ status: json_response.code,
927
+ message_error: "Error message: #{json_response.message}, #{response['message']} #{response['error_details']}",
928
+ xml: '',
929
+ uuid: '',
930
+ fecha_timbrado: '',
931
+ sello_cfd: '',
932
+ sello_sat: '',
933
+ no_certificado_sat: '',
934
+ }
935
+
936
+ return response
937
+ end
938
+
939
+
739
940
  end
740
941
 
741
942
 
@@ -1,3 +1,3 @@
1
1
  module SwFac
2
- VERSION = "0.3.59"
2
+ VERSION = "0.3.62"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sw_fac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.59
4
+ version: 0.3.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel Padilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler