Class: Dscf::Payment::PaymentRequestsController

Inherits:
ApplicationController show all
Includes:
Core::Common
Defined in:
app/controllers/dscf/payment/payment_requests_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



7
8
9
10
11
# File 'app/controllers/dscf/payment/payment_requests_controller.rb', line 7

def create
  super do
    Dscf::Payment::PaymentRequest.new(model_params)
  end
end

#process_paymentObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dscf/payment/payment_requests_controller.rb', line 13

def process_payment
  payment_request = Dscf::Payment::PaymentRequest.find(params[:id])

  unless payment_request.pending?
    return render_error(
      error: "Payment request cannot be processed",
      errors: [ "Payment request status is #{payment_request.status}" ]
    )
  end

  service = Dscf::Payment::PaymentService.new(payment_request, current_user)
  payment = service.process

  render_success(
    data: payment,
    message: "Payment processed successfully"
  )
rescue ActiveRecord::RecordNotFound
  render_error(error: "Payment request not found", status: :not_found)
rescue => e
  render_error(error: "Payment processing failed", errors: [ e.message ])
end