Module: SatMx
- Defined in:
- lib/sat_mx.rb,
lib/sat_mx/body.rb,
lib/sat_mx/client.rb,
lib/sat_mx/result.rb,
lib/sat_mx/signer.rb,
lib/sat_mx/version.rb,
lib/sat_mx/configuration.rb,
lib/sat_mx/authentication.rb,
lib/sat_mx/verify_request.rb,
lib/sat_mx/download_request.rb,
lib/sat_mx/download_petition.rb,
lib/sat_mx/verify_request_body.rb,
lib/sat_mx/download_request_body.rb,
lib/sat_mx/download_petition_body.rb,
lib/sat_mx/download_request_received.rb,
lib/sat_mx/download_request_received_body.rb
Defined Under Namespace
Modules: Body Classes: Authentication, Client, Configuration, DownloadPetition, DownloadPetitionBody, DownloadRequest, DownloadRequestBody, DownloadRequestReceived, DownloadRequestReceivedBody, Error, Result, Signer, VerifyRequest, VerifyRequestBody, XmlAuthBody
Constant Summary collapse
- VERSION =
"0.4.1"
Class Method Summary collapse
-
.authenticate(certificate: nil, private_key: nil) ⇒ SatMx::Result
Authenticates with the SAT web service using the configured certificate and private key.
- .configuration ⇒ Object
-
.configure {|config| ... } ⇒ Object
Configures the gem using a block, its not threadsafe, so its recommended call only when you're initializing your application, e.g.
-
.download_petition(package_id:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Downloads a package of CFDI documents from the SAT web service.
-
.download_request(start_date:, end_date:, request_type:, issuing_rfc:, recipient_rfcs:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Requests a download of CFDI documents from the SAT web service.
-
.download_request_received(access_token:, start_date:, end_date:, request_type:, recipient_rfc:, issuing_rfc: nil, requester_rfc: nil, document_status: nil, complement: nil, **options) ⇒ SatMx::Result
Requests a download of received CFDI documents from the SAT web service SolicitaDescargaService with SOAPAction SolicitaDescargaRecibidos.
-
.verify_request(request_id:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Verifies the status of a previously submitted download request.
Class Method Details
.authenticate(certificate: nil, private_key: nil) ⇒ SatMx::Result
Authenticates with the SAT web service using the configured certificate and private key. This method uses SOAP to communicate with the SAT authentication service and returns a token that can be used for subsequent requests.
result = SatMx.authenticate
if result.success?
puts "Authentication token: #{result.value}"
else
puts "Authentication failed"
end
61 62 63 64 65 66 67 68 |
# File 'lib/sat_mx.rb', line 61 def authenticate(certificate: nil, private_key: nil) cert = certificate || configuration.certificate key = private_key || configuration.private_key Authentication.authenticate( certificate: cert, private_key: key ) end |
.configuration ⇒ Object
36 37 38 |
# File 'lib/sat_mx.rb', line 36 def configuration @configuration ||= Configuration.new end |
.configure {|config| ... } ⇒ Object
Configures the gem using a block, its not threadsafe, so its recommended call only when you're initializing your application, e.g. in your initializers directory of your rails app @example SatMx.configure do |config| config = "path/to/certificate.cer" config = "path/to/private.key" config = "key_password" end
30 31 32 33 34 |
# File 'lib/sat_mx.rb', line 30 def configure config = {} yield(config) @configuration = Configuration.new(**config) end |
.download_petition(package_id:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Downloads a package of CFDI documents from the SAT web service.
result = SatMx.download_petition(
package_id: "18015570-C084-4BE8-BE36-476F5D46A133_01",
requester_rfc: "ABC010101ABC",
access_token: "your_access_token"
)
if result.success?
File.write("package.zip", result.value)
else
puts "Download failed: #{result.value}"
end
250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/sat_mx.rb', line 250 def download_petition(package_id:, requester_rfc:, access_token:, **) certificate = [:certificate] || configuration.certificate private_key = [:private_key] || configuration.private_key DownloadPetition.call( package_id:, requester_rfc:, access_token:, certificate:, private_key: ) end |
.download_request(start_date:, end_date:, request_type:, issuing_rfc:, recipient_rfcs:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Requests a download of CFDI documents from the SAT web service.
result = SatMx.download_request(
start_date: Time.new(2024, 1, 1),
end_date: Time.new(2024, 1, 31),
request_type: :cfdi,
issuing_rfc: "ABC010101ABC",
recipient_rfcs: ["XYZ020202XYZ"],
requester_rfc: "ABC010101ABC",
access_token: "your_access_token"
)
if result.success?
puts "Request ID: #{result.value}"
else
puts "Request failed: #{result.value}"
end
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sat_mx.rb', line 104 def download_request(start_date:, end_date:, request_type:, issuing_rfc:, recipient_rfcs:, requester_rfc:, access_token:, **) certificate = [:certificate] || configuration.certificate private_key = [:private_key] || configuration.private_key DownloadRequest.call( start_date:, end_date:, request_type:, issuing_rfc:, recipient_rfcs:, requester_rfc:, access_token:, certificate:, private_key: ) end |
.download_request_received(access_token:, start_date:, end_date:, request_type:, recipient_rfc:, issuing_rfc: nil, requester_rfc: nil, document_status: nil, complement: nil, **options) ⇒ SatMx::Result
Requests a download of received CFDI documents from the SAT web service SolicitaDescargaService with SOAPAction SolicitaDescargaRecibidos
result = SatMx.download_request_received(
start_date: Time.new(2024, 1, 1),
end_date: Time.new(2024, 1, 31),
request_type: :cfdi,
recipient_rfc: "ABC010101ABC",
requester_rfc: "ABC010101ABC",
access_token: "your_access_token"
)
if result.success?
puts "Request ID: #{result.value}"
else
puts "Request failed: #{result.value}"
end
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/sat_mx.rb', line 156 def download_request_received( access_token:, start_date:, end_date:, request_type:, recipient_rfc:, issuing_rfc: nil, requester_rfc: nil, document_status: nil, complement: nil, ** ) certificate = [:certificate] || configuration.certificate private_key = [:private_key] || configuration.private_key DownloadRequestReceived.call( start_date:, end_date:, request_type:, recipient_rfc:, requester_rfc:, issuing_rfc:, complement:, document_status:, access_token:, certificate:, private_key: ) end |
.verify_request(request_id:, requester_rfc:, access_token:, **options) ⇒ SatMx::Result
Verifies the status of a previously submitted download request.
result = SatMx.verify_request(
request_id: "606c5667-345a-4630-8979-0769734ac80b",
requester_rfc: "ABC010101ABC",
access_token: "your_access_token"
)
if result.success?
puts "Status: #{result.value[:request_status]}"
puts "Packages: #{result.value[:package_ids]}"
else
puts "Verification failed: #{result.value}"
end
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/sat_mx.rb', line 212 def verify_request(request_id:, requester_rfc:, access_token:, **) certificate = [:certificate] || configuration.certificate private_key = [:private_key] || configuration.private_key VerifyRequest.call( request_id:, requester_rfc:, access_token:, certificate:, private_key: ) end |