Class: Workarea::GlobalE::Api::SendOrderToMerchant

Inherits:
Object
  • Object
show all
Defined in:
app/services/workarea/global_e/api/send_order_to_merchant.rb

Defined Under Namespace

Classes: ItemPricer, SaveUser

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(order, merchant_order) ⇒ SendOrderToMerchant

Returns a new instance of SendOrderToMerchant.



7
8
9
10
11
12
13
14
15
# File 'app/services/workarea/global_e/api/send_order_to_merchant.rb', line 7

def initialize(order, merchant_order)
  @order = order
  @merchant_order = merchant_order
  @order_discount_price_adjustments = order
    .price_adjustments
    .discounts
    .select { |pa| pa.price == "order" }
    .group_discounts_by_id
end

Instance Attribute Details

#merchant_orderObject (readonly)

Returns the value of attribute merchant_order.



5
6
7
# File 'app/services/workarea/global_e/api/send_order_to_merchant.rb', line 5

def merchant_order
  @merchant_order
end

#orderObject (readonly)

Returns the value of attribute order.



5
6
7
# File 'app/services/workarea/global_e/api/send_order_to_merchant.rb', line 5

def order
  @order
end

#order_discount_price_adjustmentsObject (readonly)

Returns the value of attribute order_discount_price_adjustments.



5
6
7
# File 'app/services/workarea/global_e/api/send_order_to_merchant.rb', line 5

def order_discount_price_adjustments
  @order_discount_price_adjustments
end

Instance Method Details

#responseObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/services/workarea/global_e/api/send_order_to_merchant.rb', line 17

def response
  @response ||=
    begin
      with_order_lock do
        set_product_prices
        set_order_discounts
        update_order
        save_shippings
        save_payment
        save_user

        raise GlobalE::UnpurchasableOrder, order.errors.full_messages.join("\n") unless @order.valid?(:purchasable)

        capture_invetory
        place_order
        place_order_side_effects

        Workarea::GlobalE::Merchant::ResponseInfo.new(order: order)
      end
    end
end