Permalink
Browse files

merged with remote master, fixed up test_helper includes

  • Loading branch information...
Dirk Kelly
Dirk Kelly committed Oct 18, 2011
2 parents 24817a9 + c274eb9 commit 622426ce1369ee55d5bf6d743b8da46397548278
View
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
View
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in activemerchant-anz.gemspec
+gemspec
View
19 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.
View
14 README
@@ -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
View
@@ -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
View
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -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
View
@@ -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
@@ -0,0 +1,5 @@
+module ActiveMerchant
+ module Anz
+ VERSION = "0.1.0"
+ end
+end
@@ -1,16 +1,21 @@
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
self.homepage_url = 'http://www.anz.com.au'
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,58 +81,59 @@ 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']
success = (response['vpc_TxnResponseCode'] == '0')
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
@@ -0,0 +1 @@
+require 'active_merchant-anz'
Oops, something went wrong.

0 comments on commit 622426c

Please sign in to comment.