Class: DefraRubyMocks::GovpayController

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

Instance Method Summary collapse

Instance Method Details

#create_paymentObject



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

def create_payment
  valid_create_params

  store_return_url(params[:return_url])

  render json: GovpayCreatePaymentService.new.run(
    amount: params[:amount], description: params[:description]
  )
rescue StandardError => e
  Rails.logger.error("MOCKS: Govpay payment creation error: #{e.message}")
  head 500
end

#create_refundObject



43
44
45
46
47
48
49
50
51
# File 'app/controllers/defra_ruby_mocks/govpay_controller.rb', line 43

def create_refund
  valid_create_refund_params
  render json: GovpayRequestRefundService.new.run(payment_id: params[:payment_id],
                                                  amount: params[:amount],
                                                  refund_amount_available: params[:refund_amount_available])
rescue StandardError => e
  Rails.logger.error("MOCKS: Govpay refund error: #{e.message}")
  head 500
end

#next_urlObject

This mocks the Govpay route which presents the payment details page to the user. We don’t mock the actual payment details and payment confirmation pages - we go straight to the application callback route.



24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/defra_ruby_mocks/govpay_controller.rb', line 24

def next_url
  response_url = retrieve_return_url
  Rails.logger.warn "Govpay mock calling response URL #{response_url}"
  redirect_to response_url, allow_other_host: true
rescue RestClient::ExceptionWithResponse => e
  Rails.logger.warn "Govpay mock: RestClient received response: #{e}"
rescue StandardError => e
  Rails.logger.error("Govpay mock: Error sending request to govpay: #{e}")
  Airbrake.notify(e, message: "Error on govpay request")
end

#payment_detailsObject



35
36
37
38
39
40
41
# File 'app/controllers/defra_ruby_mocks/govpay_controller.rb', line 35

def payment_details
  valid_payment_id
  render json: GovpayGetPaymentService.new.run(payment_id: params[:payment_id])
rescue StandardError => e
  Rails.logger.error("MOCKS: Govpay payment details error: #{e.message}")
  head 422
end

#refund_detailsObject



53
54
55
56
57
58
# File 'app/controllers/defra_ruby_mocks/govpay_controller.rb', line 53

def refund_details
  render json: GovpayRefundDetailsService.new.run(payment_id: params[:payment_id], refund_id: params[:refund_id])
rescue StandardError => e
  Rails.logger.error("MOCKS: Govpay refund error: #{e.message}")
  head 500
end