1- require 'net/http'
2- require 'securerandom'
3- require 'json'
41require_relative '../Response/generic_response.rb'
2+ require_relative '../Helpers/request_helper.rb'
53
64class SwCancelation
75 def self . cancel_uuid ( url , token , uuid , rfc , motivo , folio_sustitucion )
8- url = URI ( "#{ url } /cfdi33/cancel/#{ rfc } /#{ uuid } /#{ motivo } /#{ folio_sustitucion } " )
9- http = Net ::HTTP . new ( url . host , url . port )
10- request = Net ::HTTP ::Post . new ( url )
11- request [ "Authorization" ] = 'bearer ' + token
12- request [ "Cache-Control" ] = 'no-cache'
13- response = http . request ( request )
6+ endpoint = URI ( "#{ url } /cfdi33/cancel/#{ rfc } /#{ uuid } /#{ motivo } /#{ folio_sustitucion } " )
7+ response = RequestHelper . post_json_request ( endpoint , token )
148 response_obj = GenericResponse . new ( response )
159 return response_obj . validate_status_code ( response_obj )
1610 end
17-
11+
1812 def self . cancel_csd ( url , token , uuid , rfc , password , csd , key , motivo , folio_sustitucion )
19- url = URI ( url + "/cfdi33/cancel/csd" )
20- http = Net ::HTTP . new ( url . host , url . port )
21- request = Net ::HTTP ::Post . new ( url )
22- request [ "Content-Type" ] = 'application/json'
23- request [ "Authorization" ] = 'bearer ' + token
24- request [ "Cache-Control" ] = 'no-cache'
25- data = { uuid : uuid , rfc : rfc , b64Cer : csd , b64Key : key , password : password , motivo : motivo , folioSustitucion : folio_sustitucion }
26- request . body = data . to_json
27- response = http . request ( request )
13+ endpoint = URI ( url + "/cfdi33/cancel/csd" )
14+ payload = {
15+ "uuid" : uuid ,
16+ "password" : password ,
17+ "rfc" : rfc ,
18+ "motivo" : motivo ,
19+ "foliosustitucion" : folio_sustitucion ,
20+ "b64Cer" : csd ,
21+ "b64Key" : key
22+ }
23+ response = RequestHelper . post_json_request ( endpoint , token , payload )
2824 response_obj = GenericResponse . new ( response )
2925 return response_obj . validate_status_code ( response_obj )
3026 end
3127
3228 def self . cancel_pfx ( url , token , uuid , rfc , password , pfx , motivo , folio_sustitucion )
33- url = URI ( url + "/cfdi33/cancel/pfx" )
34- http = Net ::HTTP . new ( url . host , url . port )
35- request = Net ::HTTP ::Post . new ( url )
36- request [ "Content-Type" ] = 'application/json'
37- request [ "Authorization" ] = 'bearer ' + token
38- request [ "Cache-Control" ] = 'no-cache'
39- data = { uuid : uuid , rfc : rfc , b64Pfx : pfx , password : password , motivo : motivo , folioSustitucion : folio_sustitucion }
40- request . body = data . to_json
41- response = http . request ( request )
29+ endpoint = URI ( url + "/cfdi33/cancel/pfx" )
30+ payload = {
31+ "uuid" : uuid ,
32+ "password" : password ,
33+ "rfc" : rfc ,
34+ "motivo" : motivo ,
35+ "foliosustitucion" : folio_sustitucion ,
36+ "b64Pfx" : pfx
37+ }
38+ response = RequestHelper . post_json_request ( endpoint , token , payload )
4239 response_obj = GenericResponse . new ( response )
4340 return response_obj . validate_status_code ( response_obj )
4441 end
4542
4643 def self . cancel_xml ( url , token , xml )
47- url = URI ( url + "/cfdi33/cancel/xml" )
48- boundary = '----' + SecureRandom . urlsafe_base64
49- http = Net ::HTTP . new ( url . host , url . port )
50- request = Net ::HTTP ::Post . new ( url )
51- request [ "Authorization" ] = 'bearer ' + token
52- request [ "Content-Type" ] = 'multipart/form-data;boundary="' + boundary + '"'
53- request [ "Cache-Control" ] = 'no-cache'
54- request . body = "--" + boundary + "\r \n Content-Type: text/xml\r \n Content-Transfer-Encoding: binary\r \n Content-Disposition: form-data; name=\" xml\" ; filename=\" xml\" \r \n \r \n " + xml + "\r \n --" + boundary + "--"
55- response = http . request ( request )
44+ endpoint = URI ( url + "/cfdi33/cancel/xml" )
45+ response = RequestHelper . post_multipart_request ( endpoint , token , xml )
5646 response_obj = GenericResponse . new ( response )
57- return response_obj . validate_status_code ( response_obj )
47+ return response_obj . validate_status_code ( response_obj )
5848 end
59- end
49+ end
0 commit comments