activemerchant-anz-gateway 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENCE +19 -0
- data/README.md +62 -0
- data/Rakefile +1 -0
- data/activemerchant-anz-gateway.gemspec +26 -0
- data/lib/active_merchant-anz.rb +13 -0
- data/lib/active_merchant-anz/version.rb +5 -0
- data/lib/active_merchant/billing/gateways/anz.rb +143 -0
- data/lib/activemerchant-anz-gateway.rb +1 -0
- data/test/fixtures.yml +3 -0
- data/test/remote/gateways/remote_anz_test.rb +47 -0
- data/test/test_helper.rb +178 -0
- data/test/unit/gateways/anz_test.rb +68 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENCE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2009 by Anuj Luthra
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Anz eGate
|
2
|
+
|
3
|
+
Provides an ActiveMerchant gateway to interface with ANZ's eGate.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
This is now available as a gem, as long as you have it in your Gemfile you can use bundler.
|
8
|
+
|
9
|
+
Gemfile
|
10
|
+
|
11
|
+
source :rubygems
|
12
|
+
|
13
|
+
gem 'activemerchant-anz-gateway'
|
14
|
+
|
15
|
+
Basic Usage
|
16
|
+
|
17
|
+
require 'bundler'
|
18
|
+
Bundler.require
|
19
|
+
|
20
|
+
# Your merchant must have operators, to test prefix your merchant name with TEST
|
21
|
+
gateway = ActiveMerchant::Billing::AnzGateway.new(
|
22
|
+
:merchant_id => 'TESTANZMURCONREG',
|
23
|
+
:access_code => '31C43EF3'
|
24
|
+
)
|
25
|
+
|
26
|
+
# ANZ only require the card number, month and year
|
27
|
+
card = ActiveMerchant::Billing::CreditCard.new(
|
28
|
+
:number => '5123456789012346',
|
29
|
+
:month => 5,
|
30
|
+
:year => 2013
|
31
|
+
)
|
32
|
+
|
33
|
+
params = {
|
34
|
+
:order_id => 'X123F',
|
35
|
+
:invoice => '10001'
|
36
|
+
}
|
37
|
+
|
38
|
+
# $10 puchase
|
39
|
+
result = gateway.purchase(1000, card, params)
|
40
|
+
|
41
|
+
Other Features
|
42
|
+
|
43
|
+
There are features for refuding/crediting and querying past records, however these are missing tests and I can't vouch for them.
|
44
|
+
|
45
|
+
You can manage your anz merchant account over at https://migs.mastercard.com.au/ma
|
46
|
+
|
47
|
+
## Testing
|
48
|
+
|
49
|
+
Anz seem to have removed their public testing profile, I've instead set the fixtures to come from environment variables
|
50
|
+
|
51
|
+
export ANZ_MERCHANT=TESTyoumerchantname
|
52
|
+
export ANZ_CODE=youroperatorcode
|
53
|
+
|
54
|
+
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.
|
55
|
+
|
56
|
+
## Acknowledgements
|
57
|
+
|
58
|
+
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).
|
59
|
+
|
60
|
+
# LICENCE
|
61
|
+
|
62
|
+
Licenced under MIT Copyright 2009 by Anuj Luthra, for details see LICENCE
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path("../lib/active_merchant-anz/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = "activemerchant-anz-gateway"
|
6
|
+
s.version = ActiveMerchant::Anz::VERSION
|
7
|
+
s.authors = ["Anuj Luthra", "Dirk Kelly"]
|
8
|
+
s.email = ["anuj.luthra@gmail.com", "dk@dirkkelly.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{Gateway for ANZ and ActiveMerchant}
|
11
|
+
s.description = %q{Provides an interface to ANZ for the Activemerchant library, fork of github@anujluthra's work}
|
12
|
+
|
13
|
+
s.rubyforge_project = "activemerchant-anz-gateway"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "test-unit"
|
22
|
+
s.add_development_dependency "mocha"
|
23
|
+
|
24
|
+
s.add_runtime_dependency "activemerchant"
|
25
|
+
s.add_runtime_dependency "activesupport"
|
26
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_merchant'
|
2
|
+
require 'active_merchant/billing'
|
3
|
+
require 'active_support/core_ext/object'
|
4
|
+
|
5
|
+
require "active_merchant-anz/version"
|
6
|
+
require "active_merchant/billing/gateways/anz"
|
7
|
+
|
8
|
+
|
9
|
+
module ActiveMerchant
|
10
|
+
module Anz
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'active_merchant'
|
3
|
+
require 'active_merchant/billing'
|
4
|
+
|
5
|
+
module ActiveMerchant #:nodoc:
|
6
|
+
module Billing #:nodoc:
|
7
|
+
class AnzGateway < Gateway
|
8
|
+
|
9
|
+
undef_method :capture
|
10
|
+
|
11
|
+
self.supported_countries = ['AU']
|
12
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
|
13
|
+
self.money_format = :cents
|
14
|
+
self.homepage_url = 'http://www.anz.com.au'
|
15
|
+
self.display_name = 'ANZ eGate'
|
16
|
+
GATEWAY_URL = "https://migs.mastercard.com.au/vpcdps"
|
17
|
+
VIRTUAL_PAYMENT_CLIENT_API_VERION = 1
|
18
|
+
|
19
|
+
def initialize(options={})
|
20
|
+
requires!(options, :merchant_id, :access_code)
|
21
|
+
if options[:mode] && (options[:mode].to_sym == :production || options[:mode].to_sym == :test)
|
22
|
+
self.mode = options[:mode]
|
23
|
+
end
|
24
|
+
@options = options
|
25
|
+
super
|
26
|
+
end
|
27
|
+
|
28
|
+
########################################################
|
29
|
+
# allowed operations for mastercard migs virtual gateway
|
30
|
+
########################################################
|
31
|
+
|
32
|
+
#actual payment
|
33
|
+
def purchase(money, creditcard, options = {})
|
34
|
+
requires!(options, :invoice, :order_id)
|
35
|
+
params = {}
|
36
|
+
add_credit_card(params, creditcard)
|
37
|
+
add_merchant_transaction_id(params, options[:order_id])
|
38
|
+
add_invoice_number(params, options[:invoice])
|
39
|
+
add_amount(params, money)
|
40
|
+
process_action('pay', params)
|
41
|
+
end
|
42
|
+
|
43
|
+
###############################################################
|
44
|
+
## Next two operations require a AMA username and AMA password
|
45
|
+
|
46
|
+
#refunds to the customer's card. autorization id is required
|
47
|
+
def credit(money, authorization_number, options = {})
|
48
|
+
requires!(options, :username, :password, :order_id)
|
49
|
+
params = {}
|
50
|
+
add_merchant_transaction_id(params, options[:order_id])
|
51
|
+
add_authorization_number(params, authorization_number)
|
52
|
+
add_username_password(params, options[:username], options[:password])
|
53
|
+
add_amount(params, money)
|
54
|
+
process_action('refund', params)
|
55
|
+
end
|
56
|
+
|
57
|
+
#query a past payment, unique merchant transaction ref. is required
|
58
|
+
def query(merchant_transaction_id)
|
59
|
+
params = {}
|
60
|
+
add_merchant_transaction_id(params, merchant_transaction_id)
|
61
|
+
process_action('QueryDR', params)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
#########################################################
|
66
|
+
#methods to beautify and prepare the params before handing over to bank
|
67
|
+
#########################################################
|
68
|
+
|
69
|
+
def process_action(action, params)
|
70
|
+
payment_params = post_data(action, params)
|
71
|
+
response = ssl_post GATEWAY_URL, payment_params
|
72
|
+
build_response(response)
|
73
|
+
end
|
74
|
+
|
75
|
+
#ADDS
|
76
|
+
#
|
77
|
+
#
|
78
|
+
def post_data(action, params)
|
79
|
+
return params.merge(:vpc_Version => VIRTUAL_PAYMENT_CLIENT_API_VERION,
|
80
|
+
:vpc_AccessCode => @options[:access_code],
|
81
|
+
:vpc_Merchant => @options[:merchant_id],
|
82
|
+
:vpc_Command => action).to_query
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_invoice_number(params, invoice_number)
|
86
|
+
return params.merge!(:vpc_TicketNo => invoice_number,
|
87
|
+
:vpc_OrderInfo => invoice_number)
|
88
|
+
end
|
89
|
+
|
90
|
+
def add_credit_card(params, creditcard)
|
91
|
+
expiry = "#{creditcard.year.to_s[-2,2]}#{sprintf("%.2i", creditcard.month)}"
|
92
|
+
return params.merge!(:vpc_CardNum => creditcard.number,
|
93
|
+
:vpc_CardSecurityCode => creditcard.verification_value,
|
94
|
+
:vpc_CardExp => "#{expiry}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def add_amount(params, money)
|
98
|
+
params[:vpc_Amount] = money.to_i
|
99
|
+
end
|
100
|
+
|
101
|
+
#ADDS THE AUTHORIZATION NUMBER OF A PREVIOUS TRANSACTION
|
102
|
+
#IN THE REQUEST PARAMS. THIS IS MOSTLY USED IN A REFUND
|
103
|
+
#OR A QUERY FOR A PREVIOUSLY PERFORMED TRANSACTION
|
104
|
+
def add_authorization_number(params, authorization)
|
105
|
+
return params.merge!(:vpc_TransactionNo => authorization)
|
106
|
+
end
|
107
|
+
|
108
|
+
#ADDS A UNIQUE ID(can be alpanumeric) TO THE PARAMS LIST.
|
109
|
+
#EVERY TRANSACTION SENT TO BANKING GATEWAY SHOULD HAVE A
|
110
|
+
#UNIQUE IDENTIFICATION NUMBER. THIS HELPS IN TRACING THE
|
111
|
+
#TRANSACTION IN CASE OF QUERIES AND AUDITS. THIS IS A REQUIRED
|
112
|
+
#FIELD IN EVERY REQUEST SENT TO GATEWAY.
|
113
|
+
def add_merchant_transaction_id(params, transaction_id)
|
114
|
+
return params.merge!(:vpc_MerchTxnRef => transaction_id)
|
115
|
+
end
|
116
|
+
|
117
|
+
#USED FOR REFUNDS AND QUERYING THE GATEWAY. NEED THE
|
118
|
+
#MA USERNAME AND PASSWORD REQUIRED. THESE ARE SUPPLIED
|
119
|
+
#BY THE BANKING AUTHORITY.
|
120
|
+
def add_username_password(params, username, password)
|
121
|
+
return params.merge!(:vpc_User => username,
|
122
|
+
:vpc_Password => password)
|
123
|
+
end
|
124
|
+
|
125
|
+
def build_response(response_str)
|
126
|
+
response = parse(response_str)
|
127
|
+
authorization = response['vpc_TransactionNo']
|
128
|
+
success = (response['vpc_TxnResponseCode'] == '0')
|
129
|
+
message = CGI.unescape(response['vpc_Message'])
|
130
|
+
Response.new(success, message, response, :authorization => authorization, :test => test?)
|
131
|
+
end
|
132
|
+
|
133
|
+
def parse(html_encoded_url)
|
134
|
+
params = CGI::parse(html_encoded_url)
|
135
|
+
hash = {}
|
136
|
+
params.each do|key, value|
|
137
|
+
hash[key] = value[0]
|
138
|
+
end
|
139
|
+
hash
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'active_merchant-anz'
|
data/test/fixtures.yml
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path('../../test_helper',File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class AnzTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@gateway = AnzGateway.new(fixtures(:anz))
|
6
|
+
|
7
|
+
@credit_card_success = credit_card('5123456789012346',
|
8
|
+
:month => 5,
|
9
|
+
:year => 2013
|
10
|
+
)
|
11
|
+
|
12
|
+
@credit_card_fail = credit_card('1234567812345678',
|
13
|
+
:month => Time.now.month,
|
14
|
+
:year => Time.now.year
|
15
|
+
)
|
16
|
+
|
17
|
+
@params = {
|
18
|
+
:order_id => 'X123F',
|
19
|
+
:invoice => '10001'
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_invalid_amount
|
24
|
+
assert response = @gateway.purchase(0, @credit_card_success, @params)
|
25
|
+
assert_failure response
|
26
|
+
assert response.test?
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_purchase_success_with_verification_value
|
30
|
+
assert response = @gateway.purchase(100, @credit_card_success, @params)
|
31
|
+
assert_success response
|
32
|
+
assert response.test?
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_invalid_expiration_date
|
36
|
+
@credit_card_success.year = 2005
|
37
|
+
assert response = @gateway.purchase(100, @credit_card_success, @params)
|
38
|
+
assert_failure response
|
39
|
+
assert response.test?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_purchase_error
|
43
|
+
assert response = @gateway.purchase(100, @credit_card_fail, @params)
|
44
|
+
assert_equal false, response.success?
|
45
|
+
assert response.test?
|
46
|
+
end
|
47
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup
|
5
|
+
rescue LoadError => e
|
6
|
+
puts "Error loading bundler (#{e.message}): \"gem install bundler\" for bundler support."
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
require 'test/unit'
|
11
|
+
require 'mocha'
|
12
|
+
require 'erb'
|
13
|
+
require 'activemerchant-anz-gateway'
|
14
|
+
|
15
|
+
ActiveMerchant::Billing::Base.mode = :test
|
16
|
+
|
17
|
+
class AnzGateway < ActiveMerchant::Billing::AnzGateway
|
18
|
+
end
|
19
|
+
|
20
|
+
module ActiveMerchant
|
21
|
+
module Assertions
|
22
|
+
AssertionClass = Test::Unit::AssertionFailedError
|
23
|
+
|
24
|
+
def assert_field(field, value)
|
25
|
+
clean_backtrace do
|
26
|
+
assert_equal value, @helper.fields[field]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Allows the testing of you to check for negative assertions:
|
31
|
+
#
|
32
|
+
# # Instead of
|
33
|
+
# assert !something_that_is_false
|
34
|
+
#
|
35
|
+
# # Do this
|
36
|
+
# assert_false something_that_should_be_false
|
37
|
+
#
|
38
|
+
# An optional +msg+ parameter is available to help you debug.
|
39
|
+
def assert_false(boolean, message = nil)
|
40
|
+
message = build_message message, '<?> is not false or nil.', boolean
|
41
|
+
|
42
|
+
clean_backtrace do
|
43
|
+
assert_block message do
|
44
|
+
not boolean
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# A handy little assertion to check for a successful response:
|
50
|
+
#
|
51
|
+
# # Instead of
|
52
|
+
# assert_success response
|
53
|
+
#
|
54
|
+
# # DRY that up with
|
55
|
+
# assert_success response
|
56
|
+
#
|
57
|
+
# A message will automatically show the inspection of the response
|
58
|
+
# object if things go afoul.
|
59
|
+
def assert_success(response)
|
60
|
+
clean_backtrace do
|
61
|
+
assert response.success?, "Response failed: #{response.inspect}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# The negative of +assert_success+
|
66
|
+
def assert_failure(response)
|
67
|
+
clean_backtrace do
|
68
|
+
assert_false response.success?, "Response expected to fail: #{response.inspect}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def assert_valid(validateable)
|
73
|
+
clean_backtrace do
|
74
|
+
assert validateable.valid?, "Expected to be valid"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def assert_not_valid(validateable)
|
79
|
+
clean_backtrace do
|
80
|
+
assert_false validateable.valid?, "Expected to not be valid"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def assert_deprecation_warning(message, target)
|
85
|
+
target.expects(:deprecated).with(message)
|
86
|
+
yield
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def clean_backtrace(&block)
|
91
|
+
yield
|
92
|
+
rescue AssertionClass => e
|
93
|
+
path = File.expand_path(__FILE__)
|
94
|
+
raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
module Fixtures
|
99
|
+
HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
|
100
|
+
LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
|
101
|
+
DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
|
102
|
+
|
103
|
+
private
|
104
|
+
def credit_card(number = '4242424242424242', options = {})
|
105
|
+
defaults = {
|
106
|
+
:number => number,
|
107
|
+
:month => 9,
|
108
|
+
:year => Time.now.year + 1,
|
109
|
+
:first_name => 'Longbob',
|
110
|
+
:last_name => 'Longsen',
|
111
|
+
:verification_value => '123',
|
112
|
+
:type => 'visa'
|
113
|
+
}.update(options)
|
114
|
+
|
115
|
+
Billing::CreditCard.new(defaults)
|
116
|
+
end
|
117
|
+
|
118
|
+
def check(options = {})
|
119
|
+
defaults = {
|
120
|
+
:name => 'Jim Smith',
|
121
|
+
:routing_number => '244183602',
|
122
|
+
:account_number => '15378535',
|
123
|
+
:account_holder_type => 'personal',
|
124
|
+
:account_type => 'checking',
|
125
|
+
:number => '1'
|
126
|
+
}.update(options)
|
127
|
+
|
128
|
+
Billing::Check.new(defaults)
|
129
|
+
end
|
130
|
+
|
131
|
+
def address(options = {})
|
132
|
+
{
|
133
|
+
:name => 'Jim Smith',
|
134
|
+
:address1 => '1234 My Street',
|
135
|
+
:address2 => 'Apt 1',
|
136
|
+
:company => 'Widgets Inc',
|
137
|
+
:city => 'Ottawa',
|
138
|
+
:state => 'ON',
|
139
|
+
:zip => 'K1C2N6',
|
140
|
+
:country => 'CA',
|
141
|
+
:phone => '(555)555-5555',
|
142
|
+
:fax => '(555)555-6666'
|
143
|
+
}.update(options)
|
144
|
+
end
|
145
|
+
|
146
|
+
def all_fixtures
|
147
|
+
@@fixtures ||= load_fixtures
|
148
|
+
end
|
149
|
+
|
150
|
+
def fixtures(key)
|
151
|
+
data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
|
152
|
+
|
153
|
+
data.dup
|
154
|
+
end
|
155
|
+
|
156
|
+
def load_fixtures
|
157
|
+
file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
|
158
|
+
yaml_data = YAML.load(ERB.new(File.read(file)).result)
|
159
|
+
symbolize_keys(yaml_data)
|
160
|
+
|
161
|
+
yaml_data
|
162
|
+
end
|
163
|
+
|
164
|
+
def symbolize_keys(hash)
|
165
|
+
return unless hash.is_a?(Hash)
|
166
|
+
|
167
|
+
hash.symbolize_keys!
|
168
|
+
hash.each{|k,v| symbolize_keys(v)}
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
Test::Unit::TestCase.class_eval do
|
174
|
+
include ActiveMerchant::Billing
|
175
|
+
include ActiveMerchant::Assertions
|
176
|
+
include ActiveMerchant::Utils
|
177
|
+
include ActiveMerchant::Fixtures
|
178
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require File.expand_path('../../test_helper',File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class AnzTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
@gateway = AnzGateway.new(fixtures(:anz))
|
6
|
+
|
7
|
+
@credit_card_success = credit_card('5123456789012346',
|
8
|
+
:month => 5,
|
9
|
+
:year => 2013
|
10
|
+
)
|
11
|
+
|
12
|
+
@credit_card_fail = credit_card('1234567812345678',
|
13
|
+
:month => Time.now.month,
|
14
|
+
:year => Time.now.year
|
15
|
+
)
|
16
|
+
|
17
|
+
@options = {
|
18
|
+
:order_id => 'X123F',
|
19
|
+
:invoice => '10001',
|
20
|
+
}
|
21
|
+
|
22
|
+
@amount = 100
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_successful_purchase
|
26
|
+
@gateway.expects(:ssl_post).returns(successful_purchase_response)
|
27
|
+
|
28
|
+
assert response = @gateway.purchase(@amount, @credit_card_success, @options)
|
29
|
+
assert_instance_of Response, response
|
30
|
+
assert_success response
|
31
|
+
assert !response.authorization.blank?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_failed_purchase
|
35
|
+
@gateway.expects(:ssl_post).returns(failed_purchase_response)
|
36
|
+
|
37
|
+
assert response = @gateway.purchase(@amount, @credit_card_fail, @options)
|
38
|
+
assert_instance_of Response, response
|
39
|
+
assert_failure response
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_amount_style
|
43
|
+
assert_equal '1034', @gateway.send(:amount, 1034)
|
44
|
+
|
45
|
+
assert_raise(ArgumentError) do
|
46
|
+
@gateway.send(:amount, '10.34')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_ensure_does_not_respond_to_authorize
|
51
|
+
assert !@gateway.respond_to?(:authorize)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_ensure_does_not_respond_to_capture
|
55
|
+
assert !@gateway.respond_to?(:capture)
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def successful_purchase_response
|
60
|
+
"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"
|
61
|
+
end
|
62
|
+
|
63
|
+
def failed_purchase_response
|
64
|
+
"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"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activemerchant-anz-gateway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anuj Luthra
|
9
|
+
- Dirk Kelly
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-10-18 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: test-unit
|
17
|
+
requirement: &70343403500900 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70343403500900
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: mocha
|
28
|
+
requirement: &70343403500360 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70343403500360
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activemerchant
|
39
|
+
requirement: &70343403499820 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70343403499820
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activesupport
|
50
|
+
requirement: &70343403499280 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70343403499280
|
59
|
+
description: Provides an interface to ANZ for the Activemerchant library, fork of
|
60
|
+
github@anujluthra's work
|
61
|
+
email:
|
62
|
+
- anuj.luthra@gmail.com
|
63
|
+
- dk@dirkkelly.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- LICENCE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- activemerchant-anz-gateway.gemspec
|
74
|
+
- lib/active_merchant-anz.rb
|
75
|
+
- lib/active_merchant-anz/version.rb
|
76
|
+
- lib/active_merchant/billing/gateways/anz.rb
|
77
|
+
- lib/activemerchant-anz-gateway.rb
|
78
|
+
- test/fixtures.yml
|
79
|
+
- test/remote/gateways/remote_anz_test.rb
|
80
|
+
- test/test_helper.rb
|
81
|
+
- test/unit/gateways/anz_test.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project: activemerchant-anz-gateway
|
102
|
+
rubygems_version: 1.8.6
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Gateway for ANZ and ActiveMerchant
|
106
|
+
test_files: []
|