Class: SpreeCmCommissioner::IntercityTaxiOrder::Update
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::IntercityTaxiOrder::Update
- Includes:
- Spree::LineItems::Helper, Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/intercity_taxi_order/update.rb
Instance Method Summary collapse
-
#call(order:, remark: nil, passenger_count: nil, pickup_map_place_attributes: nil, dropoff_map_place_attributes: nil, distance_attributes: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Details
#call(order:, remark: nil, passenger_count: nil, pickup_map_place_attributes: nil, dropoff_map_place_attributes: nil, distance_attributes: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/update.rb', line 8 def call( # rubocop:disable Metrics/ParameterLists order:, remark: nil, passenger_count: nil, pickup_map_place_attributes: nil, dropoff_map_place_attributes: nil, distance_attributes: nil ) line_item = order.line_items.first raise ArgumentError, 'Order has no line items' if line_item.blank? if pickup_map_place_attributes.present? line_item.pickup_map_place = SpreeCmCommissioner::IntercityTaxi::MapPlace.new( pickup_map_place_attributes ) end if dropoff_map_place_attributes.present? line_item.dropoff_map_place = SpreeCmCommissioner::IntercityTaxi::MapPlace.new( dropoff_map_place_attributes ) end # Verify signature and extract data for distance if distance_attributes.present? verified_data = verify_and_extract_distance(distance_attributes) return failure(nil, verified_data[:error]) unless verified_data[:success] line_item.distance = SpreeCmCommissioner::Distance.new(verified_data[:value]) end line_item.remark = remark if remark.present? line_item.passenger_count = passenger_count if passenger_count.present? line_item.save! recalculate_service.call(order: order, line_item: line_item) success(order.reload) rescue StandardError => e failure(nil, e.) end |