Class: DefraRubyMocks::WorldpayController

Inherits:
ApplicationController show all
Defined in:
app/controllers/defra_ruby_mocks/worldpay_controller.rb

Instance Method Summary collapse

Instance Method Details

#dispatcherObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/defra_ruby_mocks/worldpay_controller.rb', line 19

def dispatcher
  @response = WorldpayResponseService.run(
    success_url: params[:successURL],
    failure_url: params[:failureURL],
    pending_url: params[:pendingURL],
    cancel_url: params[:cancelURL],
    error_url: params[:errorURL]
  )

  if @response.status == :STUCK
    render formats: :html, action: "stuck", layout: false
  else
    redirect_to @response.url
  end
rescue StandardError => e
  Rails.logger.error("MOCKS: Worldpay dispatcher error: #{e.message}")
  head 500
end

#payments_serviceObject



9
10
11
12
13
14
15
16
17
# File 'app/controllers/defra_ruby_mocks/worldpay_controller.rb', line 9

def payments_service
  @values = WorldpayRequestHandlerService.run(convert_request_body_to_xml)

  render_payment_response if @values[:request_type] == :payment
  render_refund_response if @values[:request_type] == :refund
rescue StandardError => e
  Rails.logger.error("MOCKS: Worldpay payments service error: #{e.message}")
  head 500
end