Class: Nfe::ServiceInvoice
- Inherits:
-
Data
- Object
- Data
- Nfe::ServiceInvoice
- Defined in:
- lib/nfe/resources/dto/service_invoice.rb,
sig/nfe/resources/dto/service_invoice.rbs
Overview
Immutable value object for a service invoice (NFS-e) as returned by the
NFE.io api.nfe.io/v1 service-invoice API.
The nf-servico-v1.yaml OpenAPI spec declares the retrieve success
response inline (no named schema in components.schemas — only the
error model is componentized), so this DTO is hand-written and pinned to
the spec by an alignment test. ServiceInvoice.from_api maps the API camelCase keys onto
snake_case members and is nil-tolerant (+from_api(nil)+ returns nil).
The full parsed payload is preserved under raw for forward
compatibility — fields without a typed member (the withholding tree,
provider, taxationType, location, approximateTax, ...) are
accessible through it.
borrower is hydrated into ServiceInvoiceBorrower (typed readers
plus a Hash-compatibility bridge, so borrower["name"] keeps working).
flow_status drives the polling lifecycle; pass it to
FlowStatus.terminal? to decide when the document is settled.
Instance Attribute Summary collapse
-
#amount_net ⇒ Object
readonly
Returns the value of attribute amount_net.
-
#base_tax_amount ⇒ Float, ...
readonly
Returns the value of attribute base_tax_amount.
-
#borrower ⇒ Nfe::ServiceInvoiceBorrower?
readonly
Returns the value of attribute borrower.
-
#cancelled_on ⇒ String?
readonly
Returns the value of attribute cancelled_on.
-
#check_code ⇒ String?
readonly
Returns the value of attribute check_code.
-
#city_service_code ⇒ Object
readonly
Returns the value of attribute city_service_code.
-
#created_on ⇒ String?
readonly
Returns the value of attribute created_on.
-
#description ⇒ String?
readonly
Returns the value of attribute description.
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#federal_service_code ⇒ Object
readonly
Returns the value of attribute federal_service_code.
-
#flow_message ⇒ String?
readonly
Returns the value of attribute flow_message.
-
#flow_status ⇒ String?
readonly
Returns the value of attribute flow_status.
-
#id ⇒ String?
readonly
Returns the value of attribute id.
-
#iss_rate ⇒ Float, ...
readonly
Returns the value of attribute iss_rate.
-
#iss_tax_amount ⇒ Float, ...
readonly
Returns the value of attribute iss_tax_amount.
-
#issued_on ⇒ String?
readonly
Returns the value of attribute issued_on.
-
#modified_on ⇒ String?
readonly
Returns the value of attribute modified_on.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#pdf ⇒ Object
readonly
deprecated
Deprecated.
Ghost field — the retrieve response carries no
pdfkey (alwaysnil). Use Resources::ServiceInvoices#download_pdf. -
#raw ⇒ Hash[untyped, untyped]?
readonly
Returns the value of attribute raw.
-
#rps_number ⇒ Object
readonly
Returns the value of attribute rps_number.
-
#rps_serial_number ⇒ Object
readonly
Returns the value of attribute rps_serial_number.
-
#services_amount ⇒ Object
readonly
Returns the value of attribute services_amount.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#xml ⇒ Object
readonly
deprecated
Deprecated.
Ghost field — the retrieve response carries no
xmlkey (alwaysnil). Use Resources::ServiceInvoices#download_xml.
Class Method Summary collapse
-
.from_api(payload) ⇒ Nfe::ServiceInvoice?
Build a ServiceInvoice from an API payload.
- .new ⇒ instance
Instance Method Summary collapse
-
#initialize ⇒ ServiceInvoice
constructor
A new instance of ServiceInvoice.
Constructor Details
#initialize ⇒ ServiceInvoice
Returns a new instance of ServiceInvoice.
32 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 32
def initialize: (id: String?, flow_status: String?, flow_message: String?, status: untyped, environment: untyped, rps_number: untyped, rps_serial_number: untyped, number: untyped, check_code: String?, issued_on: String?, cancelled_on: String?, amount_net: untyped, services_amount: untyped, borrower: Nfe::ServiceInvoiceBorrower?, city_service_code: untyped, federal_service_code: untyped, description: String?, pdf: untyped, xml: untyped, created_on: String?, modified_on: String?, base_tax_amount: (Float | Integer)?, iss_rate: (Float | Integer)?, iss_tax_amount: (Float | Integer)?, raw: Hash[untyped, untyped]?) -> void
|
Instance Attribute Details
#amount_net ⇒ Object (readonly)
Returns the value of attribute amount_net.
14 15 16 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 14 def amount_net @amount_net end |
#base_tax_amount ⇒ Float, ... (readonly)
Returns the value of attribute base_tax_amount.
24 25 26 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 24 def base_tax_amount @base_tax_amount end |
#borrower ⇒ Nfe::ServiceInvoiceBorrower? (readonly)
Returns the value of attribute borrower.
16 17 18 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 16 def borrower @borrower end |
#cancelled_on ⇒ String? (readonly)
Returns the value of attribute cancelled_on.
13 14 15 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 13 def cancelled_on @cancelled_on end |
#check_code ⇒ String? (readonly)
Returns the value of attribute check_code.
11 12 13 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 11 def check_code @check_code end |
#city_service_code ⇒ Object (readonly)
Returns the value of attribute city_service_code.
17 18 19 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 17 def city_service_code @city_service_code end |
#created_on ⇒ String? (readonly)
Returns the value of attribute created_on.
22 23 24 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 22 def created_on @created_on end |
#description ⇒ String? (readonly)
Returns the value of attribute description.
19 20 21 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 19 def description @description end |
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
7 8 9 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 7 def environment @environment end |
#federal_service_code ⇒ Object (readonly)
Returns the value of attribute federal_service_code.
18 19 20 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 18 def federal_service_code @federal_service_code end |
#flow_message ⇒ String? (readonly)
Returns the value of attribute flow_message.
5 6 7 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 5 def @flow_message end |
#flow_status ⇒ String? (readonly)
Returns the value of attribute flow_status.
4 5 6 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 4 def flow_status @flow_status end |
#id ⇒ String? (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 3 def id @id end |
#iss_rate ⇒ Float, ... (readonly)
Returns the value of attribute iss_rate.
25 26 27 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 25 def iss_rate @iss_rate end |
#iss_tax_amount ⇒ Float, ... (readonly)
Returns the value of attribute iss_tax_amount.
26 27 28 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 26 def iss_tax_amount @iss_tax_amount end |
#issued_on ⇒ String? (readonly)
Returns the value of attribute issued_on.
12 13 14 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 12 def issued_on @issued_on end |
#modified_on ⇒ String? (readonly)
Returns the value of attribute modified_on.
23 24 25 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 23 def modified_on @modified_on end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
10 11 12 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 10 def number @number end |
#pdf ⇒ Object (readonly)
Ghost field — the retrieve response carries no pdf key
(always nil). Use Resources::ServiceInvoices#download_pdf.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/nfe/resources/dto/service_invoice.rb', line 31 class ServiceInvoice < Data.define( :id, :flow_status, :flow_message, :status, :environment, :rps_number, :rps_serial_number, :number, :check_code, :issued_on, :cancelled_on, :amount_net, :services_amount, :borrower, :city_service_code, :federal_service_code, :description, :pdf, :xml, :created_on, :modified_on, :base_tax_amount, :iss_rate, :iss_tax_amount, :raw ) # Build a {Nfe::ServiceInvoice} from an API payload. # # @param payload [Hash, nil] the response object. # @return [Nfe::ServiceInvoice, nil] +nil+ when +payload+ is +nil+. # rubocop:disable Metrics/MethodLength, Metrics/AbcSize -- wide value-object mapping kept inline for Steep keyword-arg verification def self.from_api(payload) return nil if payload.nil? new( id: payload["id"], flow_status: payload["flowStatus"], flow_message: payload["flowMessage"], status: payload["status"], environment: payload["environment"], rps_number: payload["rpsNumber"], rps_serial_number: payload["rpsSerialNumber"], number: payload["number"], check_code: payload["checkCode"], issued_on: payload["issuedOn"], cancelled_on: payload["cancelledOn"], amount_net: payload["amountNet"], services_amount: payload["servicesAmount"], borrower: ServiceInvoiceBorrower.from_api(payload["borrower"]), city_service_code: payload["cityServiceCode"], federal_service_code: payload["federalServiceCode"], description: payload["description"], pdf: payload["pdf"], xml: payload["xml"], created_on: payload["createdOn"], modified_on: payload["modifiedOn"], base_tax_amount: payload["baseTaxAmount"], iss_rate: payload["issRate"], iss_tax_amount: payload["issTaxAmount"], raw: payload ) end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize end |
#raw ⇒ Hash[untyped, untyped]? (readonly)
Returns the value of attribute raw.
27 28 29 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 27 def raw @raw end |
#rps_number ⇒ Object (readonly)
Returns the value of attribute rps_number.
8 9 10 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 8 def rps_number @rps_number end |
#rps_serial_number ⇒ Object (readonly)
Returns the value of attribute rps_serial_number.
9 10 11 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 9 def rps_serial_number @rps_serial_number end |
#services_amount ⇒ Object (readonly)
Returns the value of attribute services_amount.
15 16 17 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 15 def services_amount @services_amount end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 6 def status @status end |
#xml ⇒ Object (readonly)
Ghost field — the retrieve response carries no xml key
(always nil). Use Resources::ServiceInvoices#download_xml.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/nfe/resources/dto/service_invoice.rb', line 31 class ServiceInvoice < Data.define( :id, :flow_status, :flow_message, :status, :environment, :rps_number, :rps_serial_number, :number, :check_code, :issued_on, :cancelled_on, :amount_net, :services_amount, :borrower, :city_service_code, :federal_service_code, :description, :pdf, :xml, :created_on, :modified_on, :base_tax_amount, :iss_rate, :iss_tax_amount, :raw ) # Build a {Nfe::ServiceInvoice} from an API payload. # # @param payload [Hash, nil] the response object. # @return [Nfe::ServiceInvoice, nil] +nil+ when +payload+ is +nil+. # rubocop:disable Metrics/MethodLength, Metrics/AbcSize -- wide value-object mapping kept inline for Steep keyword-arg verification def self.from_api(payload) return nil if payload.nil? new( id: payload["id"], flow_status: payload["flowStatus"], flow_message: payload["flowMessage"], status: payload["status"], environment: payload["environment"], rps_number: payload["rpsNumber"], rps_serial_number: payload["rpsSerialNumber"], number: payload["number"], check_code: payload["checkCode"], issued_on: payload["issuedOn"], cancelled_on: payload["cancelledOn"], amount_net: payload["amountNet"], services_amount: payload["servicesAmount"], borrower: ServiceInvoiceBorrower.from_api(payload["borrower"]), city_service_code: payload["cityServiceCode"], federal_service_code: payload["federalServiceCode"], description: payload["description"], pdf: payload["pdf"], xml: payload["xml"], created_on: payload["createdOn"], modified_on: payload["modifiedOn"], base_tax_amount: payload["baseTaxAmount"], iss_rate: payload["issRate"], iss_tax_amount: payload["issTaxAmount"], raw: payload ) end # rubocop:enable Metrics/MethodLength, Metrics/AbcSize end |
Class Method Details
.from_api(payload) ⇒ Nfe::ServiceInvoice?
Build a Nfe::ServiceInvoice from an API payload.
rubocop:disable Metrics/MethodLength, Metrics/AbcSize -- wide value-object mapping kept inline for Steep keyword-arg verification
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/nfe/resources/dto/service_invoice.rb', line 63 def self.from_api(payload) return nil if payload.nil? new( id: payload["id"], flow_status: payload["flowStatus"], flow_message: payload["flowMessage"], status: payload["status"], environment: payload["environment"], rps_number: payload["rpsNumber"], rps_serial_number: payload["rpsSerialNumber"], number: payload["number"], check_code: payload["checkCode"], issued_on: payload["issuedOn"], cancelled_on: payload["cancelledOn"], amount_net: payload["amountNet"], services_amount: payload["servicesAmount"], borrower: ServiceInvoiceBorrower.from_api(payload["borrower"]), city_service_code: payload["cityServiceCode"], federal_service_code: payload["federalServiceCode"], description: payload["description"], pdf: payload["pdf"], xml: payload["xml"], created_on: payload["createdOn"], modified_on: payload["modifiedOn"], base_tax_amount: payload["baseTaxAmount"], iss_rate: payload["issRate"], iss_tax_amount: payload["issTaxAmount"], raw: payload ) end |
.new ⇒ instance
31 |
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 31
def self.new: (id: String?, flow_status: String?, flow_message: String?, status: untyped, environment: untyped, rps_number: untyped, rps_serial_number: untyped, number: untyped, check_code: String?, issued_on: String?, cancelled_on: String?, amount_net: untyped, services_amount: untyped, borrower: Nfe::ServiceInvoiceBorrower?, city_service_code: untyped, federal_service_code: untyped, description: String?, pdf: untyped, xml: untyped, created_on: String?, modified_on: String?, base_tax_amount: (Float | Integer)?, iss_rate: (Float | Integer)?, iss_tax_amount: (Float | Integer)?, raw: Hash[untyped, untyped]?) -> instance
|