Class: Nfe::ConsumerInvoice

Inherits:
Data
  • Object
show all
Defined in:
lib/nfe/resources/dto/consumer_invoice.rb,
sig/nfe/resources/dto/consumer_invoice.rbs

Overview

Immutable value object for a consumer invoice (NFC-e — Nota Fiscal de Consumidor Eletrônica) emitted through the NFE.io api.nfse.io v2 API.

Hand-written (rather than reusing the verbose generated nf-consumidor-v2 DTOs) so the public shape stays clean and snake_case. ConsumerInvoice.from_api maps the API camelCase keys onto the snake_case members, drops unknown keys, and is nil-tolerant (+from_api(nil)+ returns nil). The full parsed payload is preserved under raw for forward compatibility.

Shape mirrors POST /v2/companies/{id}/consumerinvoices and GET .../consumerinvoices/{id} per nf-consumidor-v2.yaml.

+number+/+serie+ are kept as returned (no Integer coercion) so leading zeros and string representations from the API survive untouched.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConsumerInvoice

Returns a new instance of ConsumerInvoice.

Parameters:

  • id: (String, nil)
  • status: (Object)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • environment: (String, nil)
  • access_key: (String, nil)
  • number: (Object)
  • serie: (Object)
  • total_amount: (Object)
  • issued_on: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)
  • cancelled_on: (String, nil)
  • raw: (Hash[untyped, untyped], nil)


22
# File 'sig/nfe/resources/dto/consumer_invoice.rbs', line 22

def initialize: (id: String?, status: untyped, flow_status: String?, flow_message: String?, environment: String?, access_key: String?, number: untyped, serie: untyped, total_amount: untyped, issued_on: String?, created_on: String?, modified_on: String?, cancelled_on: String?, raw: Hash[untyped, untyped]?) -> void

Instance Attribute Details

#access_keyString? (readonly)

Returns the value of attribute access_key.

Returns:

  • (String, nil)


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

def access_key
  @access_key
end

#cancelled_onString? (readonly)

Returns the value of attribute cancelled_on.

Returns:

  • (String, nil)


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

def cancelled_on
  @cancelled_on
end

#created_onString? (readonly)

Returns the value of attribute created_on.

Returns:

  • (String, nil)


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

def created_on
  @created_on
end

#environmentString? (readonly)

Returns the value of attribute environment.

Returns:

  • (String, nil)


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

def environment
  @environment
end

#flow_messageString? (readonly)

Returns the value of attribute flow_message.

Returns:

  • (String, nil)


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

def flow_message
  @flow_message
end

#flow_statusString? (readonly)

Returns the value of attribute flow_status.

Returns:

  • (String, nil)


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

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/consumer_invoice.rbs', line 3

def id
  @id
end

#issued_onString? (readonly)

Returns the value of attribute issued_on.

Returns:

  • (String, nil)


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

def issued_on
  @issued_on
end

#modified_onString? (readonly)

Returns the value of attribute modified_on.

Returns:

  • (String, nil)


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

def modified_on
  @modified_on
end

#numberObject (readonly)

Returns the value of attribute number.

Returns:

  • (Object)


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

def number
  @number
end

#rawHash[untyped, untyped]? (readonly)

Returns the value of attribute raw.

Returns:

  • (Hash[untyped, untyped], nil)


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

def raw
  @raw
end

#serieObject (readonly)

Returns the value of attribute serie.

Returns:

  • (Object)


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

def serie
  @serie
end

#statusObject (readonly)

Returns the value of attribute status.

Returns:

  • (Object)


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

def status
  @status
end

#total_amountObject (readonly)

Returns the value of attribute total_amount.

Returns:

  • (Object)


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

def total_amount
  @total_amount
end

Class Method Details

.from_api(payload) ⇒ Nfe::ConsumerInvoice?

Build a Nfe::ConsumerInvoice from an API payload.

Parameters:

  • payload (Hash, nil)

    the parsed consumer-invoice object.

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nfe/resources/dto/consumer_invoice.rb', line 38

def self.from_api(payload)
  return nil if payload.nil?

  new(
    id: payload["id"],
    status: payload["status"],
    flow_status: payload["flowStatus"],
    flow_message: payload["flowMessage"],
    environment: payload["environment"],
    access_key: payload["accessKey"],
    number: payload["number"],
    serie: payload["serie"],
    total_amount: payload["totalAmount"],
    issued_on: payload["issuedOn"],
    created_on: payload["createdOn"],
    modified_on: payload["modifiedOn"],
    cancelled_on: payload["cancelledOn"],
    raw: payload
  )
end

.newinstance

Parameters:

  • id: (String, nil)
  • status: (Object)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • environment: (String, nil)
  • access_key: (String, nil)
  • number: (Object)
  • serie: (Object)
  • total_amount: (Object)
  • issued_on: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)
  • cancelled_on: (String, nil)
  • raw: (Hash[untyped, untyped], nil)

Returns:

  • (instance)


20
# File 'sig/nfe/resources/dto/consumer_invoice.rbs', line 20

def self.new: (id: String?, status: untyped, flow_status: String?, flow_message: String?, environment: String?, access_key: String?, number: untyped, serie: untyped, total_amount: untyped, issued_on: String?, created_on: String?, modified_on: String?, cancelled_on: String?, raw: Hash[untyped, untyped]?) -> instance