Z tego co wiem API się nie zmieniło, nadal jest w wersji 3.2.
Tak wygląda mój kontroler płatności
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
A tak plik z konfiguracją
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'
Może problem tkwi w tym, że url_status oraz return nie prowadzą bezprośrednio do payments/comeback
, z uwagi na to, że ten ta ścieżka odpowiada za akcje show więc ruby szukało po prostu płatności z ID comeback.
Reasumując użytkownik w widoku show widzi wszystkie parametry płatności, klika payment_button i zostaje przenoszony poprawnie na strone przelewow 24 gdzie wszystkie dane typu id sprzedawcy, kwota, tytul są poprawne, jednakże po płatności w momencie gdy powinny zostać odebrane dane służące do weryfikacji nie otrzymuję niczego, przez co transakcja nie może dojść do skutku i w panelu sandboxa posiada status “do wykorzystania”
Prawdopodobnie pomieszałem coś z implementacją, jednak kompletnie nie wiem jak sobie z tym poradzić