2017-03-19 2 views
0

나는이 보석을 통해 내 애플 리케이션에 Przelewy24 결제 시스템을 구현하기 위해 노력하고있어 : https://github.com/jcieslar/przelewy24_payment루비 전무에 대한 레일 Przelewy24 지불 시스템 구현, 정의되지 않은 메서드`force_encoding '에 : NilClass

하지만 지불에 문제가 확인이 정확하게 이 오류를 받고 있어요 :

NoMethodError in PaymentsController#comeback 
undefined method `force_encoding' for nil:NilClass 

은 아마 이것이 내가있는 방법 오류를 요청 매개 변수와 응답 헤더를 받고하지하고 때 것은 아무것도 없기 때문에 Przelewy24로부터 데이터를 수신의 문제입니다. 내가 직접 에 URL이 '/ 결제/복귀'을 url_status 및 url_return를 설정할 수 없습니다

Przelewy24Payment.setup do |config| 
    config.merchant_id = 'XXXXX' 
    config.pos_id = 'XXXXX' 
    config.crc_key = 'XXXXXXXXXXXXXXXXXXXX' 
    config.language = 'pl' 
    config.currency = 'PLN' 
    config.country = 'PL' 
    config.mode = :development 
    config.url_status = '/kam' 
    config.url_return = '/kam' 
    config.hostname = { 
     :development => "http://127.0.0.1:3000", 
     :production => "mydomain.pl", 
     :staging => "staging.domain" 
    } 
end 

그리고 /캄

get '/kam' => 'payments#comeback' 

내 경로 : 이 내 config 파일입니다 내 컨트롤러에서 동작 표시하기 때문에 오류가 발생하기 때문에

Couldn't find Payment with 'id'=comeback 

이 문제를 해결하는 방법을 모른다면 제발 도와주세요.

+0

에 의해 쇼보기에서에서 전송 된? 나는 특히 오류를 던진 줄에 관심이있다. – tpei

+0

물론, 난 그냥 아래에 게시했습니다 –

+0

흠, 나는 당신의 경로가 제대로 설치되지 않았다고 가정합니다. 분명히'/ payments/: id'는 (당신이 Rails의 기본값처럼) show 액션으로 인도하는 경로입니다. 그런 다음'/ payments/comeback'을 호출하면 레일스는'comeback'을 id 매개 변수로 해석하고'comeback'을 ID로 사용하여 지불을 시도하고 실패합니다. – tpei

답변

0

이 내 지불 컨트롤러

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) %> 
관련 문제