Class: Inttegro::Order::LineItemGroup

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/inttegro/order/line_item_group.rb

Overview

Cart contents and totals

This generated model is immutable. Construct it with .new, or decode a string-keyed API payload with .from_hash. #serialize produces a string-keyed hash using the original wire field names and serialized enum values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#line_items ⇒ Array<Inttegro::Order::LineItem> (readonly)

Array of products, fees, and shipping charges

Required in the API payload. Wire name: line_items.

Returns:



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
# File 'lib/inttegro/order/line_item_group.rb', line 31

class LineItemGroup < T::Struct
  const :line_items, T::Array[Inttegro::Order::LineItem]
  const :total, Inttegro::Money::Amount

  extend T::Sig

  sig { params(hash: T::Hash[String, Object], strict: T::Boolean).returns(T.attached_class) }
  def self.from_hash(hash, strict = false)
    data = hash.dup
    if (line_items_value = data["line_items"]).is_a?(Array)
      data["line_items"] = line_items_value.map do |item|
        next item unless item.is_a?(Hash)
        case item["type"]
        when "product"
          Inttegro::Order::ProductLineItem.from_hash(item)
        when "fee"
          Inttegro::Order::FeeLineItem.from_hash(item)
        when "shipping"
          Inttegro::Order::ShippingLineItem.from_hash(item)
        when "discount"
          Inttegro::Order::DiscountLineItem.from_hash(item)
        else
          item
        end
      end
    end
    super(data, strict)
  end
end

#total ⇒ Inttegro::Money::Amount (readonly)

Value of the total field in the Inttegro API payload.

Required in the API payload. Wire name: total.



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
# File 'lib/inttegro/order/line_item_group.rb', line 31

class LineItemGroup < T::Struct
  const :line_items, T::Array[Inttegro::Order::LineItem]
  const :total, Inttegro::Money::Amount

  extend T::Sig

  sig { params(hash: T::Hash[String, Object], strict: T::Boolean).returns(T.attached_class) }
  def self.from_hash(hash, strict = false)
    data = hash.dup
    if (line_items_value = data["line_items"]).is_a?(Array)
      data["line_items"] = line_items_value.map do |item|
        next item unless item.is_a?(Hash)
        case item["type"]
        when "product"
          Inttegro::Order::ProductLineItem.from_hash(item)
        when "fee"
          Inttegro::Order::FeeLineItem.from_hash(item)
        when "shipping"
          Inttegro::Order::ShippingLineItem.from_hash(item)
        when "discount"
          Inttegro::Order::DiscountLineItem.from_hash(item)
        else
          item
        end
      end
    end
    super(data, strict)
  end
end

Class Method Details

.from_hash(hash, strict = false) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/inttegro/order/line_item_group.rb', line 38

def self.from_hash(hash, strict = false)
  data = hash.dup
  if (line_items_value = data["line_items"]).is_a?(Array)
    data["line_items"] = line_items_value.map do |item|
      next item unless item.is_a?(Hash)
      case item["type"]
      when "product"
        Inttegro::Order::ProductLineItem.from_hash(item)
      when "fee"
        Inttegro::Order::FeeLineItem.from_hash(item)
      when "shipping"
        Inttegro::Order::ShippingLineItem.from_hash(item)
      when "discount"
        Inttegro::Order::DiscountLineItem.from_hash(item)
      else
        item
      end
    end
  end
  super(data, strict)
end