Skip to content

Commit

Permalink
separate test and production urls for robokassa
Browse files Browse the repository at this point in the history
  • Loading branch information
nashby committed Mar 16, 2012
1 parent 07fb549 commit c2ec85d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
30 changes: 23 additions & 7 deletions lib/active_merchant/billing/integrations/robokassa.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,28 +1,44 @@
module ActiveMerchant #:nodoc: module ActiveMerchant #:nodoc:
module Billing #:nodoc: module Billing #:nodoc:
module Integrations #:nodoc: module Integrations #:nodoc:

# Documentation: http://robokassa.ru/Doc/En/Interface.aspx # Documentation: http://robokassa.ru/Doc/En/Interface.aspx
module Robokassa module Robokassa
autoload :Helper, File.dirname(__FILE__) + '/robokassa/helper.rb' autoload :Helper, File.dirname(__FILE__) + '/robokassa/helper.rb'
autoload :Notification, File.dirname(__FILE__) + '/robokassa/notification.rb' autoload :Notification, File.dirname(__FILE__) + '/robokassa/notification.rb'
autoload :Return, File.dirname(__FILE__) + '/robokassa/return.rb' autoload :Return, File.dirname(__FILE__) + '/robokassa/return.rb'


mattr_accessor :service_url # Overwrite this if you want to change the Robokassa test url
self.service_url = 'https://merchant.roboxchange.com/Index.aspx' mattr_accessor :test_url
self.test_url = 'http://test.robokassa.ru/Index.aspx'

# Overwrite this if you want to change the Robokassa production url
mattr_accessor :production_url
self.production_url = 'https://merchant.roboxchange.com/Index.aspx'


mattr_accessor :signature_parameter_name mattr_accessor :signature_parameter_name
self.signature_parameter_name = 'SignatureValue' self.signature_parameter_name = 'SignatureValue'


def self.service_url
mode = ActiveMerchant::Billing::Base.integration_mode
case mode
when :production
self.production_url
when :test
self.test_url
else
raise StandardError, "Integration mode set to an invalid value: #{mode}"
end
end


def self.helper(order, account, options = {}) def self.helper(order, account, options = {})
Helper.new(order, account, options) Helper.new(order, account, options)
end end


def self.notification(query_string, options = {}) def self.notification(query_string, options = {})
Notification.new(query_string, options) Notification.new(query_string, options)
end end

def self.return(query_string) def self.return(query_string)
Return.new(query_string) Return.new(query_string)
end end
Expand Down
22 changes: 19 additions & 3 deletions test/unit/integrations/robokassa_module_test.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,12 +6,28 @@ class RobokassaModuleTest < Test::Unit::TestCase
def test_helper_method def test_helper_method
assert_instance_of Robokassa::Helper, Robokassa.helper(123, 'test') assert_instance_of Robokassa::Helper, Robokassa.helper(123, 'test')
end end

def test_notification_method def test_notification_method
assert_instance_of Robokassa::Notification, Robokassa.notification('name=cody') assert_instance_of Robokassa::Notification, Robokassa.notification('name=cody')
end end

def test_return_method def test_return_method
assert_instance_of Robokassa::Return, Robokassa.return('name=cody') assert_instance_of Robokassa::Return, Robokassa.return('name=cody')
end end
end
def test_test_mode
ActiveMerchant::Billing::Base.integration_mode = :test
assert_equal 'http://test.robokassa.ru/Index.aspx', Robokassa.service_url
end

def test_production_mode
ActiveMerchant::Billing::Base.integration_mode = :production
assert_equal 'https://merchant.roboxchange.com/Index.aspx', Robokassa.service_url
end

def test_invalid_mode
ActiveMerchant::Billing::Base.integration_mode = :bro
assert_raise(StandardError){ Robokassa.service_url }
end

end

0 comments on commit c2ec85d

Please sign in to comment.