Class: PaymentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- PaymentsController
- Includes:
- Tosspayments2::Rails::ControllerConcern
- Defined in:
- lib/generators/tosspayments2/install/templates/payments_controller.rb
Instance Method Summary collapse
- #cancel ⇒ Object
- #checkout ⇒ Object
- #create ⇒ Object
- #fail ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #success ⇒ Object
Instance Method Details
#cancel ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 57 def cancel toss_client.cancel( payment_key: @payment.transaction_id, cancel_reason: params[:cancel_reason] || '고객 요청에 의한 취소' ) @payment.update!(status: 'cancelled') redirect_to @payment, notice: '결제가 취소되었습니다.' rescue Tosspayments2::Rails::APIError => e Rails.logger.error("Payment cancel error: #{e.message}") redirect_to @payment, alert: '결제 취소에 실패했습니다.' end |
#checkout ⇒ Object
31 32 33 34 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 31 def checkout @order_id = params[:order_id] @payment = Payment.find_by!(order_id: @order_id) end |
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 19 def create @payment = Payment.new(payment_params) @payment.status = 'pending' @payment.order_id = "ORDER-#{Time.current.strftime('%Y%m%d%H%M%S')}-#{SecureRandom.hex(4)}" if @payment.save redirect_to checkout_payments_path(order_id: @payment.order_id) else render :new, status: :unprocessable_entity end end |
#fail ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 45 def fail order_id = params[:orderId] # 실패 시 Payment 상태 업데이트 if order_id && (payment = Payment.find_by(order_id: order_id)) payment.update(status: 'failed') end flash[:alert] = "결제 실패: #{params[:message] || params[:errorMessage]}" redirect_to root_path end |
#index ⇒ Object
8 9 10 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 8 def index @payments = Payment.order(created_at: :desc) end |
#new ⇒ Object
14 15 16 17 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 14 def new @payment = Payment.new @order_id = "ORDER-#{Time.current.strftime('%Y%m%d%H%M%S')}-#{SecureRandom.hex(4)}" end |
#show ⇒ Object
12 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 12 def show; end |
#success ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/generators/tosspayments2/install/templates/payments_controller.rb', line 36 def success load_params verify_amount! process_payment_confirmation redirect_to @payment, notice: '결제가 성공적으로 완료되었습니다.' rescue Tosspayments2::Rails::VerificationError, Tosspayments2::Rails::APIError => e handle_payment_error(e) end |