Class: Workarea::Orderbot::SaveOrder

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::CallbacksWorker, Sidekiq::Worker
Defined in:
app/workers/workarea/orderbot/save_order.rb

Defined Under Namespace

Classes: OrderbotSaveOrderError

Instance Method Summary collapse

Instance Method Details

#perform(id) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/workers/workarea/orderbot/save_order.rb', line 13

def perform(id)
  return unless Orderbot.api_configured?

  order = Workarea::Order.find(id)
  orderbot_order = Workarea::Orderbot::Order.new(order.id)
  response = Workarea::Orderbot.gateway.create_order(orderbot_order.to_a)

  raise OrderbotSaveOrderError, response.error_details unless response.success?
  raise OrderbotSaveOrderError, messages(response.body) unless created?(response.body) # checks for a 200 response that fails to create the order

  orderbot_order_id = response.body.first["order_id"]
  order.set_orderbot_exported_data!(orderbot_order_id)
end