diff --git a/app/controllers/robokassa_controller.rb b/app/controllers/robokassa_controller.rb index 7f990ba..0872a31 100644 --- a/app/controllers/robokassa_controller.rb +++ b/app/controllers/robokassa_controller.rb @@ -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 diff --git a/lib/rubykassa.rb b/lib/rubykassa.rb index a4a9538..cb44c6b 100644 --- a/lib/rubykassa.rb +++ b/lib/rubykassa.rb @@ -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 diff --git a/lib/rubykassa/configuration.rb b/lib/rubykassa/configuration.rb index 61bbb82..2385b8f 100644 --- a/lib/rubykassa/configuration.rb +++ b/lib/rubykassa/configuration.rb @@ -2,6 +2,8 @@ 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" @@ -9,7 +11,9 @@ def initialize 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 diff --git a/spec/rubykassa/client_configuration_spec.rb b/spec/rubykassa/client_configuration_spec.rb index 448d382..7f783df 100644 --- a/spec/rubykassa/client_configuration_spec.rb +++ b/spec/rubykassa/client_configuration_spec.rb @@ -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