przelewy24_payment 0.1.1 → 0.1.2
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/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
*.swp
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Przelewy24Payment
|
2
2
|
|
3
|
-
|
3
|
+
It's rails gem to integrate polish payment method: przelewy24.pl
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -10,15 +10,124 @@ Add this line to your application's Gemfile:
|
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
13
|
-
$ bundle
|
13
|
+
$ bundle install
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
17
|
$ gem install przelewy24_payment
|
18
18
|
|
19
|
+
After this create przelewy24_payment config:
|
20
|
+
|
21
|
+
$ rails g przelewy24_payment:install
|
22
|
+
|
23
|
+
And you can there "config/initializers/przelewy24_payment.rb" setup your settings:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Przelewy24Payment.setup do |config|
|
27
|
+
config.seller_id = 'your_seller_id'
|
28
|
+
config.language = 'pl'
|
29
|
+
config.mode = :development
|
30
|
+
config.error_url = 'http://localhost:3000/your_payment/comeback'
|
31
|
+
config.comeback_url = 'http://localhost:3000/your_payment/comeback'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
19
35
|
## Usage
|
20
36
|
|
21
|
-
|
37
|
+
Your controller e.g 'PaymentController' should only include:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class YourPaymentController < ApplicationController
|
41
|
+
include Przelewy24PaymentController
|
42
|
+
...
|
43
|
+
```
|
44
|
+
|
45
|
+
And you should also have this methods in your payment controller:
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
class YourPaymentController < ApplicationController
|
49
|
+
include Przelewy24PaymentController
|
50
|
+
...
|
51
|
+
|
52
|
+
# after success payemnt this method will be trigger
|
53
|
+
def payment_success(payment_params)
|
54
|
+
# payment_params returns hash with:
|
55
|
+
# p24_session_id
|
56
|
+
# p24_order_id
|
57
|
+
# p24_kwota
|
58
|
+
# p24_karta
|
59
|
+
# p24_order_id_full
|
60
|
+
# p24_crc
|
61
|
+
|
62
|
+
# e.g
|
63
|
+
# payment = Payment.find_by_session_id(payment_params[:p24_session_id])
|
64
|
+
end
|
65
|
+
|
66
|
+
# after error payemnt this method will be trigger
|
67
|
+
def payment_error(payment_params, code, description)
|
68
|
+
# payment_params returns hash with:
|
69
|
+
# p24_session_id
|
70
|
+
# p24_order_id
|
71
|
+
# p24_kwota
|
72
|
+
# p24_error_code
|
73
|
+
# p24_order_id_full
|
74
|
+
# p24_crc
|
75
|
+
#
|
76
|
+
# code return error code
|
77
|
+
# description return error description
|
78
|
+
end
|
79
|
+
|
80
|
+
def payment_verify(response_params)
|
81
|
+
# e.g:
|
82
|
+
# payment = Payment.find_by_session_id(response_params[:p24_session_id])
|
83
|
+
|
84
|
+
# you must return hash with amount which was save in your db and optional if you use your crc_key
|
85
|
+
return data = { :amount => payment.value }
|
86
|
+
|
87
|
+
#or
|
88
|
+
|
89
|
+
# optional variant:
|
90
|
+
return data = { :amount => your_payment_value, :crc_key => your_crc_key }
|
91
|
+
end
|
92
|
+
```
|
93
|
+
|
94
|
+
Last step, on your payment view e.g 'app/views/YourController/your_payment.html.haml' you should add:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
= payment_button(@data)
|
98
|
+
```
|
99
|
+
|
100
|
+
And also on your payment controller you should specify @data hash e.g:
|
101
|
+
|
102
|
+
```ruby
|
103
|
+
class YourPaymentController < ApplicationController
|
104
|
+
include Przelewy24PaymentController
|
105
|
+
...
|
106
|
+
|
107
|
+
def your_payment
|
108
|
+
session_id = Przelewy24Payment.friendly_token[0,20]
|
109
|
+
value = give_your_amount
|
110
|
+
@data = { :session_id => session_id,
|
111
|
+
:description => "opis",
|
112
|
+
:value => value,
|
113
|
+
:client => 'Adam Nowak',
|
114
|
+
:address => 'Powstancow 22/2',
|
115
|
+
:zipcode => '53-456',
|
116
|
+
:city => 'Wroclaw',
|
117
|
+
:country => 'Polska',
|
118
|
+
:email => 'payment@example.com',
|
119
|
+
# adding this params, you overwrite your config settings so this param is optional
|
120
|
+
# :language => 'pl',
|
121
|
+
# :crc => your_crc_key,
|
122
|
+
# :seller_id => seller_id
|
123
|
+
}
|
124
|
+
end
|
125
|
+
|
126
|
+
...
|
127
|
+
|
128
|
+
```
|
129
|
+
|
130
|
+
Finish :)
|
22
131
|
|
23
132
|
## Contributing
|
24
133
|
|
data/lib/przelewy24_payment.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
require "przelewy24_payment/version"
|
2
2
|
require "przelewy24_payment/engine"
|
3
|
+
require "przelewy24_payment/przelewy24_payment_controller"
|
3
4
|
|
4
5
|
module Przelewy24Payment
|
5
6
|
|
6
|
-
module Controllers
|
7
|
-
autoload :Przelewy24Payment, 'controllers/przelewy24_payment'
|
8
|
-
end
|
9
|
-
|
10
7
|
mattr_accessor :seller_id
|
11
8
|
@@seller_id = '17329'
|
12
9
|
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Przelewy24PaymentController
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
include InstanceMethods
|
6
|
+
extend ClassMethods
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
|
12
|
+
end # ClassMethods
|
13
|
+
|
14
|
+
module InstanceMethods
|
15
|
+
def payment_success(payment_params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def payment_error(payment_params, code, description)
|
19
|
+
end
|
20
|
+
|
21
|
+
def payment_verify(response_params)
|
22
|
+
return data = { :amount => 100.0, :crc_key => '' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def comeback
|
26
|
+
@response = przelewy24_verify(params)
|
27
|
+
result = @response.split("\r\n")
|
28
|
+
if result[1] == "TRUE"
|
29
|
+
payment_success(params)
|
30
|
+
else
|
31
|
+
payment_error(params, :error_code => result[2], :error_descr => result[3])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def przelewy24_verify(params)
|
38
|
+
require 'net/https'
|
39
|
+
require 'net/http'
|
40
|
+
require 'open-uri'
|
41
|
+
require 'openssl'
|
42
|
+
|
43
|
+
data = payment_verify(params)
|
44
|
+
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}
|
45
|
+
if data[:crc_key].present?
|
46
|
+
params_new[:p24_crc] = Digest::MD5.hexdigest(params[:p24_session_id]+"|"+params[:p24_order_id]+"|"+params[:p24_kwota]+"|"+data[:crc_key])
|
47
|
+
end
|
48
|
+
|
49
|
+
url = URI.parse(Przelewy24Payment.transaction_url)
|
50
|
+
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"})
|
51
|
+
req.form_data = params_new
|
52
|
+
con = Net::HTTP.new(url.host, 443)
|
53
|
+
con.use_ssl = true
|
54
|
+
con.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
55
|
+
response = con.start {|http| http.request(req)}
|
56
|
+
return response.body
|
57
|
+
end
|
58
|
+
|
59
|
+
end # InstanceMethods
|
60
|
+
|
61
|
+
|
62
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: przelewy24_payment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
12
|
+
date: 2012-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Integration with polish payment method: Przelewy24'
|
15
15
|
email:
|
@@ -18,11 +18,11 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
+
- .gitignore
|
21
22
|
- Gemfile
|
22
23
|
- LICENSE.txt
|
23
24
|
- README.md
|
24
25
|
- Rakefile
|
25
|
-
- app/controllers/przelewy24_payment/payment_controller.rb
|
26
26
|
- app/helpers/przelewy24_payment/payment_helper.rb
|
27
27
|
- app/views/przelewy24_payment/_payment_form.html.haml
|
28
28
|
- lib/generators/przelewy24_payment/install/USAGE
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/generators/przelewy24_payment/install/templates/przelewy24_payment.rb
|
31
31
|
- lib/przelewy24_payment.rb
|
32
32
|
- lib/przelewy24_payment/engine.rb
|
33
|
+
- lib/przelewy24_payment/przelewy24_payment_controller.rb
|
33
34
|
- lib/przelewy24_payment/version.rb
|
34
35
|
- przelewy24_payment.gemspec
|
35
36
|
homepage: https://github.com/jcieslar/przelewy24_payment
|
@@ -1,63 +0,0 @@
|
|
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
|