przelewy24_payment 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. data/Gemfile +4 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +29 -0
  4. data/Rakefile +1 -0
  5. data/app/controllers/.przelewy24_payment_controller.rb.swo +0 -0
  6. data/app/controllers/.przelewy24_payment_controller.rb.swp +0 -0
  7. data/app/controllers/przelewy24_payment/.payment_controller.rb.swp +0 -0
  8. data/app/controllers/przelewy24_payment/payment_controller.rb +63 -0
  9. data/app/controllers/przelewy24_payment/payment_controller.rb~ +62 -0
  10. data/app/helpers/przelewy24_payment/.payment_helper.rb.swp +0 -0
  11. data/app/helpers/przelewy24_payment/payment_helper.rb +5 -0
  12. data/app/views/._p24_payment.html.haml.swp +0 -0
  13. data/app/views/._przelewy24_payment.html.haml.swp +0 -0
  14. data/app/views/przelewy24_payment/_payment_form.html.haml +45 -0
  15. data/lib/.przelewy24_payment.rb.swm +0 -0
  16. data/lib/.przelewy24_payment.rb.swn +0 -0
  17. data/lib/.przelewy24_payment.rb.swo +0 -0
  18. data/lib/.przelewy24_payment.rb.swp +0 -0
  19. data/lib/generators/przelewy24_payment/install/.install_generator.rb.swp +0 -0
  20. data/lib/generators/przelewy24_payment/install/USAGE +8 -0
  21. data/lib/generators/przelewy24_payment/install/install_generator.rb +8 -0
  22. data/lib/generators/przelewy24_payment/install/install_generator.rb~ +85 -0
  23. data/lib/generators/przelewy24_payment/install/templates/przelewy24_payment.rb +7 -0
  24. data/lib/przelewy24_payment.rb +65 -0
  25. data/lib/przelewy24_payment/.version.rb.swp +0 -0
  26. data/lib/przelewy24_payment/engine.rb +4 -0
  27. data/lib/przelewy24_payment/version.rb +3 -0
  28. data/przelewy24_payment.gemspec +19 -0
  29. metadata +73 -0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in przelewy24_payment.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Przelewy24Payment
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'przelewy24_payment'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install przelewy24_payment
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,63 @@
1
+ class Przelewy24Payment::PaymentController < ActionController::Base
2
+
3
+ def payment
4
+ @data = {
5
+ :session_id => 'sssss',
6
+ :description => "opis",
7
+ :value => '34.3',
8
+ :client => 'Adam Nowak',
9
+ :address => 'Powstancow 22/2',
10
+ :zipcode => '53-456',
11
+ :city => 'Wroclaw',
12
+ :country => 'Polska',
13
+ :email => 'test@example.com'
14
+ }
15
+ end
16
+
17
+ def payment_success(payment_params)
18
+ end
19
+
20
+
21
+ def payment_error(payment_params, code, description)
22
+ end
23
+
24
+ def payment_verify(response_params)
25
+ return data = { :amount => 100.0, :crc_key => '' }
26
+ end
27
+
28
+ def comeback
29
+ @response = przelewy24_verify(params)
30
+ result = @response.split("\r\n")
31
+ if result[1] == "TRUE"
32
+ payment_success(params)
33
+ else
34
+ payment_error(params, :error_code => result[2], :error_descr => result[3])
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def przelewy24_verify(params)
41
+ require 'net/https'
42
+ require 'net/http'
43
+ require 'open-uri'
44
+ require 'openssl'
45
+
46
+ data = payment_verify(params)
47
+
48
+ params_new = {:p24_session_id => params[:p24_session_id], :p24_order_id => params[:p24_order_id], :p24_id_sprzedawcy => Przelewy24Payment.seller_id, :p24_kwota => Przelewy24Payment.p24_price(data[:amount]).to_s}
49
+ if data[:crc_key].present?
50
+ params_new[:p24_crc] = Digest::MD5.hexdigest(params[:p24_session_id]+"|"+params[:p24_order_id]+"|"+params[:p24_kwota]+"|"+data[:crc_key])
51
+ end
52
+
53
+ url = URI.parse(Przelewy24Payment.transaction_url)
54
+ req = Net::HTTP::Post.new(url.path,{"User-Agent" => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10"})
55
+ req.form_data = params_new
56
+ con = Net::HTTP.new(url.host, 443)
57
+ con.use_ssl = true
58
+ con.verify_mode = OpenSSL::SSL::VERIFY_NONE
59
+ response = con.start {|http| http.request(req)}
60
+ return response.body
61
+ end
62
+
63
+ end
@@ -0,0 +1,62 @@
1
+ class Przelewy24PaymentController < ApplicationController
2
+ def payment
3
+ @data = {
4
+ :session_id => 'sssss',
5
+ :description => "opis",
6
+ :value => '34.3',
7
+ :client => 'Adam Nowak',
8
+ :address => 'Powstancow 22/2',
9
+ :zipcode => '53-456',
10
+ :city => 'Wroclaw',
11
+ :country => 'Polska',
12
+ :email => 'test@example.com'
13
+ }
14
+ end
15
+
16
+ def payment_success(payment_params)
17
+ end
18
+
19
+
20
+ def payment_error(payment_params, code, description)
21
+ end
22
+
23
+ def payment_verify(response_params)
24
+ return data = { :amount => 100.0, :crc_key => '' }
25
+ end
26
+
27
+ def comeback
28
+ @response = przelewy24_verify(params)
29
+ result = @response.split("\r\n")
30
+ if result[1] == "TRUE"
31
+ payment_success(params)
32
+ else
33
+ payment_error(params, :error_code => result[2], :error_descr => result[3])
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def przelewy24_verify(params)
40
+ require 'net/https'
41
+ require 'net/http'
42
+ require 'open-uri'
43
+ require 'openssl'
44
+
45
+ data = payment_verify(params)
46
+
47
+ params_new = {:p24_session_id => params[:p24_session_id], :p24_order_id => params[:p24_order_id], :p24_id_sprzedawcy => P24Payment::SELLER_ID, :p24_kwota => P24Payment.p24_price(data[:amount]).to_s}
48
+ if data[:crc_key].present?
49
+ params_new[:p24_crc] = Digest::MD5.hexdigest(params[:p24_session_id]+"|"+params[:p24_order_id]+"|"+params[:p24_kwota]+"|"+data[:crc_key])
50
+ end
51
+
52
+ url = URI.parse(P24Payment.transaction_url)
53
+ req = Net::HTTP::Post.new(url.path,{"User-Agent" => "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10"})
54
+ req.form_data = params_new
55
+ con = Net::HTTP.new(url.host, 443)
56
+ con.use_ssl = true
57
+ con.verify_mode = OpenSSL::SSL::VERIFY_NONE
58
+ response = con.start {|http| http.request(req)}
59
+ return response.body
60
+ end
61
+
62
+ end
@@ -0,0 +1,5 @@
1
+ module Przelewy24Payment::PaymentHelper
2
+ def payment_button(date)
3
+ render :partial => 'przelewy24_payment/payment_form', :locals => { :data => date }
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ = form_tag Przelewy24Payment.post_url, :method => "post" do
2
+ = hidden_field_tag 'p24_session_id', @data[:session_id]
3
+ = hidden_field_tag 'p24_id_sprzedawcy', @data.has_key?(:seller_id) ? @data[:seller_id] : Przelewy24Payment.seller_id
4
+ = hidden_field_tag 'p24_kwota', Przelewy24Payment.p24_price(@data[:value])
5
+ = hidden_field_tag 'p24_klient', @data[:client_name]
6
+ = hidden_field_tag 'p24_adres', @data[:address]
7
+ = hidden_field_tag 'p24_kod', @data[:zipcode]
8
+ = hidden_field_tag 'p24_miasto', @data[:city]
9
+ = hidden_field_tag 'p24_kraj', @data[:country]
10
+ = hidden_field_tag 'p24_email', @data[:email]
11
+ = hidden_field_tag 'p24_return_url_ok', @data.has_key?(:comeback_url) ? @data[:comeback_url] : Przelewy24Payment.comeback_url
12
+ = hidden_field_tag 'p24_return_url_error', @data.has_key?(:error_url) ? @data[:error_url] : Przelewy24Payment.error_url
13
+ = hidden_field_tag 'p24_opis', @data[:description]
14
+ = hidden_field_tag 'p24_language', @data.has_key?(:language) ? @data[:language] : Przelewy24Payment.language
15
+ = hidden_field_tag 'p24_crc', @data[:crc]
16
+ = button_tag( t("activerecord.models.p24_payment.buy"))
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate install Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,8 @@
1
+ class Przelewy24Payment::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def add_config
5
+ template "przelewy24_payment.rb", "config/initializers/przelewy24_payment.rb"
6
+ end
7
+
8
+ end
@@ -0,0 +1,85 @@
1
+ class CustomizeAdmin::InstallGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+
4
+ def add_gems
5
+ insert_into_file "Gemfile", :after => "source 'https://rubygems.org'\n" do
6
+ "# CustomizeAdmin gems:\n gem 'inherited_resources', '1.3.0'\n gem 'has_scope', '0.5.1'\n gem 'formtastic'\n gem 'will_paginate', '3.0.2'\n gem 'devise', '2.0.0'\n gem 'twitter-bootstrap-rails', '2.1.0' \n gem 'ckeditor', '3.7.1' \n gem 'globalize3' \n \n"
7
+ end
8
+ end
9
+
10
+ def add_routes
11
+ insert_into_file "config/routes.rb", :after => "draw do\n" do
12
+ @name_space = ask("Tell me the admin namespace?")
13
+ " mount CustomizeAdmin::Engine => '/admin', :as => 'customize_admin'\n namespace :#{@name_space} do\n #customize_admin:\n match '/' => 'dashboard#index' \n \n end\n"
14
+ end
15
+ end
16
+
17
+ def create_menu_file
18
+ create_file "app/views/customize_admin/application/_admin_menu.html.erb" do
19
+ "<%= link_to 'Dashboard', #{@name_space}_path, :class => 'brand' %>
20
+ <ul class='nav'>
21
+ <li></li>
22
+ </ul>
23
+ "
24
+ end
25
+ end
26
+
27
+ def run_bootstrap_generator
28
+ generate "bootstrap:install"
29
+ end
30
+
31
+ def install_formtastic
32
+ generate "formtastic:install"
33
+ end
34
+
35
+ def run_devise_generator
36
+ generate "devise:install"
37
+ end
38
+
39
+ def create_admin_user_table
40
+ #@devise_name = ask("Tell me devise admin user model (default is AdminUser)")
41
+ #@devise_name.blank? ? @devise_name = "AdminUser" : ""
42
+ generate "devise AdminUser"
43
+ end
44
+
45
+ def remove_registerable
46
+ model_file = File.join(destination_root, "app", "models", "admin_user.rb")
47
+ gsub_file model_file, /\:registerable([.]*,)?/, ""
48
+ end
49
+
50
+ def admin_user_add_to_migration
51
+ inject_into_file Dir["db/migrate/*_devise_create_admin_users.rb"].first,
52
+ "# Create a default user\n AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')\n\n ",
53
+ :before => "add_index :admin_users, :email"
54
+ end
55
+
56
+ def add_dashboard
57
+ s = ""
58
+ @name_space.to_s.split("_").each do |n|
59
+ s += n[0].capitalize + n.slice(1..-1)
60
+ end
61
+ @name_space_class = s
62
+ template "dashboard_controller.rb", "app/controllers/#{@name_space}/dashboard_controller.rb"
63
+ template "index.html.erb", "app/views/#{@name_space}/dashboard/index.html.erb"
64
+ end
65
+
66
+ def add_devise_layout
67
+ template "devise_admin.html.erb", "app/views/layouts/devise_admin.html.erb"
68
+ inject_into_file Dir["app/controllers/application_controller.rb"].first,
69
+ "\n layout :layout_by_resource
70
+ def layout_by_resource
71
+ if devise_controller? && resource_name == :admin_user
72
+ 'devise_admin'
73
+ else
74
+ 'application'
75
+ end
76
+ end ",
77
+ :after => "class ApplicationController < ActionController::Base"
78
+
79
+ end
80
+
81
+ def add_config
82
+ template "customize_admin.rb", "config/initializers/customize_admin.rb"
83
+ end
84
+
85
+ end
@@ -0,0 +1,7 @@
1
+ Przelewy24Payment.setup do |config|
2
+ config.seller_id = '17329'
3
+ config.language = 'pl'
4
+ config.mode = :development
5
+ config.error_url = 'http://localhost:3000/owner_advert/comeback'
6
+ config.comeback_url = 'http://localhost:3000/owner_advert/comeback'
7
+ end
@@ -0,0 +1,65 @@
1
+ require "przelewy24_payment/version"
2
+ require "przelewy24_payment/engine"
3
+
4
+ module Przelewy24Payment
5
+
6
+ module Controllers
7
+ autoload :Przelewy24Payment, 'controllers/przelewy24_payment'
8
+ end
9
+
10
+ mattr_accessor :seller_id
11
+ @@seller_id = '17329'
12
+
13
+ mattr_accessor :language
14
+ @@language = 'pl'
15
+
16
+ mattr_accessor :mode
17
+ @@mode = :development
18
+
19
+ mattr_accessor :error_url
20
+ @@error_url = ''
21
+
22
+ mattr_accessor :comeback_url
23
+ @@comeback_url = ''
24
+
25
+ mattr_accessor :crc_key
26
+ @@crc_key = ''
27
+
28
+ def self.setup
29
+ yield self
30
+ end
31
+
32
+ def self.complete_url(params)
33
+ params
34
+ end
35
+
36
+ def self.post_url
37
+ if @@mode == :development
38
+ 'https://sandbox.przelewy24.pl/index.php'
39
+ elsif @@mode == :production
40
+ 'https://secure.przelewy24.pl/index.php'
41
+ end
42
+ end
43
+
44
+ def self.transaction_url
45
+ if @@mode == :development
46
+ 'https://sandbox.przelewy24.pl/transakcja.php'
47
+ elsif @mode == :production
48
+ 'https://secure.przelewy24.pl/index.php'
49
+ end
50
+ end
51
+
52
+ def self.p24_price(price)
53
+ price.present? ? (price.to_f.round(2) * 100) : 0
54
+ end
55
+
56
+ def self.friendly_token
57
+ SecureRandom.base64(15).tr('+/=lIO0', 'aqrsxyz')
58
+ end
59
+
60
+ def self.calculate_crc(value,session_id, crc_key=nil)
61
+ calc_md5 = Digest::MD5.hexdigest(session_id.to_s + "|" + (seller_id).to_s + "|" + (p24_price(value)).to_s + "|" + (crc_key.nil? ? "" : crc_key.to_s))
62
+ return calc_md5
63
+ end
64
+
65
+ end
@@ -0,0 +1,4 @@
1
+ module Przelewy24Payment
2
+ class Engine < Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Przelewy24Payment
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'przelewy24_payment/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "przelewy24_payment"
8
+ gem.version = Przelewy24Payment::VERSION
9
+ gem.authors = ["Jakub Cieślar"]
10
+ gem.email = ["cieslar.jakub@gmail.com"]
11
+ gem.description = %q{Integration with polish payment method: Przelewy24}
12
+ gem.summary = %q{Integration with polish payment method: Przelewy24}
13
+ gem.homepage = "https://github.com/jcieslar/przelewy24_payment"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: przelewy24_payment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jakub Cieślar
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'Integration with polish payment method: Przelewy24'
15
+ email:
16
+ - cieslar.jakub@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - app/controllers/.przelewy24_payment_controller.rb.swo
26
+ - app/controllers/.przelewy24_payment_controller.rb.swp
27
+ - app/controllers/przelewy24_payment/.payment_controller.rb.swp
28
+ - app/controllers/przelewy24_payment/payment_controller.rb
29
+ - app/controllers/przelewy24_payment/payment_controller.rb~
30
+ - app/helpers/przelewy24_payment/.payment_helper.rb.swp
31
+ - app/helpers/przelewy24_payment/payment_helper.rb
32
+ - app/views/._p24_payment.html.haml.swp
33
+ - app/views/._przelewy24_payment.html.haml.swp
34
+ - app/views/przelewy24_payment/_payment_form.html.haml
35
+ - lib/.przelewy24_payment.rb.swm
36
+ - lib/.przelewy24_payment.rb.swn
37
+ - lib/.przelewy24_payment.rb.swo
38
+ - lib/.przelewy24_payment.rb.swp
39
+ - lib/generators/przelewy24_payment/install/.install_generator.rb.swp
40
+ - lib/generators/przelewy24_payment/install/USAGE
41
+ - lib/generators/przelewy24_payment/install/install_generator.rb
42
+ - lib/generators/przelewy24_payment/install/install_generator.rb~
43
+ - lib/generators/przelewy24_payment/install/templates/przelewy24_payment.rb
44
+ - lib/przelewy24_payment.rb
45
+ - lib/przelewy24_payment/.version.rb.swp
46
+ - lib/przelewy24_payment/engine.rb
47
+ - lib/przelewy24_payment/version.rb
48
+ - przelewy24_payment.gemspec
49
+ homepage: https://github.com/jcieslar/przelewy24_payment
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.24
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: ! 'Integration with polish payment method: Przelewy24'
73
+ test_files: []