Class: SpreeCmCommissioner::DraftOrders::Create

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/draft_orders/create.rb

Instance Method Summary collapse

Instance Method Details

#call(line_items:, user: nil, store: nil, currency: nil, tenant: nil, options: {}) ⇒ Object

rubocop:disable Metrics/ParameterLists



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/spree_cm_commissioner/draft_orders/create.rb', line 30

def call(line_items:, user: nil, store: nil, currency: nil, tenant: nil, options: {}) # rubocop:disable Metrics/ParameterLists
  return failure(nil, I18n.t('spree_cm_commissioner.draft_order.line_items_missing')) if line_items.blank?

  # Authorize BEFORE anything is built: a bad token must not leave a half-created order behind.
  # Held on the instance (Spree::ServiceModule builds a fresh one per call) rather than passed
  # down, so the two methods below keep the signatures they had before private sales existed.
  @private_sale = resolve_private_sale(options[:private_sale_token], user)

  order = create_order!(line_items, user, store, currency, tenant, options)
  success(order: order)
rescue StandardError => e
  failure(nil, e.message)
end