lib/wolf_core/application/integrations/orders_api_operations.rb



module WolfCore
  module Integrations
    module OrdersApiOperations
      include WolfCore::HttpOperations

      def fetch_order!(wolf_token:, order_id:, tenant:, wolf_platform_url:, error_message:)
        response = safe_http_get(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/orders/#{order_id}",
          query: { tenant: tenant },
          error_message: error_message
        )
        response_body = response.body
        response_body.dig("data", "table", "order")
      end

      def fetch_order(wolf_token:, order_id:, tenant:, wolf_platform_url:)
        http_get(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/orders/#{order_id}",
          query: { tenant: tenant }
        )
      end

      def create_order!(wolf_token:, order:, tenant:, wolf_platform_url:, error_message:)
        safe_http_post(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/orders",
          query: { tenant: tenant },
          body: order,
          error_message: error_message
        )
      end

      def create_order(wolf_token:, order:, tenant:, wolf_platform_url:)
        http_post(
          headers: { "Authorization" => "Bearer #{wolf_token}" },
          url: "#{wolf_platform_url}/api/v2/orders",
          query: { tenant: tenant },
          body: order
        )
      end
    end
  end
end