robokassa 0.0.2 → 0.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +104 -110
  2. data/VERSION +1 -1
  3. data/config/routes.rb +5 -7
  4. metadata +2 -2
data/README.md CHANGED
@@ -21,138 +21,132 @@ Update your bundle
21
21
 
22
22
  bundle install
23
23
 
24
- ```ruby
25
24
  config/initializers/robokassa.rb:
26
25
 
27
- ROBOKASSA_SETTINGS = {
28
- :test_mode => true,
29
- :login => 'LOGIN',
30
- :password1 => 'PASSWORD1',
31
- :password2 => 'PASSWORD2'
32
- }
26
+ ROBOKASSA_SETTINGS = {
27
+ :test_mode => true,
28
+ :login => 'LOGIN',
29
+ :password1 => 'PASSWORD1',
30
+ :password2 => 'PASSWORD2'
31
+ }
32
+
33
+ $robokassa = Robokassa::Interface.new(ROBOKASSA_SETTINGS)
34
+
35
+ module Robokassa
36
+ class Interface
37
+ def notify_implementation(invoice_id, *args); end
38
+
39
+ class << self
40
+ def get_options_by_notification_key(key)
41
+ ROBOKASSA_SETTINGS
42
+ end
43
+
44
+ def success_implementation(invoice_id, *args)
45
+ payment = Payment.find_by_id(invoice_id)
46
+ payment.to_success!
47
+ end
48
+
49
+ def fail_implementation(invoice_id, *args)
50
+ payment = Payment.find_by_id(invoice_id)
51
+ payment.to_fail!
52
+ end
53
+ end
54
+ end
55
+ end
33
56
 
34
- $robokassa = Robokassa::Interface.new(ROBOKASSA_SETTINGS)
57
+ routes.rb:
35
58
 
36
- module Robokassa
37
- class Interface
38
- def notify_implementation(invoice_id, *args); end
59
+ mount Robokassa::Engine => "/robokassa", :as => "robokassa"
39
60
 
40
- class << self
41
- def get_options_by_notification_key(key)
42
- ROBOKASSA_SETTINGS
43
- end
61
+ app/controllers/dashboard/payments_controller.rb:
44
62
 
45
- def success_implementation(invoice_id, *args)
46
- payment = Payment.find_by_id(invoice_id)
47
- payment.to_success!
63
+ class Dashboard::PaymentsController < Dashboard::ApplicationController
64
+ ...
65
+ def create
66
+ @payment = current_user.payments.create!(:amount => params[:payment][:amount])
67
+ pay_url = $robokassa.init_payment_url(
68
+ @payment.id, @payment.amount, "Платеж № #{@payment.id}",
69
+ '', 'ru', current_user.email, {}
70
+ )
71
+ redirect_to pay_url
48
72
  end
73
+ ...
49
74
 
50
- def fail_implementation(invoice_id, *args)
51
- payment = Payment.find_by_id(invoice_id)
52
- payment.to_fail!
53
- end
54
- end
55
- end
56
- end
75
+ app/models/payment.rb:
57
76
 
58
- routes.rb:
77
+ class Payment < ActiveRecord::Base
78
+ include AASM
59
79
 
60
- ...
61
- controller :robokassa do
62
- get "robokassa/:notification_key/notify" => :notify, :as => :robokassa_notification
63
- get "robokassa/success" => :success, :as => :robokassa_on_success
64
- get "robokassa/fail" => :fail, :as => :robokassa_on_fail
65
- end
66
- ...
67
-
68
- class Dashboard::PaymentsController < Dashboard::ApplicationController
69
- ...
70
- def create
71
- @payment = current_user.payments.create!(:amount => params[:payment][:amount])
72
- pay_url = $robokassa.init_payment_url(
73
- @payment.id, @payment.amount, "Платеж № #{@payment.id}",
74
- '', 'ru', current_user.email, {}
75
- )
76
- redirect_to pay_url
77
- end
78
- ...
79
-
80
- class Payment < ActiveRecord::Base
81
- include AASM
82
-
83
- validates_presence_of :user_id, :amount
84
- attr_accessible :amount
85
- belongs_to :user
86
-
87
- default_scope order("id desc")
88
-
89
- aasm do
90
- state :new, :initial => true
91
- state :success
92
- state :fail
93
-
94
- event :to_success, :after => :give_money! do
95
- transitions :to => :success
96
- end
80
+ validates_presence_of :user_id, :amount
81
+ attr_accessible :amount
82
+ belongs_to :user
97
83
 
98
- event :to_fail do
99
- transitions :to => :fail
100
- end
101
- end
84
+ default_scope order("id desc")
85
+
86
+ aasm do
87
+ state :new, :initial => true
88
+ state :success
89
+ state :fail
90
+
91
+ event :to_success, :after => :give_money! do
92
+ transitions :to => :success
93
+ end
94
+
95
+ event :to_fail do
96
+ transitions :to => :fail
97
+ end
98
+ end
99
+
100
+ def state
101
+ self.aasm_state
102
+ end
102
103
 
103
- def state
104
- self.aasm_state
105
- end
104
+ def give_money!
105
+ self.user.give_money!(self.amount)
106
+ end
106
107
 
107
- def give_money!
108
- self.user.give_money!(self.amount)
109
- end
108
+ def printable_amount
109
+ "#{self.amount.to_s} руб."
110
+ end
111
+ end
110
112
 
111
- def printable_amount
112
- "#{self.amount.to_s} руб."
113
- end
114
- end
113
+ app/models/user.rb:
115
114
 
116
- class User < ActiveRecord::Base
117
- ...
118
- def give_money!(amount)
119
- sql = "update users set balance='#{self.balance + amount.to_f}' where id='#{self.id}'"
120
- connection.update(sql)
121
- end
122
- ...
115
+ class User < ActiveRecord::Base
116
+ ...
117
+ has_balance
118
+ ...
123
119
 
124
120
  dashboarb/payments/_form.html.erb:
125
121
 
126
- <%= semantic_form_for [:dashboard, @payment] do |f| %>
127
- <%= f.error_messages %>
128
- <%= f.input :amount %>
129
- <%= actions_for f, "Пополнить" %>
130
- <% end %>
122
+ <%= semantic_form_for [:dashboard, @payment] do |f| %>
123
+ <%= f.error_messages %>
124
+ <%= f.input :amount %>
125
+ <%= actions_for f, "Пополнить" %>
126
+ <% end %>
131
127
 
132
128
  app/controllers/robokassa.rb:
133
129
 
134
- # coding: utf-8
135
- class RobokassaController < Robokassa::Controller
136
- def success
137
- super
138
- @payment = Payment.find_by_id(params[:InvId])
139
- if @payment
140
- redirect_to dashboard_payment_path(@payment),
141
- :notice => "Ваш платеж на сумму #{@payment.amount.to_s} руб. успешно принят. Спасибо!"
142
- else
143
- redirect_to new_dashboard_payment_path,
144
- :error => "Не могу найти платеж по данному идентификатору"
145
- end
146
- end
147
-
148
- def fail
149
- super
150
- redirect_to dashboard_payments_path,
151
- :error => "Во время принятия платежа возникла ошибка. Мы скоро разберемся!"
152
- end
153
- end
130
+ # coding: utf-8
131
+ class RobokassaController < Robokassa::Controller
132
+ def success
133
+ super
134
+ @payment = Payment.find_by_id(params[:InvId])
135
+ if @payment
136
+ redirect_to dashboard_payment_path(@payment),
137
+ :notice => "Ваш платеж на сумму #{@payment.amount.to_s} руб. успешно принят. Спасибо!"
138
+ else
139
+ redirect_to new_dashboard_payment_path,
140
+ :error => "Не могу найти платеж по данному идентификатору"
141
+ end
142
+ end
154
143
 
155
- ```
144
+ def fail
145
+ super
146
+ redirect_to dashboard_payments_path,
147
+ :error => "Во время принятия платежа возникла ошибка. Мы скоро разберемся!"
148
+ end
149
+ end
156
150
 
157
151
  In Robokassa account settings set:
158
152
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.21
data/config/routes.rb CHANGED
@@ -1,8 +1,6 @@
1
- Rails.application.routes.draw do
2
- controller :robokassa do
3
- get "robokassa/:notification_key/notify" => :notify, :as => :robokassa_notification
4
-
5
- get "robokassa/success" => :success, :as => :robokassa_on_success
6
- get "robokassa/fail" => :fail, :as => :robokassa_on_fail
7
- end
1
+ # coding: utf-8
2
+ Robokassa::Engine.routes.draw do
3
+ get "/:notification_key/notify" => :notify, :as => :robokassa_notification
4
+ get "/success" => :success, :as => :robokassa_on_success
5
+ get "/fail" => :fail, :as => :robokassa_on_fail
8
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: robokassa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.21
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: 2013-03-31 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails