payr 1.0 → 1.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/README.md +17 -3
- data/app/controllers/payr/bills_controller.rb +34 -33
- data/app/models/payr/bill.rb +1 -1
- data/lib/generators/templates/migration.rb +1 -0
- data/lib/payr/rails/routes.rb +11 -4
- data/lib/payr/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
|
@@ -82,11 +82,12 @@ You can use the routes by default by adding this to your config/routes.rb
|
|
|
82
82
|
payr_routes
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
This will generate
|
|
85
|
+
This will generate 5 routes :
|
|
86
86
|
|
|
87
87
|
```sh
|
|
88
88
|
$ > rake routes
|
|
89
89
|
payr_bills_pay GET /bills/pay(.:format) payr/bills#pay
|
|
90
|
+
payr_bills_pay POST /bills/pay(.:format) payr/bills#pay
|
|
90
91
|
payr_bills_paid GET /bills/paid(.:format) payr/bills#paid
|
|
91
92
|
payr_bills_refused GET /bills/refused(.:format) payr/bills#refused
|
|
92
93
|
payr_bills_cancelled GET /bills/cancelled(.:format) payr/bills#cancelled
|
|
@@ -102,11 +103,12 @@ We recommand to override the controllers thoug. For that, define a custom contro
|
|
|
102
103
|
|
|
103
104
|
If you created a app/controllers/paiement/callbacks controller.
|
|
104
105
|
|
|
105
|
-
This will generate
|
|
106
|
+
This will generate 5 routes :
|
|
106
107
|
|
|
107
108
|
```sh
|
|
108
109
|
$ > rake routes
|
|
109
110
|
payr_bills_pay GET /paiement/callbacks/pay(.:format) paiement/callbacks#pay
|
|
111
|
+
payr_bills_pay POST /paiement/callbacks/pay(.:format) paiement/callbacks#pay
|
|
110
112
|
payr_bills_paid GET /paiement/callbacks/paid(.:format) paiement/callbacks#paid
|
|
111
113
|
payr_bills_refused GET /paiement/callbacks/refused(.:format) paiement/callbacks#refused
|
|
112
114
|
payr_bills_cancelled GET /paiement/callbacks/cancelled(.:format) paiement/callbacks#cancelled
|
|
@@ -166,7 +168,14 @@ payr_bills_pay_path(article_id: pack.id,
|
|
|
166
168
|
id: current_recruiter.id },
|
|
167
169
|
total_price: pack.price.to_i*100 )
|
|
168
170
|
```
|
|
169
|
-
|
|
171
|
+
You can also use the bill_reference parameter if you want to have a custom bill_parameter :
|
|
172
|
+
```ruby
|
|
173
|
+
payr_bills_pay_path(article_id: pack.id,
|
|
174
|
+
buyer: { email: current_recruiter.email,
|
|
175
|
+
id: current_recruiter.id },
|
|
176
|
+
total_price: pack.price.to_i*100,
|
|
177
|
+
bill_reference: "F00000001" )
|
|
178
|
+
```
|
|
170
179
|
This will call the bills#action and then redirect the user to the paybox paiement page.
|
|
171
180
|
|
|
172
181
|
You can also override the views by creating the appropriate files :
|
|
@@ -235,4 +244,9 @@ rake
|
|
|
235
244
|
|
|
236
245
|
i'll gladly add your work =)
|
|
237
246
|
|
|
247
|
+
### TODO
|
|
248
|
+
|
|
249
|
+
- add helper "after_payment_path", "after_cancelled_path" etc that can be overrided to avoid to override BillsControllers
|
|
250
|
+
- improve documentation about what BillController does
|
|
251
|
+
|
|
238
252
|
This project rocks and uses MIT-LICENSE.
|
|
@@ -1,52 +1,53 @@
|
|
|
1
1
|
class Payr::BillsController < ApplicationController
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
before_filter :check_response, except: [:pay, :failure, :ipn]
|
|
3
|
+
before_filter :check_ipn_response, only: [:ipn]
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
UNPROCESSED = "unprocessed"
|
|
6
6
|
PAID = "paid"
|
|
7
7
|
REFUSED = "refused"
|
|
8
8
|
CANCELLED = "cancelled"
|
|
9
9
|
SIGN_ERROR = "bad_signature"
|
|
10
10
|
NO_ERROR = "00000"
|
|
11
11
|
def pay
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
@bill = Payr::Bill.new(buyer_id: params[:buyer][:id],
|
|
13
|
+
amount: params[:total_price],
|
|
14
|
+
article_id: params[:article_id],
|
|
15
|
+
state: UNPROCESSED,
|
|
16
|
+
bill_reference: params[:bill_reference])
|
|
16
17
|
@payr = Payr::Client.new
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
if @bill.save
|
|
19
|
+
@paybox_params = @payr.get_paybox_params_from command_id: @bill.id,
|
|
20
|
+
buyer_email: params[:buyer][:email],
|
|
21
|
+
total_price: params[:total_price],
|
|
22
|
+
callbacks: {
|
|
23
|
+
paid: payr_bills_paid_url,
|
|
24
|
+
refused: payr_bills_refused_url,
|
|
25
|
+
cancelled: payr_bills_cancelled_url,
|
|
26
|
+
ipn: payr_bills_ipn_url
|
|
27
|
+
}
|
|
28
|
+
end
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
def paid
|
|
32
|
+
change_status params[:ref], PAID
|
|
33
|
+
end
|
|
33
34
|
|
|
34
35
|
def refused
|
|
35
|
-
|
|
36
|
+
change_status params[:ref], REFUSED, params[:error]
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def cancelled
|
|
39
|
-
|
|
40
|
+
change_status params[:ref], CANCELLED, params[:error]
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
def ipn
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
if params[:error] == NO_ERROR
|
|
45
|
+
change_status params[:ref], PAID
|
|
46
|
+
else
|
|
47
|
+
@bill = Payr::Bill.find(params[:ref])
|
|
48
|
+
@bill.update_attribute(:error_code, params[:error])
|
|
49
|
+
end
|
|
50
|
+
render nothing: true, :status => 200, :content_type => 'text/html'
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
def failure
|
|
@@ -55,9 +56,9 @@ class Payr::BillsController < ApplicationController
|
|
|
55
56
|
|
|
56
57
|
protected
|
|
57
58
|
def change_status id, status, error=nil
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
@bill = Payr::Bill.find(id)
|
|
60
|
+
@bill.update_attribute(:state, status)
|
|
61
|
+
@bill.update_attribute(:error_code, error) unless error.nil?
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
end
|
data/app/models/payr/bill.rb
CHANGED
data/lib/payr/rails/routes.rb
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
module ActionDispatch::Routing
|
|
2
2
|
class Mapper
|
|
3
|
-
def payr_routes(options={})
|
|
4
|
-
["pay", "paid", "refused", "cancelled", "ipn", "failure"].each do |action|
|
|
3
|
+
def payr_routes(options={})
|
|
5
4
|
if options && options[:callback_controller]
|
|
6
|
-
get
|
|
5
|
+
get "#{options[:callback_controller]}/pay", as: "payr_bills_pay"
|
|
6
|
+
post "#{options[:callback_controller]}/pay", as: "payr_bills_pay"
|
|
7
7
|
else
|
|
8
|
-
get
|
|
8
|
+
get "payr/bills/pay", as: "payr_bills_pay"
|
|
9
|
+
post "payr/bills/pay", as: "payr_bills_pay"
|
|
10
|
+
end
|
|
11
|
+
["paid", "refused", "cancelled", "ipn", "failure"].each do |action|
|
|
12
|
+
if options && options[:callback_controller]
|
|
13
|
+
get "#{options[:callback_controller]}/#{action}", as: "payr_bills_#{action}"
|
|
14
|
+
else
|
|
15
|
+
get "payr/bills/#{action}", as: "payr_bills_#{action}"
|
|
9
16
|
end
|
|
10
17
|
end
|
|
11
18
|
end
|
data/lib/payr/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: payr
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.1
|
|
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-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
138
138
|
version: '0'
|
|
139
139
|
segments:
|
|
140
140
|
- 0
|
|
141
|
-
hash:
|
|
141
|
+
hash: 2281109692306427172
|
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
none: false
|
|
144
144
|
requirements:
|
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
147
147
|
version: '0'
|
|
148
148
|
segments:
|
|
149
149
|
- 0
|
|
150
|
-
hash:
|
|
150
|
+
hash: 2281109692306427172
|
|
151
151
|
requirements: []
|
|
152
152
|
rubyforge_project:
|
|
153
153
|
rubygems_version: 1.8.24
|