Class: Nfe::Resources::InboundProductInvoices
- Inherits:
-
AbstractResource
- Object
- AbstractResource
- Nfe::Resources::InboundProductInvoices
- Defined in:
- lib/nfe/resources/inbound_product_invoices.rb,
sig/nfe/resources/inbound_product_invoices.rbs
Overview
Inbound supplier NF-e (Nota Fiscal Eletrônica de fornecedor) resource for
the :cte host family (+https://api.nfse.io+). Manages automatic NF-e
fetch via SEFAZ Distribuição DFe, reads received NF-e documents/events,
sends the recipient manifest (Manifestação do Destinatário) and reprocesses
webhooks.
This is an inbound/query resource (settings + access-key lookups), not an
emission resource: there is no discriminated 202 +Pending+/+Issued+
contract here. The host carries no version segment, so paths embed /v2
literally and #api_version is "".
There are two detail surfaces: the generic webhook-v1 path
(+.../inbound/key+) and the recommended webhook-v2 path
(+.../inbound/productinvoice/key+, which adds a productInvoices array).
Constant Summary collapse
- MANIFEST_AWARENESS =
Manifest event type — Ciência da Operação (awareness, default).
210_210- MANIFEST_CONFIRMATION =
Manifest event type — Confirmação da Operação (confirmation).
210_220- MANIFEST_NOT_PERFORMED =
Manifest event type — Operação não Realizada (operation not performed).
210_240
Instance Attribute Summary
Attributes inherited from AbstractResource
Instance Method Summary collapse
- #api_family ⇒ Symbol
-
#api_version ⇒ String
The
:ctehost carries no version segment;/v2is embedded per path. -
#compact(hash) ⇒ Hash[untyped, untyped]
Drop
nilvalues so optional fields are omitted from the body. - #company_and_key(company_id, access_key) ⇒ [ String, String ]
- #company_key_event(company_id, access_key, event_key) ⇒ [ String, String, String ]
-
#disable_auto_fetch(company_id:) ⇒ Nfe::InboundSettings
Disable automatic NF-e distribution fetch for a company.
-
#enable_auto_fetch(company_id:, start_from_nsu: nil, start_from_date: nil, environment_sefaz: nil, automatic_manifesting: nil, webhook_version: nil) ⇒ Nfe::InboundSettings
Enable automatic NF-e distribution fetch for a company.
-
#get_details(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an inbound document by access key (webhook-v1 format).
-
#get_event_details(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an event related to an inbound document (webhook-v1).
-
#get_event_xml(company_id:, access_key:, event_key:) ⇒ String
Download the XML of an event related to an inbound document.
-
#get_json(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get the structured JSON representation of an inbound NF-e by access key.
-
#get_pdf(company_id:, access_key:) ⇒ String
Download the PDF (DANFE) of an inbound NF-e by access key.
-
#get_product_invoice_details(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an inbound NF-e by access key (webhook-v2 format, recommended; adds the
product_invoicesarray). -
#get_product_invoice_event_details(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an event related to an inbound NF-e (webhook-v2).
-
#get_settings(company_id:) ⇒ Nfe::InboundSettings
Get the current automatic NF-e fetch settings.
-
#get_xml(company_id:, access_key:) ⇒ String
Download the XML of an inbound document by access key.
- #json_body(data) ⇒ String
- #json_headers ⇒ Hash[String, String]
-
#manifest(company_id:, access_key:, tp_event: MANIFEST_AWARENESS) ⇒ String
Send the recipient manifest (Manifestação do Destinatário) for an NF-e.
- #pdf_accept ⇒ Hash[String, String]
-
#reprocess_webhook(company_id:, access_key_or_nsu:) ⇒ Nfe::InboundInvoiceMetadata
Reprocess the webhook for an inbound NF-e, identified by either a 44-digit access key OR a numeric NSU.
- #xml_accept ⇒ Hash[String, String]
Methods inherited from AbstractResource
#build_list_page, #build_multipart_body, #cursor_list_page, #delete, #dig_key, #download, #extract_invoice_id, #full_path, #get, #handle_async_response, #hydrate, #hydrate_list, #initialize, #multipart_part, #page_list_page, #parse_json, #post, #put, #unwrap, #upload_multipart
Constructor Details
This class inherits a constructor from Nfe::Resources::AbstractResource
Instance Method Details
#api_family ⇒ Symbol
38 39 40 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 38 def api_family :cte end |
#api_version ⇒ String
The :cte host carries no version segment; /v2 is embedded per path.
43 44 45 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 43 def api_version "" end |
#compact(hash) ⇒ Hash[untyped, untyped]
Drop nil values so optional fields are omitted from the body.
236 237 238 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 236 def compact(hash) hash.compact end |
#company_and_key(company_id, access_key) ⇒ [ String, String ]
210 211 212 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 210 def company_and_key(company_id, access_key) [Nfe::IdValidator.company_id(company_id), Nfe::IdValidator.access_key(access_key)] end |
#company_key_event(company_id, access_key, event_key) ⇒ [ String, String, String ]
214 215 216 217 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 214 def company_key_event(company_id, access_key, event_key) [Nfe::IdValidator.company_id(company_id), Nfe::IdValidator.access_key(access_key), Nfe::IdValidator.event_key(event_key)] end |
#disable_auto_fetch(company_id:) ⇒ Nfe::InboundSettings
Disable automatic NF-e distribution fetch for a company.
75 76 77 78 79 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 75 def disable_auto_fetch(company_id:) id = Nfe::IdValidator.company_id(company_id) response = delete("/v2/companies/#{id}/inbound/productinvoices") hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#enable_auto_fetch(company_id:, start_from_nsu: nil, start_from_date: nil, environment_sefaz: nil, automatic_manifesting: nil, webhook_version: nil) ⇒ Nfe::InboundSettings
Enable automatic NF-e distribution fetch for a company.
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 58 def enable_auto_fetch(company_id:, start_from_nsu: nil, start_from_date: nil, environment_sefaz: nil, automatic_manifesting: nil, webhook_version: nil) id = Nfe::IdValidator.company_id(company_id) body = compact( "startFromNsu" => start_from_nsu, "startFromDate" => start_from_date, "environmentSEFAZ" => environment_sefaz, "automaticManifesting" => automatic_manifesting, "webhookVersion" => webhook_version ) response = post("/v2/companies/#{id}/inbound/productinvoices", body: json_body(body), headers: json_headers) hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#get_details(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an inbound document by access key (webhook-v1 format).
96 97 98 99 100 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 96 def get_details(company_id:, access_key:) id, key = company_and_key(company_id, access_key) response = get("/v2/companies/#{id}/inbound/#{key}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_event_details(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an event related to an inbound document (webhook-v1).
120 121 122 123 124 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 120 def get_event_details(company_id:, access_key:, event_key:) id, key, ev = company_key_event(company_id, access_key, event_key) response = get("/v2/companies/#{id}/inbound/#{key}/events/#{ev}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_event_xml(company_id:, access_key:, event_key:) ⇒ String
Download the XML of an event related to an inbound document.
154 155 156 157 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 154 def get_event_xml(company_id:, access_key:, event_key:) id, key, ev = company_key_event(company_id, access_key, event_key) download("/v2/companies/#{id}/inbound/#{key}/events/#{ev}/xml", headers: xml_accept) end |
#get_json(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get the structured JSON representation of an inbound NF-e by access key.
174 175 176 177 178 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 174 def get_json(company_id:, access_key:) id, key = company_and_key(company_id, access_key) response = get("/v2/companies/#{id}/inbound/productinvoice/#{key}/json") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_pdf(company_id:, access_key:) ⇒ String
Download the PDF (DANFE) of an inbound NF-e by access key.
164 165 166 167 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 164 def get_pdf(company_id:, access_key:) id, key = company_and_key(company_id, access_key) download("/v2/companies/#{id}/inbound/#{key}/pdf", headers: pdf_accept) end |
#get_product_invoice_details(company_id:, access_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an inbound NF-e by access key (webhook-v2 format,
recommended; adds the product_invoices array).
108 109 110 111 112 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 108 def get_product_invoice_details(company_id:, access_key:) id, key = company_and_key(company_id, access_key) response = get("/v2/companies/#{id}/inbound/productinvoice/#{key}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_product_invoice_event_details(company_id:, access_key:, event_key:) ⇒ Nfe::InboundInvoiceMetadata
Get details of an event related to an inbound NF-e (webhook-v2).
132 133 134 135 136 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 132 def get_product_invoice_event_details(company_id:, access_key:, event_key:) id, key, ev = company_key_event(company_id, access_key, event_key) response = get("/v2/companies/#{id}/inbound/productinvoice/#{key}/events/#{ev}") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#get_settings(company_id:) ⇒ Nfe::InboundSettings
Get the current automatic NF-e fetch settings.
85 86 87 88 89 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 85 def get_settings(company_id:) id = Nfe::IdValidator.company_id(company_id) response = get("/v2/companies/#{id}/inbound/productinvoices") hydrate(Nfe::InboundSettings, parse_json(response.body)) end |
#get_xml(company_id:, access_key:) ⇒ String
Download the XML of an inbound document by access key.
143 144 145 146 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 143 def get_xml(company_id:, access_key:) id, key = company_and_key(company_id, access_key) download("/v2/companies/#{id}/inbound/#{key}/xml", headers: xml_accept) end |
#json_body(data) ⇒ String
223 224 225 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 223 def json_body(data) JSON.generate(data) end |
#json_headers ⇒ Hash[String, String]
219 220 221 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 219 def json_headers { "Content-Type" => "application/json" } end |
#manifest(company_id:, access_key:, tp_event: MANIFEST_AWARENESS) ⇒ String
Send the recipient manifest (Manifestação do Destinatário) for an NF-e.
tp_event defaults to MANIFEST_AWARENESS (210210); the other codes are
MANIFEST_CONFIRMATION (210220) and MANIFEST_NOT_PERFORMED (210240).
188 189 190 191 192 193 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 188 def manifest(company_id:, access_key:, tp_event: MANIFEST_AWARENESS) id, key = company_and_key(company_id, access_key) response = post("/v2/companies/#{id}/inbound/#{key}/manifest", query: { tpEvent: tp_event }) response.body || "" end |
#pdf_accept ⇒ Hash[String, String]
231 232 233 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 231 def pdf_accept { "Accept" => "application/pdf" } end |
#reprocess_webhook(company_id:, access_key_or_nsu:) ⇒ Nfe::InboundInvoiceMetadata
Reprocess the webhook for an inbound NF-e, identified by either a 44-digit access key OR a numeric NSU. A bare NSU is not rejected as an invalid key.
201 202 203 204 205 206 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 201 def reprocess_webhook(company_id:, access_key_or_nsu:) id = Nfe::IdValidator.company_id(company_id) identifier = Nfe::IdValidator.presence!(access_key_or_nsu, "access_key_or_nsu") response = post("/v2/companies/#{id}/inbound/productinvoice/#{identifier}/processwebhook") hydrate(Nfe::InboundInvoiceMetadata, parse_json(response.body)) end |
#xml_accept ⇒ Hash[String, String]
227 228 229 |
# File 'lib/nfe/resources/inbound_product_invoices.rb', line 227 def xml_accept { "Accept" => "application/xml" } end |