Class: Nfe::ServiceInvoice

Inherits:
Data
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServiceInvoice

Returns a new instance of ServiceInvoice.

Parameters:

  • id: (String, nil)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • status: (Object)
  • environment: (Object)
  • rps_number: (Object)
  • rps_serial_number: (Object)
  • number: (Object)
  • check_code: (String, nil)
  • issued_on: (String, nil)
  • cancelled_on: (String, nil)
  • amount_net: (Object)
  • services_amount: (Object)
  • borrower: (Nfe::ServiceInvoiceBorrower, nil)
  • city_service_code: (Object)
  • federal_service_code: (Object)
  • description: (String, nil)
  • pdf: (Object)
  • xml: (Object)
  • created_on: (String, nil)
  • modified_on: (String, nil)
  • base_tax_amount: (Float, Integer, nil)
  • iss_rate: (Float, Integer, nil)
  • iss_tax_amount: (Float, Integer, nil)
  • raw: (Hash[untyped, untyped], nil)


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_netObject (readonly)

Returns the value of attribute amount_net.

Returns:

  • (Object)


14
15
16
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 14

def amount_net
  @amount_net
end

#base_tax_amountFloat, ... (readonly)

Returns the value of attribute base_tax_amount.

Returns:

  • (Float, Integer, nil)


24
25
26
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 24

def base_tax_amount
  @base_tax_amount
end

#borrowerNfe::ServiceInvoiceBorrower? (readonly)

Returns the value of attribute borrower.

Returns:



16
17
18
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 16

def borrower
  @borrower
end

#cancelled_onString? (readonly)

Returns the value of attribute cancelled_on.

Returns:

  • (String, nil)


13
14
15
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 13

def cancelled_on
  @cancelled_on
end

#check_codeString? (readonly)

Returns the value of attribute check_code.

Returns:

  • (String, nil)


11
12
13
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 11

def check_code
  @check_code
end

#city_service_codeObject (readonly)

Returns the value of attribute city_service_code.

Returns:

  • (Object)


17
18
19
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 17

def city_service_code
  @city_service_code
end

#created_onString? (readonly)

Returns the value of attribute created_on.

Returns:

  • (String, nil)


22
23
24
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 22

def created_on
  @created_on
end

#descriptionString? (readonly)

Returns the value of attribute description.

Returns:

  • (String, nil)


19
20
21
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 19

def description
  @description
end

#environmentObject (readonly)

Returns the value of attribute environment.

Returns:

  • (Object)


7
8
9
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 7

def environment
  @environment
end

#federal_service_codeObject (readonly)

Returns the value of attribute federal_service_code.

Returns:

  • (Object)


18
19
20
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 18

def federal_service_code
  @federal_service_code
end

#flow_messageString? (readonly)

Returns the value of attribute flow_message.

Returns:

  • (String, nil)


5
6
7
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 5

def flow_message
  @flow_message
end

#flow_statusString? (readonly)

Returns the value of attribute flow_status.

Returns:

  • (String, nil)


4
5
6
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 4

def flow_status
  @flow_status
end

#idString? (readonly)

Returns the value of attribute id.

Returns:

  • (String, nil)


3
4
5
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 3

def id
  @id
end

#iss_rateFloat, ... (readonly)

Returns the value of attribute iss_rate.

Returns:

  • (Float, Integer, nil)


25
26
27
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 25

def iss_rate
  @iss_rate
end

#iss_tax_amountFloat, ... (readonly)

Returns the value of attribute iss_tax_amount.

Returns:

  • (Float, Integer, nil)


26
27
28
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 26

def iss_tax_amount
  @iss_tax_amount
end

#issued_onString? (readonly)

Returns the value of attribute issued_on.

Returns:

  • (String, nil)


12
13
14
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 12

def issued_on
  @issued_on
end

#modified_onString? (readonly)

Returns the value of attribute modified_on.

Returns:

  • (String, nil)


23
24
25
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 23

def modified_on
  @modified_on
end

#numberObject (readonly)

Returns the value of attribute number.

Returns:

  • (Object)


10
11
12
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 10

def number
  @number
end

#pdfObject (readonly)

Deprecated.

Ghost field — the retrieve response carries no pdf key (always nil). Use Resources::ServiceInvoices#download_pdf.

Returns:

  • (Object)


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

#rawHash[untyped, untyped]? (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[untyped, untyped], nil)


27
28
29
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 27

def raw
  @raw
end

#rps_numberObject (readonly)

Returns the value of attribute rps_number.

Returns:

  • (Object)


8
9
10
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 8

def rps_number
  @rps_number
end

#rps_serial_numberObject (readonly)

Returns the value of attribute rps_serial_number.

Returns:

  • (Object)


9
10
11
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 9

def rps_serial_number
  @rps_serial_number
end

#services_amountObject (readonly)

Returns the value of attribute services_amount.

Returns:

  • (Object)


15
16
17
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 15

def services_amount
  @services_amount
end

#statusObject (readonly)

Returns the value of attribute status.

Returns:

  • (Object)


6
7
8
# File 'sig/nfe/resources/dto/service_invoice.rbs', line 6

def status
  @status
end

#xmlObject (readonly)

Deprecated.

Ghost field — the retrieve response carries no xml key (always nil). Use Resources::ServiceInvoices#download_xml.

Returns:

  • (Object)


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

Parameters:

  • payload (Hash, nil)

    the response object.

Returns:



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

.newinstance

Parameters:

  • id: (String, nil)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • status: (Object)
  • environment: (Object)
  • rps_number: (Object)
  • rps_serial_number: (Object)
  • number: (Object)
  • check_code: (String, nil)
  • issued_on: (String, nil)
  • cancelled_on: (String, nil)
  • amount_net: (Object)
  • services_amount: (Object)
  • borrower: (Nfe::ServiceInvoiceBorrower, nil)
  • city_service_code: (Object)
  • federal_service_code: (Object)
  • description: (String, nil)
  • pdf: (Object)
  • xml: (Object)
  • created_on: (String, nil)
  • modified_on: (String, nil)
  • base_tax_amount: (Float, Integer, nil)
  • iss_rate: (Float, Integer, nil)
  • iss_tax_amount: (Float, Integer, nil)
  • raw: (Hash[untyped, untyped], nil)

Returns:

  • (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