Class: DefraRubyMocks::GovpayController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DefraRubyMocks::GovpayController
- Defined in:
- app/controllers/defra_ruby_mocks/govpay_controller.rb
Instance Method Summary collapse
- #create_payment ⇒ Object
- #create_refund ⇒ Object
-
#next_url ⇒ Object
This mocks the Govpay route which presents the payment details page to the user.
- #payment_details ⇒ Object
- #refund_details ⇒ Object
Instance Method Details
#create_payment ⇒ Object
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.}") head 500 end |
#create_refund ⇒ Object
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.}") head 500 end |
#next_url ⇒ Object
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_details ⇒ Object
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.}") head 422 end |
#refund_details ⇒ Object
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.}") head 500 end |