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 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 4 routes :
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 4 routes :
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
- before_filter :check_response, except: [:pay, :failure, :ipn]
3
- before_filter :check_ipn_response, only: [:ipn]
2
+ before_filter :check_response, except: [:pay, :failure, :ipn]
3
+ before_filter :check_ipn_response, only: [:ipn]
4
4
 
5
- UNPROCESSED = "unprocessed"
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
- @bill = Payr::Bill.new(buyer_id: params[:buyer][:id],
13
- amount: params[:total_price],
14
- article_id: params[:article_id],
15
- state: UNPROCESSED)
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
- if @bill.save
18
- @paybox_params = @payr.get_paybox_params_from command_id: @bill.id,
19
- buyer_email: params[:buyer][:email],
20
- total_price: params[:total_price],
21
- callbacks: {
22
- paid: payr_bills_paid_url,
23
- refused: payr_bills_refused_url,
24
- cancelled: payr_bills_cancelled_url,
25
- ipn: payr_bills_ipn_url
26
- }
27
- end
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
- def paid
31
- change_status params[:ref], PAID
32
- end
31
+ def paid
32
+ change_status params[:ref], PAID
33
+ end
33
34
 
34
35
  def refused
35
- change_status params[:ref], REFUSED, params[:error]
36
+ change_status params[:ref], REFUSED, params[:error]
36
37
  end
37
38
 
38
39
  def cancelled
39
- change_status params[:ref], CANCELLED, params[:error]
40
+ change_status params[:ref], CANCELLED, params[:error]
40
41
  end
41
42
 
42
43
  def ipn
43
- if params[:error] == NO_ERROR
44
- change_status params[:ref], PAID
45
- else
46
- @bill = Payr::Bill.find(params[:ref])
47
- @bill.update_attribute(:error_code, params[:error])
48
- end
49
- render nothing: true, :status => 200, :content_type => 'text/html'
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
- @bill = Payr::Bill.find(id)
59
- @bill.update_attribute(:state, status)
60
- @bill.update_attribute(:error_code, error) unless error.nil?
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
@@ -1,3 +1,3 @@
1
1
  class Payr::Bill < ActiveRecord::Base
2
- attr_accessible :amount, :article_id, :buyer_id, :state
2
+ attr_accessible :amount, :article_id, :buyer_id, :state, :bill_reference
3
3
  end
@@ -6,6 +6,7 @@ class CreateBillsTable < ActiveRecord::Migration
6
6
  t.integer :amount
7
7
  t.string :state
8
8
  t.string :error_code
9
+ t.string :bill_reference
9
10
  t.timestamps
10
11
  end
11
12
  end
@@ -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 "#{options[:callback_controller]}/#{action}", as: "payr_bills_#{action}"
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 "payr/bills/#{action}", as: "payr_bills_#{action}"
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
@@ -1,3 +1,3 @@
1
1
  module Payr
2
- VERSION = "1.0"
2
+ VERSION = "1.0.1"
3
3
  end
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: '1.0'
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-17 00:00:00.000000000 Z
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: -750663748071489907
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: -750663748071489907
150
+ hash: 2281109692306427172
151
151
  requirements: []
152
152
  rubyforge_project:
153
153
  rubygems_version: 1.8.24