Class: Whatsapp::Webhook::Message::Order

Inherits:
Base
  • Object
show all
Defined in:
lib/ruby/whatsapp/webhook/message/order.rb,
lib/ruby/whatsapp/webhook/message/order/product_item.rb

Overview

An inbound order placed against a Meta catalog.

Defined Under Namespace

Classes: ProductItem

Instance Attribute Summary collapse

Attributes inherited from Base

#context, #from, #id, #referral, #timestamp, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

common_attributes

Constructor Details

#initialize(catalog_id:, product_items:, text: nil, **base_attributes) ⇒ Order

Returns a new instance of Order.



20
21
22
23
24
25
26
# File 'lib/ruby/whatsapp/webhook/message/order.rb', line 20

def initialize(catalog_id:, product_items:, text: nil, **base_attributes)
  super(**base_attributes)

  @catalog_id = catalog_id
  @text = text
  @product_items = product_items
end

Instance Attribute Details

#catalog_idString?

Returns:

  • (String, nil)


10
11
12
# File 'lib/ruby/whatsapp/webhook/message/order.rb', line 10

def catalog_id
  @catalog_id
end

#product_itemsArray<ProductItem>

Returns:



18
19
20
# File 'lib/ruby/whatsapp/webhook/message/order.rb', line 18

def product_items
  @product_items
end

#textString?

Returns Optional note the customer attached to the order.

Returns:

  • (String, nil)

    Optional note the customer attached to the order.



14
15
16
# File 'lib/ruby/whatsapp/webhook/message/order.rb', line 14

def text
  @text
end

Class Method Details

.deserialize(data) ⇒ Order

Parameters:

  • data (Hash)

    The raw message hash.

Returns:



31
32
33
34
35
36
37
38
# File 'lib/ruby/whatsapp/webhook/message/order.rb', line 31

def deserialize(data)
  new(
    catalog_id: data.dig("order", "catalog_id"),
    text: data.dig("order", "text"),
    product_items: Array(data.dig("order", "product_items")).map { |item| ProductItem.deserialize(item) },
    **common_attributes(data)
  )
end