Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Integration with polish payment method: Przelewy24.pl

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 lib
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 przelewy24_payment.gemspec
README.md

Przelewy24Payment

It's rails gem to integrate polish payment method: przelewy24.pl

Installation

Add this line to your application's Gemfile:

gem 'przelewy24_payment'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install przelewy24_payment

After this create przelewy24_payment config:

$ rails g przelewy24_payment:install

And you can there "config/initializers/przelewy24_payment.rb" setup your settings:

Przelewy24Payment.setup do |config|
  config.seller_id = 'your_seller_id'
  config.language = 'pl'
  config.mode = Rails.env.to_sym  # or just put :development or :production symbol
  config.error_url = '/your_controller/comeback'
  config.comeback_url = '/your_controller/comeback'
  config.hostname = {
      :development => "http://localhost:3000",
      :production => "your.domain",
      :staging => "staging.domain"
  }
end

Usage

Your controller e.g 'PaymentController' should only include:

class YourPaymentController < ApplicationController
  include Przelewy24PaymentController
  ...

And you should also have this methods in your payment controller:

class YourPaymentController < ApplicationController
  include Przelewy24PaymentController
  ...

  # after success payemnt this method will be trigger
  # so you can do whatever you want
  def payment_success(payment_params)
    # payment_params returns hash with:
    # p24_session_id
    # p24_order_id
    # p24_kwota
    # p24_karta
    # p24_order_id_full
    # p24_crc

    # 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_session_id
    # p24_order_id
    # p24_kwota
    # p24_error_code
    # p24_order_id_full
    # p24_crc
    #
    # 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:
    # payment = Payment.find_by_session_id(response_params[:p24_session_id])

    # you must return hash with amount which was save in your db and optional if you use your crc_key
    return data = { :amount => payment.value }

    #or

    # optional variant:
    return data = { :amount => your_payment_value, :crc_key => your_crc_key }
  end

Last step, on your payment view e.g 'app/views/YourController/your_payment.html.haml' you should add:

= payment_button(@data)

And also on your payment controller you should specify @data hash e.g:

class YourPaymentController < ApplicationController
  include Przelewy24PaymentController
  ...

  def your_payment
    session_id = Przelewy24Payment.friendly_token[0,20]
    value = give_your_amount
    @data = { :session_id =>  session_id,
              :description => "opis",           # optional param
              :value => value,
              :client => 'Adam Nowak',          # optional param
              :address => 'Powstancow 22/2',    # optional param
              :zipcode => '53-456',             # optional param
              :city => 'Wroclaw',               # optional param
              :country => 'Polska',             # optional param
              :email => 'payment@example.com',
              # adding this params, you overwrite your config settings so this param is optional
              # :language => 'pl',
              # :crc => your_crc_key,
              # :seller_id => seller_id
            }
  end

  ...

Finish :)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Something went wrong with that request. Please try again.