Class: Spree::Admin::PaymentWingSdkMarkersController

Inherits:
PaymentWingSdkBaseController show all
Includes:
Backend::Callbacks
Defined in:
app/controllers/spree/admin/payment_wing_sdk_markers_controller.rb

Instance Method Summary collapse

Methods inherited from PaymentWingSdkBaseController

#load_payment, #validate_order

Instance Method Details

#updateObject



6
7
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
# File 'app/controllers/spree/admin/payment_wing_sdk_markers_controller.rb', line 6

def update
  reason = params[:updated_reason]&.strip

  if reason.blank?
    flash[:error] = Spree.t('vpago.payments.failed_require_updated_reason')
    return redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
  end

  options = {
    updated_by_user_id: try_spree_current_user.id,
    updated_reason: reason,
    status: true,
    description: 'vpago.payments.mark_with_reason'
  }

  spree_updater = Vpago::PaymentStatusMarker.new(@payment, options)
  spree_updater.call

  @payment.reload

  if @payment.order.completed?
    flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:payments))
  else
    flash[:error] = Spree.t(:unsuccessfully_updated, resource: Spree.t(:payments))
  end

  redirect_to admin_order_payment_path(order_id: @payment.order.number, id: @payment.number)
end