Class: Nfe::ProductInvoiceDetails

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

Overview

Immutable value object for the details of a product invoice (NF-e) fetched from the nfe.api.nfe.io distribution/query API by its access key (+GET /v2/productinvoices/accessKey+).

Hand-written (the consulta_nfe_distribuicao_v1 generated schema does not cover this pragmatic shape). ProductInvoiceDetails.from_api maps the API camelCase keys onto the snake_case members, hydrates the nested value objects, drops unknown keys, and is nil-tolerant (+from_api(nil)+ returns nil). All fields are optional.

The access key is NOT a body field — it is the path parameter the caller already holds — so it is intentionally not exposed here. current_status is the real top-level field (+currentStatus+, enum +unknown+/+authorized+/ canceled). The nested objects (Issuer, Buyer, Totals) keep only a pragmatic subset of the most common fields; items is kept as the raw payload array (free-form line bodies), normalized to [] when missing.

Defined Under Namespace

Classes: Buyer, Issuer, Totals

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProductInvoiceDetails

Returns a new instance of ProductInvoiceDetails.

Parameters:



51
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 51

def initialize: (current_status: String?, state_code: untyped, check_code: String?, operation_nature: String?, serie: untyped, number: untyped, issued_on: String?, operation_on: String?, issuer: Nfe::ProductInvoiceDetails::Issuer?, buyer: Nfe::ProductInvoiceDetails::Buyer?, totals: Nfe::ProductInvoiceDetails::Totals?, items: untyped) -> void

Instance Attribute Details

#buyerNfe::ProductInvoiceDetails::Buyer? (readonly)

Returns the value of attribute buyer.



45
46
47
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 45

def buyer
  @buyer
end

#check_codeString? (readonly)

Returns the value of attribute check_code.

Returns:

  • (String, nil)


38
39
40
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 38

def check_code
  @check_code
end

#current_statusString? (readonly)

Returns the value of attribute current_status.

Returns:

  • (String, nil)


36
37
38
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 36

def current_status
  @current_status
end

#issued_onString? (readonly)

Returns the value of attribute issued_on.

Returns:

  • (String, nil)


42
43
44
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 42

def issued_on
  @issued_on
end

#issuerNfe::ProductInvoiceDetails::Issuer? (readonly)

Returns the value of attribute issuer.



44
45
46
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 44

def issuer
  @issuer
end

#itemsObject (readonly)

Returns the value of attribute items.

Returns:

  • (Object)


47
48
49
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 47

def items
  @items
end

#numberObject (readonly)

Returns the value of attribute number.

Returns:

  • (Object)


41
42
43
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 41

def number
  @number
end

#operation_natureString? (readonly)

Returns the value of attribute operation_nature.

Returns:

  • (String, nil)


39
40
41
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 39

def operation_nature
  @operation_nature
end

#operation_onString? (readonly)

Returns the value of attribute operation_on.

Returns:

  • (String, nil)


43
44
45
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 43

def operation_on
  @operation_on
end

#serieObject (readonly)

Returns the value of attribute serie.

Returns:

  • (Object)


40
41
42
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 40

def serie
  @serie
end

#state_codeObject (readonly)

Returns the value of attribute state_code.

Returns:

  • (Object)


37
38
39
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 37

def state_code
  @state_code
end

#totalsNfe::ProductInvoiceDetails::Totals? (readonly)

Returns the value of attribute totals.



46
47
48
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 46

def totals
  @totals
end

Class Method Details

.from_api(payload) ⇒ Nfe::ProductInvoiceDetails?

Build a Nfe::ProductInvoiceDetails from an API payload.

Parameters:

  • payload (Hash, nil)

    the parsed invoice object.

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/nfe/resources/dto/product_invoice_query/product_invoice_details.rb', line 80

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

  new(
    current_status: payload["currentStatus"],
    state_code: payload["stateCode"],
    check_code: payload["checkCode"]&.to_s,
    operation_nature: payload["operationNature"],
    serie: payload["serie"],
    number: payload["number"],
    issued_on: payload["issuedOn"],
    operation_on: payload["operationOn"],
    issuer: Issuer.from_api(payload["issuer"]),
    buyer: Buyer.from_api(payload["buyer"]),
    totals: Totals.from_api(payload["totals"]),
    items: payload["items"] || []
  )
end

.newinstance

Parameters:

Returns:

  • (instance)


50
# File 'sig/nfe/resources/dto/product_invoice_query/product_invoice_details.rbs', line 50

def self.new: (current_status: String?, state_code: untyped, check_code: String?, operation_nature: String?, serie: untyped, number: untyped, issued_on: String?, operation_on: String?, issuer: Nfe::ProductInvoiceDetails::Issuer?, buyer: Nfe::ProductInvoiceDetails::Buyer?, totals: Nfe::ProductInvoiceDetails::Totals?, items: untyped) -> instance