Class: Nfe::TaxCoupon

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

Overview

Immutable value object for a consumer-invoice tax coupon (CFe-SAT) returned by the nfe.api.nfe.io query API (+GET /v1/consumerinvoices/coupon/accessKey+).

This is the QUERY (consulta) of an already-issued coupon by access key and is DISTINCT from ConsumerInvoice (the emission model handled by Resources::ConsumerInvoices) — different host and API version.

All fields are optional; TaxCoupon.from_api maps the API camelCase keys onto the snake_case members, hydrates the nested value objects, and is nil-tolerant (+from_api(nil)+ returns nil). The nested objects (Issuer, Buyer, Total, Delivery, AdditionalInformation, Item, Payment) keep only a pragmatic subset of the most common fields, mapped against the real CFe-SAT TaxCouponResource shape.

Defined Under Namespace

Classes: AdditionalInformation, Address, Buyer, Delivery, Issuer, Item, Payment, PaymentDetail, Total

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTaxCoupon

Returns a new instance of TaxCoupon.

Parameters:



115
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 115

def initialize: (current_status: untyped, number: untyped, sat_serie: untyped, software_version: String?, software_federal_tax_number: untyped, access_key: untyped, cashier: untyped, issued_on: String?, created_on: String?, xml_version: String?, issuer: Nfe::TaxCoupon::Issuer?, buyer: Nfe::TaxCoupon::Buyer?, totals: Nfe::TaxCoupon::Total?, delivery: Nfe::TaxCoupon::Delivery?, additional_information: Nfe::TaxCoupon::AdditionalInformation?, items: Array[Nfe::TaxCoupon::Item?], payment: Nfe::TaxCoupon::Payment?) -> void

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.

Returns:

  • (Object)


100
101
102
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 100

def access_key
  @access_key
end

#additional_informationNfe::TaxCoupon::AdditionalInformation? (readonly)

Returns the value of attribute additional_information.



109
110
111
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 109

def additional_information
  @additional_information
end

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

Returns the value of attribute buyer.

Returns:



106
107
108
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 106

def buyer
  @buyer
end

#cashierObject (readonly)

Returns the value of attribute cashier.

Returns:

  • (Object)


101
102
103
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 101

def cashier
  @cashier
end

#created_onString? (readonly)

Returns the value of attribute created_on.

Returns:

  • (String, nil)


103
104
105
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 103

def created_on
  @created_on
end

#current_statusObject (readonly)

Returns the value of attribute current_status.

Returns:

  • (Object)


95
96
97
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 95

def current_status
  @current_status
end

#deliveryNfe::TaxCoupon::Delivery? (readonly)

Returns the value of attribute delivery.

Returns:



108
109
110
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 108

def delivery
  @delivery
end

#issued_onString? (readonly)

Returns the value of attribute issued_on.

Returns:

  • (String, nil)


102
103
104
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 102

def issued_on
  @issued_on
end

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

Returns the value of attribute issuer.

Returns:



105
106
107
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 105

def issuer
  @issuer
end

#itemsArray[Nfe::TaxCoupon::Item?] (readonly)

Returns the value of attribute items.

Returns:



110
111
112
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 110

def items
  @items
end

#numberObject (readonly)

Returns the value of attribute number.

Returns:

  • (Object)


96
97
98
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 96

def number
  @number
end

#paymentNfe::TaxCoupon::Payment? (readonly)

Returns the value of attribute payment.

Returns:



111
112
113
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 111

def payment
  @payment
end

#sat_serieObject (readonly)

Returns the value of attribute sat_serie.

Returns:

  • (Object)


97
98
99
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 97

def sat_serie
  @sat_serie
end

#software_federal_tax_numberObject (readonly)

Returns the value of attribute software_federal_tax_number.

Returns:

  • (Object)


99
100
101
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 99

def software_federal_tax_number
  @software_federal_tax_number
end

#software_versionString? (readonly)

Returns the value of attribute software_version.

Returns:

  • (String, nil)


98
99
100
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 98

def software_version
  @software_version
end

#totalsNfe::TaxCoupon::Total? (readonly)

Returns the value of attribute totals.

Returns:



107
108
109
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 107

def totals
  @totals
end

#xml_versionString? (readonly)

Returns the value of attribute xml_version.

Returns:

  • (String, nil)


104
105
106
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 104

def xml_version
  @xml_version
end

Class Method Details

.from_api(payload) ⇒ Nfe::TaxCoupon?

Build a Nfe::TaxCoupon from an API payload.

rubocop:disable Metrics/AbcSize -- wide value-object mapping kept inline for Steep keyword-arg verification

Parameters:

  • payload (Hash, nil)

    the parsed coupon object.

Returns:



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/nfe/resources/dto/consumer_invoice_query/tax_coupon.rb', line 165

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

  new(
    current_status: payload["currentStatus"],
    number: payload["number"],
    sat_serie: payload["satSerie"]&.to_s,
    software_version: payload["softwareVersion"],
    software_federal_tax_number: payload["softwareFederalTaxNumber"]&.to_s,
    access_key: payload["accessKey"]&.to_s,
    cashier: payload["cashier"],
    issued_on: payload["issuedOn"],
    created_on: payload["createdOn"],
    xml_version: payload["xmlVersion"],
    issuer: Issuer.from_api(payload["issuer"]),
    buyer: Buyer.from_api(payload["buyer"]),
    totals: Total.from_api(payload["totals"]),
    delivery: Delivery.from_api(payload["delivery"]),
    additional_information: AdditionalInformation.from_api(payload["additionalInformation"]),
    items: (payload["items"] || []).map { |i| Item.from_api(i) },
    payment: Payment.from_api(payload["payment"])
  )
end

.newinstance

Parameters:

Returns:

  • (instance)


114
# File 'sig/nfe/resources/dto/consumer_invoice_query/tax_coupon.rbs', line 114

def self.new: (current_status: untyped, number: untyped, sat_serie: untyped, software_version: String?, software_federal_tax_number: untyped, access_key: untyped, cashier: untyped, issued_on: String?, created_on: String?, xml_version: String?, issuer: Nfe::TaxCoupon::Issuer?, buyer: Nfe::TaxCoupon::Buyer?, totals: Nfe::TaxCoupon::Total?, delivery: Nfe::TaxCoupon::Delivery?, additional_information: Nfe::TaxCoupon::AdditionalInformation?, items: Array[Nfe::TaxCoupon::Item?], payment: Nfe::TaxCoupon::Payment?) -> instance