Skip to content

Commit

Permalink
Merge 1e366e9 into b456b47
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKishenin committed Apr 29, 2014
2 parents b456b47 + 1e366e9 commit 9874017
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/controllers/robokassa_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ def paid
if @notification.valid_result_signature?
render text: @notification.success
else
render text: "fail"
Rubykassa.fail_callback.call
end
end

def success
if @notification.valid_success_signature?
render text: "success"
Rubykassa.success_callback.call
else
render text: "fail"
Rubykassa.fail_callback.call
end
end

def fail
render text: "fail"
Rubykassa.fail_callback.call
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/rubykassa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def configure &block
Rubykassa::Client.configure &block
end

%w(login first_password second_password mode http_method xml_http_method).map do |name|
%w(login first_password second_password mode http_method xml_http_method success_callback fail_callback).map do |name|
define_method name do
Rubykassa::Client.configuration.send(name)
end
Expand Down
6 changes: 5 additions & 1 deletion lib/rubykassa/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
module Rubykassa
class Configuration
attr_accessor :login, :first_password, :second_password, :mode, :http_method, :xml_http_method
attr_accessor :success_callback
attr_accessor :fail_callback

def initialize
self.login = "your_login"
self.first_password = "first_password"
self.second_password = "second_password"
self.mode = :test
self.http_method = :get
self.xml_http_method = :get
self.xml_http_method = :get
self.success_callback = -> {}
self.fail_callback = -> {}
end
end
end
12 changes: 12 additions & 0 deletions spec/rubykassa/client_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@
Rubykassa.mode.should == :test
Rubykassa.http_method.should == :get
Rubykassa.http_method.should == :get
expect(Rubykassa.success_callback).to be_instance_of(Proc)
expect(Rubykassa.fail_callback).to be_instance_of(Proc)
end

it "should set success_callback" do
Rubykassa.configure do |config|
config.success_callback = -> {
2 + 5
}
end

expect(Rubykassa.success_callback.call).to eq(7)
end

it "should raise error when wrong mode is set" do
Expand Down

0 comments on commit 9874017

Please sign in to comment.