Class: PaymentTest::PaymentsController

Inherits:
EngineController show all
Defined in:
app/controllers/payment_test/payments_controller.rb

Instance Method Summary collapse

Methods inherited from EngineController

#current_tenant_user, #get_layout, #options_for_klient

Instance Method Details

#indexObject



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
34
35
36
37
38
# File 'app/controllers/payment_test/payments_controller.rb', line 7

def index
  raw_status = nil
  begin
    raw_status = ::Killbill::PaymentTest::PaymentTestClient.status(options_for_klient)
  rescue StandardError => e
    Rails.logger.warn("Failed to retrieve payment status : #{e}")
  end

  @status = if raw_status.nil?
              'UNKNOWN'
            elsif raw_status.key? :always_return_plugin_status_error.to_s
              'RETURN ERROR'
            elsif raw_status.key? :always_return_plugin_status_pending.to_s
              'RETURN PENDING'
            elsif raw_status.key? :always_return_plugin_status_canceled.to_s
              'RETURN CANCELED'
            elsif raw_status.key? :always_throw.to_s
              'RETURN THROW'
            elsif raw_status.key? :always_return_nil.to_s
              'RETURN NULL '
            elsif raw_status.key? :sleep_time_sec.to_s
              "SLEEP #{sleep_time_sec}"
            else
              'CLEAR'
            end

  @methods = if raw_status.nil? || !raw_status.key?('methods') || raw_status['methods'].empty?
               ['*']
             else
               raw_status['methods']
             end
end

#resetObject



53
54
55
56
57
58
59
60
# File 'app/controllers/payment_test/payments_controller.rb', line 53

def reset
  begin
    ::Killbill::PaymentTest::PaymentTestClient.reset(nil, options_for_klient)
  rescue StandardError => e
    flash[:error] = "Failed to reset state: #{e}"
  end
  redirect_to root_path and return
end

#set_failed_stateObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/payment_test/payments_controller.rb', line 40

def set_failed_state
  new_state = params.require(:state)
  target_method = "set_status_#{new_state.to_s.downcase}"

  begin
    ::Killbill::PaymentTest::PaymentTestClient.send(target_method, nil, options_for_klient)
  rescue StandardError => e
    flash[:error] = "Failed to set state: #{e}"
  end

  redirect_to root_path and return
end