Class: Nfe::ProductInvoice

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

Overview

Immutable value object for a product invoice (NF-e) as returned by the NFE.io api.nfse.io/v2 product-invoice API.

Hand-written (rather than reusing the verbose/mangled generated nf_produto_v2 DTO names) so the public shape stays clean and snake_case. ProductInvoice.from_api maps the API camelCase keys onto snake_case members, drops unknown keys, and is nil-tolerant (+from_api(nil)+ returns nil).

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

#initializeProductInvoice

Returns a new instance of ProductInvoice.

Parameters:

  • id: (String, nil)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • status: (Object)
  • environment: (Object)
  • serie: (Object)
  • number: (Object)
  • operation_nature: (Object)
  • operation_type: (Object)
  • access_key: (String, nil)
  • protocol: (Object)
  • buyer: (Object)
  • items: (Object)
  • totals: (Object)
  • issued_on: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)


24
# File 'sig/nfe/resources/dto/product_invoice.rbs', line 24

def initialize: (id: String?, flow_status: String?, flow_message: String?, status: untyped, environment: untyped, serie: untyped, number: untyped, operation_nature: untyped, operation_type: untyped, access_key: String?, protocol: untyped, buyer: untyped, items: untyped, totals: untyped, issued_on: String?, created_on: String?, modified_on: String?) -> void

Instance Attribute Details

#access_keyString? (readonly)

Returns the value of attribute access_key.

Returns:

  • (String, nil)


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

def access_key
  @access_key
end

#buyerObject (readonly)

Returns the value of attribute buyer.

Returns:

  • (Object)


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

def buyer
  @buyer
end

#created_onString? (readonly)

Returns the value of attribute created_on.

Returns:

  • (String, nil)


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

def created_on
  @created_on
end

#environmentObject (readonly)

Returns the value of attribute environment.

Returns:

  • (Object)


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

def environment
  @environment
end

#flow_messageString? (readonly)

Returns the value of attribute flow_message.

Returns:

  • (String, nil)


5
6
7
# File 'sig/nfe/resources/dto/product_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/product_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/product_invoice.rbs', line 3

def id
  @id
end

#issued_onString? (readonly)

Returns the value of attribute issued_on.

Returns:

  • (String, nil)


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

def issued_on
  @issued_on
end

#itemsObject (readonly)

Returns the value of attribute items.

Returns:

  • (Object)


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

def items
  @items
end

#modified_onString? (readonly)

Returns the value of attribute modified_on.

Returns:

  • (String, nil)


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

def modified_on
  @modified_on
end

#numberObject (readonly)

Returns the value of attribute number.

Returns:

  • (Object)


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

def number
  @number
end

#operation_natureObject (readonly)

Returns the value of attribute operation_nature.

Returns:

  • (Object)


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

def operation_nature
  @operation_nature
end

#operation_typeObject (readonly)

Returns the value of attribute operation_type.

Returns:

  • (Object)


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

def operation_type
  @operation_type
end

#protocolObject (readonly)

Returns the value of attribute protocol.

Returns:

  • (Object)


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

def protocol
  @protocol
end

#serieObject (readonly)

Returns the value of attribute serie.

Returns:

  • (Object)


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

def serie
  @serie
end

#statusObject (readonly)

Returns the value of attribute status.

Returns:

  • (Object)


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

def status
  @status
end

#totalsObject (readonly)

Returns the value of attribute totals.

Returns:

  • (Object)


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

def totals
  @totals
end

Class Method Details

.from_api(payload) ⇒ Nfe::ProductInvoice?

Build a Nfe::ProductInvoice from an API payload.

Parameters:

  • payload (Hash, nil)

    the response object.

Returns:



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

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"],
    serie: payload["serie"],
    number: payload["number"],
    operation_nature: payload["operationNature"],
    operation_type: payload["operationType"],
    access_key: payload["accessKey"],
    protocol: payload["protocol"],
    buyer: payload["buyer"],
    items: payload["items"],
    totals: payload["totals"],
    issued_on: payload["issuedOn"],
    created_on: payload["createdOn"],
    modified_on: payload["modifiedOn"]
  )
end

.newinstance

Parameters:

  • id: (String, nil)
  • flow_status: (String, nil)
  • flow_message: (String, nil)
  • status: (Object)
  • environment: (Object)
  • serie: (Object)
  • number: (Object)
  • operation_nature: (Object)
  • operation_type: (Object)
  • access_key: (String, nil)
  • protocol: (Object)
  • buyer: (Object)
  • items: (Object)
  • totals: (Object)
  • issued_on: (String, nil)
  • created_on: (String, nil)
  • modified_on: (String, nil)

Returns:

  • (instance)


23
# File 'sig/nfe/resources/dto/product_invoice.rbs', line 23

def self.new: (id: String?, flow_status: String?, flow_message: String?, status: untyped, environment: untyped, serie: untyped, number: untyped, operation_nature: untyped, operation_type: untyped, access_key: String?, protocol: untyped, buyer: untyped, items: untyped, totals: untyped, issued_on: String?, created_on: String?, modified_on: String?) -> instance