diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..c961850 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in activemerchant-anz.gemspec +gemspec diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..c403836 --- /dev/null +++ b/LICENCE @@ -0,0 +1,19 @@ +Copyright (C) 2009 by Anuj Luthra + +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. \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index 8aca1f8..0000000 --- a/README +++ /dev/null @@ -1,14 +0,0 @@ -# ANZ eGate Gateway for ActiveMerchant - -the gateway uses mastercard migs virtual payment client for payments. Requests are sent by POST over https. - -Gateways supports: - -1. Purchase -2. Refund/Credit -3. Query past payment requests - -TODO LIST: - -1. Authorize -2. Capture diff --git a/README.md b/README.md new file mode 100644 index 0000000..caee3ad --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# Anz eGate + +Provides an ActiveMerchant gateway to interface with ANZ's eGate. + +## Usage + +This is now available as a gem, as long as you have it in your Gemfile you can use bundler. + +Gemfile + + source :rubygems + + gem 'activemerchant-anz-gateway' + +Basic Usage + + require 'bundler' + Bundler.require + + # Your merchant must have operators, to test prefix your merchant name with TEST + gateway = ActiveMerchant::Billing::AnzGateway.new( + :merchant_id => 'TESTANZMURCONREG', + :access_code => '31C43EF3' + ) + + # ANZ only require the card number, month and year + card = ActiveMerchant::Billing::CreditCard.new( + :number => '5123456789012346', + :month => 5, + :year => 2013 + ) + + params = { + :order_id => 'X123F', + :invoice => '10001' + } + + # $10 puchase + result = gateway.purchase(1000, card, params) + +Other Features + +There are features for refuding/crediting and querying past records, however these are missing tests and I can't vouch for them. + +You can manage your anz merchant account over at https://migs.mastercard.com.au/ma + +## Testing + +Anz seem to have removed their public testing profile, I've instead set the fixtures to come from environment variables + + export ANZ_MERCHANT=TESTyoumerchantname + export ANZ_CODE=youroperatorcode + +To set up your testing environment you will need to log in as the _Administrator_ using your merchantid prefixed by test. The password will be the same as your production account. + +## Acknowledgements + +I had pretty much nothing to do with this library, I just made it into a gem and check on the tests. This is a fork of [Anuj Luthra's](https://github.com/anujluthra) [fantastic work](https://github.com/anujluthra/activemerchant-anz-gateway). + +# LICENCE + +Licenced under MIT Copyright 2009 by Anuj Luthra, for details see LICENCE \ No newline at end of file diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2995527 --- /dev/null +++ b/Rakefile @@ -0,0 +1 @@ +require "bundler/gem_tasks" diff --git a/activemerchant-anz-gateway.gemspec b/activemerchant-anz-gateway.gemspec new file mode 100644 index 0000000..cf4d679 --- /dev/null +++ b/activemerchant-anz-gateway.gemspec @@ -0,0 +1,26 @@ +require File.expand_path("../lib/active_merchant-anz/version", __FILE__) + +Gem::Specification.new do |s| + s.platform = Gem::Platform::RUBY + s.name = "activemerchant-anz-gateway" + s.version = ActiveMerchant::Anz::VERSION + s.authors = ["Anuj Luthra", "Dirk Kelly"] + s.email = ["anuj.luthra@gmail.com", "dk@dirkkelly.com"] + s.homepage = "" + s.summary = %q{Gateway for ANZ and ActiveMerchant} + s.description = %q{Provides an interface to ANZ for the Activemerchant library, fork of github@anujluthra's work} + + s.rubyforge_project = "activemerchant-anz-gateway" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] + + # specify any dependencies here; for example: + s.add_development_dependency "test-unit" + s.add_development_dependency "mocha" + + s.add_runtime_dependency "activemerchant" + s.add_runtime_dependency "activesupport" +end diff --git a/lib/active_merchant-anz.rb b/lib/active_merchant-anz.rb new file mode 100644 index 0000000..234c7d6 --- /dev/null +++ b/lib/active_merchant-anz.rb @@ -0,0 +1,13 @@ +require 'active_merchant' +require 'active_merchant/billing' +require 'active_support/core_ext/object' + +require "active_merchant-anz/version" +require "active_merchant/billing/gateways/anz" + + +module ActiveMerchant + module Anz + # Your code goes here... + end +end \ No newline at end of file diff --git a/lib/active_merchant-anz/version.rb b/lib/active_merchant-anz/version.rb new file mode 100644 index 0000000..cbf9470 --- /dev/null +++ b/lib/active_merchant-anz/version.rb @@ -0,0 +1,5 @@ +module ActiveMerchant + module Anz + VERSION = "0.1.0" + end +end diff --git a/lib/active_merchant/billing/gateways/anz.rb b/lib/active_merchant/billing/gateways/anz.rb index 06dbb1f..6130980 100644 --- a/lib/active_merchant/billing/gateways/anz.rb +++ b/lib/active_merchant/billing/gateways/anz.rb @@ -1,8 +1,13 @@ require 'cgi' +require 'active_merchant' +require 'active_merchant/billing' + module ActiveMerchant #:nodoc: module Billing #:nodoc: class AnzGateway < Gateway - + + undef_method :capture + self.supported_countries = ['AU'] self.supported_cardtypes = [:visa, :master, :american_express, :diners_club] self.money_format = :cents @@ -10,7 +15,7 @@ class AnzGateway < Gateway self.display_name = 'ANZ eGate' GATEWAY_URL = "https://migs.mastercard.com.au/vpcdps" VIRTUAL_PAYMENT_CLIENT_API_VERION = 1 - + def initialize(options={}) requires!(options, :merchant_id, :access_code) if options[:mode] && (options[:mode].to_sym == :production || options[:mode].to_sym == :test) @@ -19,11 +24,11 @@ def initialize(options={}) @options = options super end - + ######################################################## # allowed operations for mastercard migs virtual gateway ######################################################## - + #actual payment def purchase(money, creditcard, options = {}) requires!(options, :invoice, :order_id) @@ -34,10 +39,10 @@ def purchase(money, creditcard, options = {}) add_amount(params, money) process_action('pay', params) end - + ############################################################### ## Next two operations require a AMA username and AMA password - + #refunds to the customer's card. autorization id is required def credit(money, authorization_number, options = {}) requires!(options, :username, :password, :order_id) @@ -48,7 +53,7 @@ def credit(money, authorization_number, options = {}) add_amount(params, money) process_action('refund', params) end - + #query a past payment, unique merchant transaction ref. is required def query(merchant_transaction_id) params = {} @@ -60,14 +65,14 @@ def query(merchant_transaction_id) ######################################################### #methods to beautify and prepare the params before handing over to bank ######################################################### - + def process_action(action, params) payment_params = post_data(action, params) response = ssl_post GATEWAY_URL, payment_params build_response(response) end - #ADDS + #ADDS # # def post_data(action, params) @@ -76,46 +81,47 @@ def post_data(action, params) :vpc_Merchant => @options[:merchant_id], :vpc_Command => action).to_query end - + def add_invoice_number(params, invoice_number) return params.merge!(:vpc_TicketNo => invoice_number, :vpc_OrderInfo => invoice_number) end - + def add_credit_card(params, creditcard) + expiry = "#{creditcard.year.to_s[-2,2]}#{sprintf("%.2i", creditcard.month)}" return params.merge!(:vpc_CardNum => creditcard.number, :vpc_CardSecurityCode => creditcard.verification_value, - :vpc_CardExp => "#{creditcard.year.to_s.last(2)}#{sprintf("%.2i", creditcard.month)}") + :vpc_CardExp => "#{expiry}") end def add_amount(params, money) - params[:vpc_Amount] = amount(money) + params[:vpc_Amount] = money.to_i end #ADDS THE AUTHORIZATION NUMBER OF A PREVIOUS TRANSACTION - #IN THE REQUEST PARAMS. THIS IS MOSTLY USED IN A REFUND + #IN THE REQUEST PARAMS. THIS IS MOSTLY USED IN A REFUND #OR A QUERY FOR A PREVIOUSLY PERFORMED TRANSACTION def add_authorization_number(params, authorization) return params.merge!(:vpc_TransactionNo => authorization) end - + #ADDS A UNIQUE ID(can be alpanumeric) TO THE PARAMS LIST. - #EVERY TRANSACTION SENT TO BANKING GATEWAY SHOULD HAVE A + #EVERY TRANSACTION SENT TO BANKING GATEWAY SHOULD HAVE A #UNIQUE IDENTIFICATION NUMBER. THIS HELPS IN TRACING THE #TRANSACTION IN CASE OF QUERIES AND AUDITS. THIS IS A REQUIRED #FIELD IN EVERY REQUEST SENT TO GATEWAY. def add_merchant_transaction_id(params, transaction_id) return params.merge!(:vpc_MerchTxnRef => transaction_id) end - - #USED FOR REFUNDS AND QUERYING THE GATEWAY. NEED THE + + #USED FOR REFUNDS AND QUERYING THE GATEWAY. NEED THE #MA USERNAME AND PASSWORD REQUIRED. THESE ARE SUPPLIED #BY THE BANKING AUTHORITY. def add_username_password(params, username, password) return params.merge!(:vpc_User => username, :vpc_Password => password) end - + def build_response(response_str) response = parse(response_str) authorization = response['vpc_TransactionNo'] @@ -123,11 +129,11 @@ def build_response(response_str) message = CGI.unescape(response['vpc_Message']) Response.new(success, message, response, :authorization => authorization, :test => test?) end - + def parse(html_encoded_url) params = CGI::parse(html_encoded_url) hash = {} - params.each do|key, value| + params.each do|key, value| hash[key] = value[0] end hash diff --git a/lib/activemerchant-anz-gateway.rb b/lib/activemerchant-anz-gateway.rb new file mode 100644 index 0000000..73267c2 --- /dev/null +++ b/lib/activemerchant-anz-gateway.rb @@ -0,0 +1 @@ +require 'active_merchant-anz' \ No newline at end of file diff --git a/test/fixtures.yml b/test/fixtures.yml index 80142aa..4ac2964 100644 --- a/test/fixtures.yml +++ b/test/fixtures.yml @@ -1,321 +1,3 @@ -# This file has all of the ActiveMerchant test account credentials. -# Many gateways do not offer publicly available test accounts. In -# order to make testing the gateways easy you can copy this file to -# your home directory as the file ~/.active_merchant/fixtures.yml -# You can then place your own test account credentials in your local -# copy of the file. -# -# If the login is numeric, ensure that you place quotes around it. -# Leading zeros will be lost when YAML parses the file if you don't. -# -# Paste any required PEM certificates after the pem key. -# anz: - merchant_id: TESTANZTEST3 - access_code: 6447E199 - -authorize_net: - login: X - password: Y - -beanstream: - login: merchant id - user: username - password: password - -beanstream_interac: - login: merchant id - user: username - password: password - -braintree: - login: demo - password: password - -card_stream: - login: X - password: Y - -cyber_source: - login: X - password: Y - -data_cash: - login: X - password: Y - -efsnet: - login: X - password: Y - -# Working credentials, no need to replace -eway: - login: '87654321' - -# Working credentials, no need to replace -exact: - login: "A00427-01" - password: testus - -ideal_ing_postbank: - login: LOGIN - password: PASSWORD - pem: |-- - PASTE YOUR PEM FILE HERE - -linkpoint: - login: STOREID - pem: |-- - PASTE YOUR PEM FILE HERE - -modern_payments: - login: login - password: password - -# Working credentials, no need to replace -moneris: - login: store1 - password: yesguy - -# Working credentials, no need to replace -# Contact Netbilling for login info to the admin area -netbilling: - login: '104901072025' - -net_registry: - login: X - password: Y - -payflow: - login: LOGIN - password: PASSWORD - partner: PayPal - -payflow_uk: - login: LOGIN - password: PASSWORD - partner: PayPalUk - -# Working credentials, no need to replace -pay_junction: - login: 'pj-ql-01' - password: 'pj-ql-01p' - -payment_express: - login: LOGIN - password: PASSWORD - -# You can use either your API PEM file or API signature with PayPal. -paypal_certificate: - login: LOGIN - password: PASSWORD - subject: - pem: |-- - PASTE YOUR PEM FILE HERE - -paypal_signature: - login: LOGIN - password: PASSWORD - signature: SIGNATURE - -pay_secure: - login: LOGIN - password: PASSWORD - -plugnpay: - login: LOGIN - password: PASSWORD - -protx: - login: LOGIN - -# Working credentials, no need to replace -psigate: - login: teststore - password: psigate1234 - -psl_card: - login: LOGIN - -# PSL doesn't want the test data made public -psl_maestro: - number: - month: - year: - verification_value: - issue_number: - -psl_maestro_address: - address1: - address2: - city: - state: - zip: - -psl_solo: - number: - month: - year: - verification_value: - issue_number: - -psl_solo_address: - address1: - city: - state: - zip: - -psl_visa: - number: - month: - year: - verification_value: - -psl_visa_address: - address1: - address2: - address3: - city: - zip: - -psl_visa_debit: - first_name: - last_name: - number: - month: - year: - verification_value: - -psl_visa_debit_address: - address1: - address2: - address3: - city: - state: - zip: - -quickpay: - login: 89898989 - password: "n5KrR5e2538awi9hUk6728LHTQ6E4uG1z4IFSb2pPN9j76DqJ2vA4698X315M1cd" - -realex: - login: X - password: Y - -realex_with_account: - login: X - password: Y - account: testaccount - -# Realex doesn't provide public testing data -# Fill in the card numbers with the Realex test -# data. -realex_visa: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_visa_declined: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_visa_referral_a: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_visa_referral_b: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_visa_coms_error: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_mastercard: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_mastercard_declined: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_mastercard_referral_a: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_mastercard_referral_b: - number: - month: '6' - year: '2020' - verification_value: '123' - -realex_mastercard_coms_error: - number: - month: '6' - year: '2020' - verification_value: '123' - -sage: - login: login - password: password - -secure_pay: - login: LOGIN - password: PASSWORD - -secure_pay_tech: - login: TESTDIGISPL1 - password: d557591484cb2cd12bba445aba420d2c69cd6a88 - -secure_pay_au: - login: - password: - -# Replace with your serial numbers for the skipjack test environment -skipjack: - login: X - password: Y - -trans_first: - login: LOGIN - password: PASSWORD - -# Working credentials, no need to replace -trust_commerce: - login: 'TestMerchant' - password: 'password' - -# Working credentials, no need to replace -usa_epay: - login: 'yCaWGYQsSVR0S48B6AKMK07RQhaxHvGu' - -# Working credentials, no need to replace -verify: - login: 'demo' - password: 'password' - -viaklix: - login: LOGIN - password: PASSWORD - user: USER - -# Working test credentials, no need to replace -wirecard: - login: 56500 - password: TestXAPTER - + merchant_id: <%= ENV['ANZ_MERCHANT'] %> + access_code: <%= ENV['ANZ_CODE'] %> \ No newline at end of file diff --git a/test/remote/gateways/remote_anz_test.rb b/test/remote/gateways/remote_anz_test.rb index 96967e8..27a906b 100644 --- a/test/remote/gateways/remote_anz_test.rb +++ b/test/remote/gateways/remote_anz_test.rb @@ -1,53 +1,44 @@ -require File.dirname(__FILE__) + '/../../test_helper' +require File.expand_path('../../test_helper',File.dirname(__FILE__)) class AnzTest < Test::Unit::TestCase def setup - Base.gateway_mode = :test @gateway = AnzGateway.new(fixtures(:anz)) - @credit_card_success = credit_card('5123456789012346', + @credit_card_success = credit_card('5123456789012346', :month => 5, :year => 2013 ) - + @credit_card_fail = credit_card('1234567812345678', :month => Time.now.month, - :year => Time.now.year + :year => Time.now.year ) - + @params = { - :booking_number => '222222D', - :unique_id => 'efad6659cea26be50fe36cbdec91f042', + :order_id => 'X123F', + :invoice => '10001' } end - + def test_invalid_amount - assert response = @gateway.purchase(Money.new(0), @credit_card_success, @params) + assert response = @gateway.purchase(0, @credit_card_success, @params) assert_failure response assert response.test? end - - def test_purchase_success_with_verification_value - assert response = @gateway.purchase(Money.new(100), @credit_card_success, @params) + + def test_purchase_success_with_verification_value + assert response = @gateway.purchase(100, @credit_card_success, @params) assert_success response assert response.test? end -# def test_purchase_with_invalid_verification_value -# @credit_card_success.verification_value = 'AAA' -# assert response = @gateway.purchase(100, @credit_card_success, @params) -# assert_nil response.authorization -# assert_failure response -# assert response.test? -# end - def test_invalid_expiration_date - @credit_card_success.year = 2005 + @credit_card_success.year = 2005 assert response = @gateway.purchase(100, @credit_card_success, @params) assert_failure response assert response.test? end - + def test_purchase_error assert response = @gateway.purchase(100, @credit_card_fail, @params) assert_equal false, response.success? diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..0928af6 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,178 @@ +begin + require 'rubygems' + require 'bundler' + Bundler.setup +rescue LoadError => e + puts "Error loading bundler (#{e.message}): \"gem install bundler\" for bundler support." +end + + +require 'test/unit' +require 'mocha' +require 'erb' +require 'activemerchant-anz-gateway' + +ActiveMerchant::Billing::Base.mode = :test + +class AnzGateway < ActiveMerchant::Billing::AnzGateway +end + +module ActiveMerchant + module Assertions + AssertionClass = 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 + + def assert_deprecation_warning(message, target) + target.expects(:deprecated).with(message) + yield + 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 + HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR) + LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS) + DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS) + + 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 + + def check(options = {}) + defaults = { + :name => 'Jim Smith', + :routing_number => '244183602', + :account_number => '15378535', + :account_holder_type => 'personal', + :account_type => 'checking', + :number => '1' + }.update(options) + + Billing::Check.new(defaults) + end + + def address(options = {}) + { + :name => 'Jim Smith', + :address1 => '1234 My Street', + :address2 => 'Apt 1', + :company => 'Widgets Inc', + :city => 'Ottawa', + :state => 'ON', + :zip => 'K1C2N6', + :country => 'CA', + :phone => '(555)555-5555', + :fax => '(555)555-6666' + }.update(options) + end + + def all_fixtures + @@fixtures ||= load_fixtures + end + + def fixtures(key) + data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'") + + data.dup + end + + def load_fixtures + file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS + yaml_data = YAML.load(ERB.new(File.read(file)).result) + symbolize_keys(yaml_data) + + yaml_data + end + + def symbolize_keys(hash) + return unless hash.is_a?(Hash) + + hash.symbolize_keys! + hash.each{|k,v| symbolize_keys(v)} + end + end +end + +Test::Unit::TestCase.class_eval do + include ActiveMerchant::Billing + include ActiveMerchant::Assertions + include ActiveMerchant::Utils + include ActiveMerchant::Fixtures +end \ No newline at end of file diff --git a/test/unit/gateways/anz_test.rb b/test/unit/gateways/anz_test.rb index 9c75a55..9f055f8 100644 --- a/test/unit/gateways/anz_test.rb +++ b/test/unit/gateways/anz_test.rb @@ -1,67 +1,65 @@ -require File.dirname(__FILE__) + '/../../test_helper' +require File.expand_path('../../test_helper',File.dirname(__FILE__)) class AnzTest < Test::Unit::TestCase def setup - Base.gateway_mode = :test @gateway = AnzGateway.new(fixtures(:anz)) - @credit_card_success = credit_card('5123456789012346', + @credit_card_success = credit_card('5123456789012346', :month => 5, :year => 2013 ) - + @credit_card_fail = credit_card('1234567812345678', :month => Time.now.month, :year => Time.now.year ) - + @options = { - :booking_number => '222222D', - :unique_id => 'efad6659cea26be50fe36cbdec91f042', + :order_id => 'X123F', + :invoice => '10001', } - - @amount = Money.new(100) + + @amount = 100 end - + def test_successful_purchase @gateway.expects(:ssl_post).returns(successful_purchase_response) - + assert response = @gateway.purchase(@amount, @credit_card_success, @options) assert_instance_of Response, response assert_success response assert !response.authorization.blank? end - + def test_failed_purchase @gateway.expects(:ssl_post).returns(failed_purchase_response) - + assert response = @gateway.purchase(@amount, @credit_card_fail, @options) assert_instance_of Response, response assert_failure response end - + def test_amount_style assert_equal '1034', @gateway.send(:amount, 1034) - assert_equal '1034', @gateway.send(:amount, Money.new(1034)) - + assert_raise(ArgumentError) do @gateway.send(:amount, '10.34') end end - + def test_ensure_does_not_respond_to_authorize assert !@gateway.respond_to?(:authorize) end - + def test_ensure_does_not_respond_to_capture assert !@gateway.respond_to?(:capture) end - + private def successful_purchase_response "vpc_AVSResultCode=Unsupported&vpc_AcqAVSRespCode=Unsupported&vpc_AcqCSCRespCode=Unsupported&vpc_AcqResponseCode=00&vpc_Amount=1400&vpc_AuthorizeId=029968&vpc_BatchNo=20080206&vpc_CSCResultCode=Unsupported&vpc_Card=MC&vpc_Command=pay&vpc_Locale=en_AU&vpc_MerchTxnRef=91bca776862f19b7757f58fc7dfdf99c&vpc_Merchant=TESTANZTEST3&vpc_Message=Approved&vpc_OrderInfo=222223&vpc_ReceiptNo=080206029968&vpc_TransactionNo=1572808&vpc_TxnResponseCode=0&vpc_Version=1" end - + def failed_purchase_response "vpc_Amount=1400&vpc_BatchNo=0&vpc_Command=pay&vpc_Locale=en_AU&vpc_MerchTxnRef=ae4dfece4b1791f47407c8fc9364d885&vpc_Merchant=TESTANZTEST3&vpc_Message=I5154-02061204%3A+Invalid+Card+Number+%3A+CardNum&vpc_OrderInfo=222223&vpc_TransactionNo=0&vpc_TxnResponseCode=7&vpc_Version=1" end