Class: DefraRubyMocks::GovpayController

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

Constant Summary

Constants included from CanUseAwsS3

CanUseAwsS3::DEFAULT_LAST_REFUND_REQUEST_TIME

Instance Method Summary collapse

Instance Method Details

#create_paymentObject



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

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("[DefraRubyMocks] [create_payment] error: #{e}")
  head 500
end

#create_refundObject



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

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("[DefraRubyMocks] [create_refund] error: #{e}")
  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.



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

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

#payment_detailsObject



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

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

#refund_detailsObject



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

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