diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1898635 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2009 Vitaly Kushner + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.markdown b/README.markdown index d0daee6..3d0d88a 100644 --- a/README.markdown +++ b/README.markdown @@ -45,4 +45,16 @@ Once you've configured the Ogone settings you need to set up a leaving page with response.inspect -Copyright (c) 2010 Astrails Ltd., released under the MIT license +## Note on Patches/Pull Requests + +* Fork the project. +* Make your feature addition or bug fix. +* Add tests for it. This is important so I don't break it in a + future version unintentionally. +* Commit, do not mess with rakefile, version, or history. + (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) +* Send me a pull request. Bonus points for topic branches. + +## Copyright + +Copyright (c) 2010 Astrails Ltd. See LICENSE for details. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..221dd25 --- /dev/null +++ b/Rakefile @@ -0,0 +1,51 @@ +require 'rubygems' +require 'rake' + +begin + require 'jeweler' + Jeweler::Tasks.new do |gem| + gem.name = "active_merchant_tranzila" + gem.summary = %Q{Tranzila gateway support for ActiveMerchant} + gem.description = %Q{Tranzila gateway support for ActiveMerchant} + gem.email = "we@astrails.com" + gem.homepage = "http://github.com/astrails/active_merchant_tranzila" + gem.authors = ["Astrails Ltd."] + end + Jeweler::GemcutterTasks.new +rescue LoadError + puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler" +end + +require 'rake/testtask' +Rake::TestTask.new(:test) do |test| + test.libs << 'lib' << 'test' + test.pattern = 'test/**/*_test.rb' + test.verbose = true +end + +begin + require 'rcov/rcovtask' + Rcov::RcovTask.new do |test| + test.libs << 'test' + test.pattern = 'test/**/*_test.rb' + test.verbose = true + end +rescue LoadError + task :rcov do + abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov" + end +end + +task :test => :check_dependencies + +task :default => :test + +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "active_merchant_tranzila #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/active_merchant_tranzila.gemspec b/active_merchant_tranzila.gemspec new file mode 100644 index 0000000..81187e2 --- /dev/null +++ b/active_merchant_tranzila.gemspec @@ -0,0 +1,50 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{active_merchant_tranzila} + s.version = "0.0.1" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Vitaly Kushner"] + s.date = %q{2010-08-11} + s.description = %q{TODO: longer description of your gem} + s.email = %q{vitaly@astrails.com} + s.extra_rdoc_files = [ + "LICENSE", + "README.markdown" + ] + s.files = [ + "LICENSE", + "README.markdown", + "Rakefile", + "lib/active_merchant/billing/gateways/tranzila.rb", + "lib/active_merchant_tranzila.rb", + "test/helper.rb", + "test/remote/gateways/remote_tranzila_test.rb", + "test/unit/gateways/tranzila_test.rb" + ] + s.homepage = %q{http://github.com/vitaly/active_merchant_tranzila} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.6} + s.summary = %q{TODO: one-line summary of your gem} + s.test_files = [ + "test/helper.rb", + "test/remote/gateways/remote_tranzila_test.rb", + "test/unit/gateways/tranzila_test.rb" + ] + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end + diff --git a/lib/active_merchant/billing/gateways/tranzila.rb b/lib/active_merchant/billing/gateways/tranzila.rb index a71ea33..e1983c0 100644 --- a/lib/active_merchant/billing/gateways/tranzila.rb +++ b/lib/active_merchant/billing/gateways/tranzila.rb @@ -1,3 +1,4 @@ +require 'active_merchant' module ActiveMerchant #:nodoc: module Billing #:nodoc: # This class implements the Tranzila (http://www.tranzila.com) Israeli payment gateway. diff --git a/lib/active_merchant_tranzila.rb b/lib/active_merchant_tranzila.rb new file mode 100644 index 0000000..92ca645 --- /dev/null +++ b/lib/active_merchant_tranzila.rb @@ -0,0 +1 @@ +require 'active_merchant/billing/gateways/tranzila' diff --git a/test/helper.rb b/test/helper.rb new file mode 100644 index 0000000..84800de --- /dev/null +++ b/test/helper.rb @@ -0,0 +1,107 @@ +require 'rubygems' +require 'test/unit' +require 'mocha' + + +$LOAD_PATH.unshift(File.dirname(__FILE__)) +$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'active_merchant_tranzila' + +ActiveMerchant::Billing::Base.mode = :test + +module ActiveMerchant + module Assertions + AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError + + def assert_field(field, value) + clean_backtrace do + assert_equal value, @helper.fields[field] + end + end + + # Allows the testing of you to check for negative assertions: + # + # # Instead of + # assert !something_that_is_false + # + # # Do this + # assert_false something_that_should_be_false + # + # An optional +msg+ parameter is available to help you debug. + def assert_false(boolean, message = nil) + message = build_message message, ' is not false or nil.', boolean + + clean_backtrace do + assert_block message do + not boolean + end + end + end + + # A handy little assertion to check for a successful response: + # + # # Instead of + # assert_success response + # + # # DRY that up with + # assert_success response + # + # A message will automatically show the inspection of the response + # object if things go afoul. + def assert_success(response) + clean_backtrace do + assert response.success?, "Response failed: #{response.inspect}" + end + end + + # The negative of +assert_success+ + def assert_failure(response) + clean_backtrace do + assert_false response.success?, "Response expected to fail: #{response.inspect}" + end + end + + def assert_valid(validateable) + clean_backtrace do + assert validateable.valid?, "Expected to be valid" + end + end + + def assert_not_valid(validateable) + clean_backtrace do + assert_false validateable.valid?, "Expected to not be valid" + end + end + + private + def clean_backtrace(&block) + yield + rescue AssertionClass => e + path = File.expand_path(__FILE__) + raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ } + end + end + + module Fixtures + private + def credit_card(number = '4242424242424242', options = {}) + defaults = { + :number => number, + :month => 9, + :year => Time.now.year + 1, + :first_name => 'Longbob', + :last_name => 'Longsen', + :verification_value => '123', + :type => 'visa' + }.update(options) + + Billing::CreditCard.new(defaults) + end + end +end + +class Test::Unit::TestCase + include ActiveMerchant::Billing + include ActiveMerchant::Fixtures + include ActiveMerchant::Assertions +end diff --git a/test/remote/gateways/remote_tranzila_test.rb b/test/remote/gateways/remote_tranzila_test.rb deleted file mode 100644 index c648464..0000000 --- a/test/remote/gateways/remote_tranzila_test.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'test_helper' - -class RemoteTranzilaTest < Test::Unit::TestCase - - - def setup - @gateway = TranzilaGateway.new(fixtures(:tranzila)) - - @amount = 100 - @credit_card = credit_card('4000100011112224') - @declined_card = credit_card('4000300011112220') - - @options = { - :order_id => '1', - :billing_address => address, - :description => 'Store Purchase' - } - end - - def test_successful_purchase - assert response = @gateway.purchase(@amount, @credit_card, @options) - assert_success response - assert_equal 'REPLACE WITH SUCCESS MESSAGE', response.message - end - - def test_unsuccessful_purchase - assert response = @gateway.purchase(@amount, @declined_card, @options) - assert_failure response - assert_equal 'REPLACE WITH FAILED PURCHASE MESSAGE', response.message - end - - def test_authorize_and_capture - amount = @amount - assert auth = @gateway.authorize(amount, @credit_card, @options) - assert_success auth - assert_equal 'Success', auth.message - assert auth.authorization - assert capture = @gateway.capture(amount, auth.authorization) - assert_success capture - end - - def test_failed_capture - assert response = @gateway.capture(@amount, '') - assert_failure response - assert_equal 'REPLACE WITH GATEWAY FAILURE MESSAGE', response.message - end - - def test_invalid_login - gateway = TranzilaGateway.new( - :login => '', - :password => '' - ) - assert response = gateway.purchase(@amount, @credit_card, @options) - assert_failure response - assert_equal 'REPLACE WITH FAILURE MESSAGE', response.message - end -end diff --git a/test/unit/gateways/tranzila_test.rb b/test/unit/gateways/tranzila_test.rb index fe3e4fe..0e0bab3 100644 --- a/test/unit/gateways/tranzila_test.rb +++ b/test/unit/gateways/tranzila_test.rb @@ -1,4 +1,4 @@ -require 'test_helper' +require 'helper' require 'rubygems' require 'ruby-debug' @@ -8,9 +8,9 @@ def setup @credit_card = credit_card('4444333322221111') @amount = 100.00 - - @options = { - :cred_type => '1', + + @options = { + :cred_type => '1', :myid => '306122847', :ConfirmationCode => '0000000', :index => '11' @@ -19,18 +19,18 @@ def setup def test_successful(successful_response, action) @gateway.expects(:ssl_post).returns(successful_response) - + assert response = @gateway.send(action, @amount, @credit_card, @options) - assert_instance_of Response, response + assert_instance_of Response, response assert_success response - + assert_equal '000', response.params['Response'] assert response.test? end def test_unsuccessful(failed_response, action, opts = {}) @gateway.expects(:ssl_post).returns(failed_response) - + assert response = @gateway.send(action, @amount, @credit_card, @options) assert_failure response assert response.test? @@ -40,7 +40,7 @@ def test_successful_purchase test_successful(successful_purchase_response, :purchase) end - def test_unsuccessful_purchas + def test_unsuccessful_purchase test_unsuccessful(failed_purchase_response, :purchase) end @@ -104,5 +104,5 @@ def failed_purchase_response def successful_purchase_response "Response=000&ccno=4444333322221111¤cy=1&cred_type=1&mycvv=123&expyear=15&supplier=test3&expmonth=09&myid=306122847&expdate=0915&sum=1.00&ConfirmationCode=0000000&index=88&Tempref=01300001&CVVstatus=3&Responsesource=0\n\n" end - + end