이 내 지불 컨트롤러
class PaymentsController < ApplicationController
include Przelewy24PaymentController
def index
@payments = Payment.all
end
def show
@payment = Payment.find(params[:id])
@data = { :session_id => @payment.session_id,
:description => @payment.porada.title,
:amount => @payment.porada.cena,
:email => @payment.user.email,
:country => 'PL',
# adding this params, you overwrite your config settings so this param is optional
:merchant_id => ‚XXXXX’,
:pos_id => ‚XXXXX’,
:api_version => '3.2',
:crc_key => ‚XXXXXXXXXXX’,
:currency => 'PLN',
:country => 'PL',
# :url_return => url_return,
# :url_status => url_status,
# other optional params
# :language => pl/en/de/es/it
# :method => method,
# :client => 'Adam Nowak',
# :address => 'Powstancow 22/2',
# :zipcode => '53-456',
# :city => 'Wroclaw',
# :phone => '481321132123',
# :time_limit => INT,
# :wait_for_result => INT,
# :channel => INT,
# :shipping => INT,
# :transfer_label => STRING(20)
# :encoding => ISO-8859-2/UTF-8/Windows-1250
}
end
def new
@payment = Payment.new(:porada_id => params[:id])
end
def edit
end
def create
@payment = Payment.new(payment_params)
@payment.session_id = Przelewy24Payment.friendly_token[0,20]
@payment_porada = @payment.porada
@user = current_user
@payment.user_id = current_user.id
@payment.user = current_user
respond_to do |format|
if @payment.save
format.html { redirect_to @payment, notice: 'Payment was successfully created.' }
format.json { render :show, status: :created, location: @payment }
else
format.html { render :new }
format.json { render json: @payment.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @payment.update(payment_params)
format.html { redirect_to @payment, notice: 'Payment was successfully updated.' }
format.json { render :show, status: :ok, location: @payment }
else
format.html { render :edit }
format.json { render json: @payment.errors, status: :unprocessable_entity }
end
end
end
def destroy
@payment.destroy
respond_to do |format|
format.html { redirect_to payments_url, notice: 'Payment was successfully destroyed.' }
format.json { head :no_content }
end
end
def payment_success(payment_params)
# payment_params returns hash with:
# p24_merchant_id
# p24_pos_id
# p24_session_id
# p24_order_id
# p24_amount
# p24_currency
# p24_method
# p24_sign
# p24_karta
# payment_id
# e.g
# payment = Payment.find_by_session_id(payment_params[:p24_session_id])
end
# after error payment this method will be trigger
# so you can do whatever you want
def payment_error(payment_params, code, description)
# payment_params returns hash with:
# p24_merchant_id
# p24_pos_id
# p24_session_id
# p24_order_id
# p24_amount
# p24_currency
# p24_method
# p24_sign
# p24_karta
# payment_id
#
# code return error code
# description return error description
end
# method to setup params to verify it final verifyciation
# so you can do whatever you want
def payment_verify(response_params)
# e.g:
# you must return hash with amount which was save in your db and your crc_key
payment = Payment::Payment.where(session_id: response_params['p24_session_id']).first
if payment
{ amount: payment.amount, crc_key: Przelewy24Payment.crc_key }
else
{}
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_payment
@payment = Payment.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def payment_params
params.require(:payment).permit(:amount, :porada_id, :user_id)
end
end
이다 그리고이 내장되어 przelewy24_payment 보석에 컴백 작업입니다.
def comeback
result = przelewy24_verify(params,request.remote_ip)
if result.error == "0"
payment_success(params)
else
payment_error(params, result.error, result.errorMessage)
end
end`
데이터는 어쩌면 컨트롤러의 코드를 보여줄 수
<%= payment_button(@data) %>
에 의해 쇼보기에서에서 전송 된? 나는 특히 오류를 던진 줄에 관심이있다. – tpei
물론, 난 그냥 아래에 게시했습니다 –
흠, 나는 당신의 경로가 제대로 설치되지 않았다고 가정합니다. 분명히'/ payments/: id'는 (당신이 Rails의 기본값처럼) show 액션으로 인도하는 경로입니다. 그런 다음'/ payments/comeback'을 호출하면 레일스는'comeback'을 id 매개 변수로 해석하고'comeback'을 ID로 사용하여 지불을 시도하고 실패합니다. – tpei