spree_przelewy24 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.
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ SpreePrzelewy24
2
+ ====================
3
+
4
+ Przelewy24 payment system for Spree (>= 1.0)
5
+
6
+ Install
7
+ =======
8
+
9
+ Add to your Gemfile:
10
+
11
+ gem 'spree_przelewy24', :git => 'git://github.com/matfiz/spree_przelewy24.git'
12
+
13
+ and run
14
+
15
+ bundle install
16
+
17
+ Przelewy24.pl Settings
18
+ ========
19
+
20
+ You'll have to set the following parameters:
21
+ * seller ID
22
+ * CRC key
23
+ * optionally: language and przelewy24 URLs
24
+
25
+ In Spree Admin zone you have to create new payment method and select *Spree::PaymentMethod::Przelewy24* as a provider.
26
+ I recommend to test it first - just select *test mode* in payment method settings and it will use sandbox platform instead of the production one.
27
+
28
+ This work is loosely based on https://github.com/pronix/spree-ebsin and https://github.com/espresse/spree_dotpay_pl_payment.git.
29
+
30
+ ------------------------------------------------------------------------------
31
+ License
32
+ ------------------------------------------------------------------------------
33
+
34
+ Copyright (c) 2011 - 2012 Grzegorz Brzezinka (@matfiz), released under the New BSD License All rights reserved.
@@ -0,0 +1,17 @@
1
+ module Spree
2
+ CheckoutController.class_eval do
3
+
4
+ before_filter :redirect_for_przelewy24, :only => :update
5
+
6
+ private
7
+
8
+ def redirect_for_przelewy24
9
+ return unless params[:state] == "payment"
10
+ @payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
11
+ if @payment_method && @payment_method.kind_of?(PaymentMethod::Przelewy24)
12
+ redirect_to gateway_przelewy24_path(:gateway_id => @payment_method.id, :order_id => @order.id)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,121 @@
1
+ require 'digest/md5'
2
+ module Spree
3
+ class Gateway::Przelewy24Controller < Spree::BaseController
4
+ skip_before_filter :verify_authenticity_token, :only => [:comeback, :complete]
5
+
6
+ # Show form Przelewy24 for pay
7
+ def show
8
+ @order = Order.find(params[:order_id])
9
+ if params[:gateway_id]
10
+ @gateway = @order.available_payment_methods.find{|x| x.id == params[:gateway_id].to_i }
11
+ @order.payments.destroy_all
12
+ payment = @order.payments.create!(:amount => 0, :payment_method_id => @gateway.id)
13
+
14
+ @p24_session_id = Time.now.to_f.to_s
15
+ @p24_crc = przelewy24_transaction_crc(@gateway,@order,@p24_session_id)
16
+
17
+ if @order.blank? || @gateway.blank?
18
+ flash[:error] = I18n.t("invalid_arguments")
19
+ redirect_to :back
20
+ else
21
+ @bill_address, @ship_address = @order.bill_address, (@order.ship_address || @order.bill_address)
22
+ end
23
+ end
24
+ end
25
+
26
+ def error
27
+
28
+ end
29
+
30
+
31
+ # Result from Przelewy24
32
+ def comeback
33
+ @order = Order.find(params[:order_id])
34
+ @gateway = @order && @order.payments.first.payment_method
35
+ @response = przelewy24_verify(@gateway,@order,params)
36
+ @amount = 100.0
37
+ @amount = params[:p24_kwota].to_f/100
38
+ result = @response.split("\r\n")
39
+ if result[1] == "TRUE"
40
+ przelewy24_payment_success(@amount)
41
+ redirect_to gateway_przelewy24_complete_path(:order_id => @order.id, :gateway_id => @gateway.id)
42
+ else
43
+ redirect_to gateway_przelewy24_error_path(:gateway_id => @gateway.id, :order_id => @order.id, :error_code => result[2], :error_descr => result[3])
44
+ end
45
+ end
46
+
47
+ # complete the order
48
+ def complete
49
+ @order = Order.find(params[:order_id])
50
+
51
+ session[:order_id]=nil
52
+ if @order.state=="complete"
53
+ redirect_to order_url(@order, {:checkout_complete => true, :order_token => @order.token}), :notice => I18n.t("payment_success")
54
+ else
55
+ redirect_to order_url(@order)
56
+ end
57
+ end
58
+
59
+
60
+
61
+ private
62
+
63
+ # validating dotpay message
64
+ def przelewy24_transaction_crc(gateway,order,session_id)
65
+ calc_md5 = Digest::MD5.hexdigest(session_id + "|" +
66
+ (@gateway.preferred_p24_id_sprzedawcy.nil? ? "" : @gateway.preferred_p24_id_sprzedawcy) + "|" +
67
+ (@gateway.p24_amount(@order.total).nil? ? "" : @gateway.p24_amount(@order.total)) + "|" +
68
+ (@gateway.preferred_crc_key.nil? ? "" : @gateway.preferred_crc_key))
69
+
70
+ return calc_md5
71
+
72
+ end
73
+
74
+ def przelewy24_verify(gateway,order,params)
75
+ require 'net/https'
76
+ require 'net/http'
77
+ require 'open-uri'
78
+ require 'openssl'
79
+
80
+ params_new = {:p24_session_id => params[:p24_session_id], :p24_order_id => params[:p24_order_id], :p24_id_sprzedawcy => gateway.preferred_p24_id_sprzedawcy, :p24_kwota => params[:p24_kwota]}
81
+ params_new[:p24_crc] = Digest::MD5.hexdigest(params[:p24_session_id]+"|"+params[:p24_order_id]+"|"+params[:p24_kwota]+"|"+gateway.preferred_crc_key)
82
+ #params_list = "p24_session_id=#{params_new[:p24_session_id]}&p24_order_id=#{params_new[:p24_session_id]}&p24_id_sprzedawcy=#{params_new[:p24_id_sprzedawcy]}&p24_kwota=#{params_new[:p24_kwota]}&p24_crc=#{params_new[:p24_crc]}"
83
+ url = URI.parse(gateway.transakcja_url)
84
+ 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"})
85
+ req.form_data = params_new
86
+ #req.basic_auth url.user, url.password if url.user
87
+ con = Net::HTTP.new(url.host, 443)
88
+ con.use_ssl = true
89
+ con.verify_mode = OpenSSL::SSL::VERIFY_NONE
90
+ response = con.start {|http| http.request(req)}
91
+ return response.body
92
+ end
93
+
94
+ # Completed payment process
95
+ def przelewy24_payment_success(amount)
96
+ @order.payment.started_processing
97
+ if @order.total.to_f == amount.to_f
98
+ @order.payment.complete
99
+ end
100
+
101
+ @order.finalize!
102
+
103
+ @order.next
104
+ @order.next
105
+ @order.save
106
+ end
107
+
108
+ # payment cancelled by user (dotpay signals 3 to 5)
109
+ def przelewy24_payment_cancel(params)
110
+ @order.cancel
111
+ end
112
+
113
+ def przelewy24_payment_new(params)
114
+ @order.payment.started_processing
115
+ @order.finalize!
116
+ end
117
+
118
+ end
119
+ end
120
+
121
+
@@ -0,0 +1,42 @@
1
+ module Spree
2
+ class PaymentMethod::Przelewy24 < PaymentMethod
3
+
4
+
5
+ attr_accessible :preferred_test_mode, :preferred_url, :preferred_url_transakcja, :preferred_test_url, :preferred_crc_key, :preferred_p24_language, :preferred_test_url_transakcja, :preferred_p24_return_url_error, :preferred_p24_return_url_ok, :preferred_p24_id_sprzedawcy
6
+
7
+ preference :p24_id_sprzedawcy, :string
8
+ preference :url, :string, :default => "https://secure.przelewy24.pl/index.php"
9
+ preference :url_transakcja, :string, :default => "https://secure.przelewy24.pl/transakcja.php"
10
+ preference :test_url, :string, :default => "https://sandbox.przelewy24.pl/index.php"
11
+ preference :test_url_transakcja, :string, :default => "https://sandbox.przelewy24.pl/transakcja.php"
12
+ preference :p24_language, :string, :default => "pl"
13
+ preference :crc_key, :string
14
+ preference :test_mode, :boolean, :default => false
15
+
16
+ def payment_profiles_supported?
17
+ false
18
+ end
19
+
20
+ def p24_amount(amount)
21
+ (amount*100.00).to_i.to_s #total amount * 100
22
+ end
23
+
24
+ def post_url
25
+ if preferred_test_mode
26
+ preferred_test_url
27
+ else
28
+ preferred_url
29
+ end
30
+ end
31
+
32
+ def transakcja_url
33
+ if preferred_test_mode
34
+ preferred_test_url_transakcja
35
+ else
36
+ preferred_url_transakcja
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+
@@ -0,0 +1,2 @@
1
+ = image_tag "store/logo_przelewy24.png", :alt => "Przelewy24"
2
+ %p= t('przelewy24.info')
@@ -0,0 +1,10 @@
1
+ %h1 t('przelewy24.error.headline')
2
+ %p t('przelewy24.error.content')
3
+ - if params[:error_code]
4
+ %p
5
+ Error code:
6
+ = params[:error_code]
7
+ - if params[:error_descr]
8
+ %p
9
+ Error description:
10
+ = params[:error_descr]
@@ -0,0 +1,62 @@
1
+ - content_for :head do
2
+ = javascript_include_tag states_url
3
+ %div{:id => "checkout"}(data-hook)
4
+ = render :partial => 'spree/shared/error_messages', :locals => { :target => @order }
5
+ %div{:class => "row", :"data-hook" => "checkout_header"}
6
+ %h1{:class => "columns three alpha", :"data-hook" => "checkout_title"}
7
+ = t(:checkout)
8
+ %div{:class => "columns thirteen omega", :"data-hook" => "checkout_progress"}
9
+ =# Spree::CheckoutHelper::checkout_progress
10
+ %ol.progress-steps#checkout-step-payment
11
+ %li.completed-first
12
+ %span
13
+ %a{:href => "/checkout/address"}
14
+ Adres
15
+ %li.completed
16
+ %span
17
+ %a{:href => "/checkout/delivery"}
18
+ Dostawa
19
+ %li.current
20
+ %span
21
+ Płatność
22
+ %li.next-last
23
+ %span
24
+ Kompletne
25
+
26
+ %div{:class => "row", :"data-hook" => "checkout_content"}
27
+ %div{:class => "columns alpha twelve", :"data-hook" => "checkout_form_wrapper"}
28
+ =# form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form|
29
+ = form_tag @gateway.post_url, :method => "post" do
30
+ %fieldset{:id => "payment"}(data-hook)
31
+ %legend= t(:payment_information)
32
+ %p= t('przelewy24.choose_channel')
33
+ = javascript_include_tag "https://secure.przelewy24.pl/external/formy.php?id=#{@gateway.preferred_p24_id_sprzedawcy}&sort=2&encoding=utf-8&cols=3&width=600"
34
+ :javascript
35
+ m_formy();
36
+ //list of obligatory fields to pass to przelewy24.pl
37
+ = hidden_field_tag 'p24_session_id', @p24_session_id
38
+ = hidden_field_tag 'p24_id_sprzedawcy', @gateway.preferred_p24_id_sprzedawcy
39
+ = hidden_field_tag 'p24_kwota', @gateway.p24_amount(@order.total)
40
+ = hidden_field_tag 'p24_klient', "#{@bill_address.firstname} #{@bill_address.lastname}"
41
+ = hidden_field_tag 'p24_adres', "#{@bill_address.address1} #{@bill_address.address2}"
42
+ = hidden_field_tag 'p24_kod', @bill_address.zipcode
43
+ = hidden_field_tag 'p24_miasto', @bill_address.city
44
+ = hidden_field_tag 'p24_kraj', @bill_address.country.iso3
45
+ = hidden_field_tag 'p24_email', (@order.email || @order.user.try(:email))
46
+ = hidden_field_tag 'p24_return_url_ok', gateway_przelewy24_comeback_url(:gateway_id => @gateway.id,:order_id => @order.id)
47
+ = hidden_field_tag 'p24_return_url_error', gateway_przelewy24_error_url(:gateway_id => @gateway.id,:order_id => @order.id)
48
+ = hidden_field_tag 'p24_opis', "#{Spree::Config[:site_name]} Order: #{@order.number}"
49
+ = hidden_field_tag 'p24_language', @gateway.preferred_p24_language
50
+ = hidden_field_tag 'p24_crc', @p24_crc
51
+
52
+ %div{:class => "form-buttons", :"data-hook" => "buttons"}
53
+ = submit_tag t(:przelewy24_payment), :class => 'continue button primary'
54
+ :javascript
55
+ disableSaveOnClick();
56
+
57
+ %br.space
58
+
59
+ %div{:id => "checkout-summary", :"data-hook" => "checkout_summary_box", :class => "columns omega four"}
60
+ = render :partial => 'spree/checkout/summary', :locals => { :order => @order }
61
+
62
+
@@ -0,0 +1,3 @@
1
+ require 'spree_core'
2
+ require 'spree_przelewy24/engine'
3
+
@@ -0,0 +1,22 @@
1
+ module SpreePrzelewy24
2
+ class Engine < Rails::Engine
3
+
4
+ engine_name 'spree_przelewy24'
5
+
6
+ config.autoload_paths += %W(#{config.root}/lib)
7
+
8
+ initializer "spree.gateway.payment_methods", :after => "spree.register.payment_methods" do |app|
9
+ app.config.spree.payment_methods << Spree::PaymentMethod::Przelewy24
10
+ end
11
+
12
+ config.to_prepare do
13
+ #loads application's model / class decorators
14
+ Dir.glob(File.join(File.dirname(__FILE__), "../../app/**/*_decorator*.rb")) do |c|
15
+ Rails.application.config.cache_classes ? require(c) : load(c)
16
+ end
17
+
18
+ end
19
+
20
+ #config.to_prepare &method(:activate).to_proc
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ namespace :spree_dotpay_pl_payment do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_dotpay_pl_payment:install:migrations'].invoke
5
+ Rake::Task['spree_dotpay_pl_payment:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
10
+ task :migrations do
11
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
12
+ destination = File.join(Rails.root, 'db')
13
+ Spree::FileUtilz.mirror_files(source, destination)
14
+ end
15
+
16
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
17
+ task :assets do
18
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
19
+ destination = File.join(Rails.root, 'public')
20
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
21
+ Spree::FileUtilz.mirror_files(source, destination)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_przelewy24
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Grzegorz Brzezinka
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-06-10 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: spree_core
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 15
28
+ segments:
29
+ - 1
30
+ - 0
31
+ version: "1.0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: haml
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description:
49
+ email: info@matfiz.com.pl
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files: []
55
+
56
+ files:
57
+ - README.md
58
+ - LICENSE
59
+ - lib/spree_przelewy24/engine.rb
60
+ - lib/tasks/install.rake
61
+ - lib/tasks/spree_dotpay_pl_payment.rake
62
+ - lib/spree_przelewy24.rb
63
+ - app/models/spree/payment_method/przelewy24.rb
64
+ - app/controllers/spree/checkout_controller_decorator.rb
65
+ - app/controllers/spree/gateway/przelewy24_controller.rb
66
+ - app/views/spree/gateway/przelewy24/show.html.haml
67
+ - app/views/spree/gateway/przelewy24/error.html.haml
68
+ - app/views/spree/checkout/payment/_przelewy24.html.haml
69
+ - app/assets/images/store/logo_przelewy24.png
70
+ homepage: https://github.com/matfiz/spree_przelewy24
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options: []
75
+
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ hash: 57
84
+ segments:
85
+ - 1
86
+ - 8
87
+ - 7
88
+ version: 1.8.7
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements:
99
+ - none
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.10
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Przelewy24 payment system for Spree
105
+ test_files: []
106
+