Permalink
Browse files

Update project to use Rubigen

git-svn-id: https://activemerchant.googlecode.com/svn/trunk/active_merchant@484 6513ea26-6c20-0410-8a68-89cd7235086d
  • Loading branch information...
1 parent 301168e commit 4948e15d7dcd11ce9099e5ca01417f81f8ad99a8 codyfauser committed Nov 30, 2007
View
@@ -1,5 +1,7 @@
# CHANGELOG
# ---
+# * Update product to use Rubigen instead of stolen Rails generator [cody]
+#
# * Mimic directory structure of unit tests in remote tests [cody]
#
# * Restructure the location of the remote tests [cody]
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
@@ -0,0 +1,61 @@
+class GatewayGenerator < RubiGen::Base
+ LIB_DIR = "lib/active_merchant/billing/gateways/"
+ UNIT_TEST_DIR = "test/unit/gateways/"
+ REMOTE_TEST_DIR = "test/remote/gateways/"
+
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.length < 1
+ @name = args.shift
+ extract_options
+ end
+
+ def class_name
+ @name.classify
+ end
+
+ def manifest
+ record do |m|
+
+ m.directory LIB_DIR
+ m.directory UNIT_TEST_DIR
+ m.directory REMOTE_TEST_DIR
+
+ m.template 'gateway.rb', LIB_DIR + "#{name}.rb"
+ m.template 'gateway_test.rb', UNIT_TEST_DIR + "#{name}_test.rb"
+ m.template 'remote_gateway_test.rb', REMOTE_TEST_DIR + "remote_#{name}_test.rb"
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name"
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |options[:author]| }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
@@ -0,0 +1,73 @@
+module ActiveMerchant #:nodoc:
+ module Billing #:nodoc:
+ class <%= class_name %>Gateway < Gateway
+ TEST_URL = 'https://example.com/test'
+ LIVE_URL = 'https://example.com/live'
+
+ attr_reader :url
+ attr_reader :response
+ attr_reader :options
+
+ def initialize(options = {})
+ #requires!(options, :login, :password)
+ @options = options
+ super
+ end
+
+ def authorize(money, creditcard, options = {})
+ post = {}
+ add_invoice(post, options)
+ add_creditcard(post, creditcard)
+ add_address(post, creditcard, options)
+ add_customer_data(post, options)
+
+ commit('authonly', money, post)
+ end
+
+ def purchase(money, creditcard, options = {})
+ post = {}
+ add_invoice(post, options)
+ add_creditcard(post, creditcard)
+ add_address(post, creditcard, options)
+ add_customer_data(post, options)
+
+ commit('sale', money, post)
+ end
+
+ def capture(money, authorization, options = {})
+ commit('capture', money, post)
+ end
+
+ def self.supported_cardtypes
+ [:visa, :master, :american_express]
+ end
+
+ private
+
+ def add_customer_data(post, options)
+ end
+
+ def add_address(post, creditcard, options)
+ end
+
+ def add_invoice(post, options)
+ end
+
+ def add_creditcard(post, creditcard)
+ end
+
+ def parse(body)
+ end
+
+ def commit(action, money, parameters)
+ end
+
+ def message_from(response)
+ end
+
+ def post_data(action, parameters = {})
+ end
+ end
+ end
+end
+
@@ -0,0 +1,44 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+
+class <%= class_name %>Test < Test::Unit::TestCase
+ AMOUNT = 100
+
+ def setup
+ @gateway = <%= class_name %>Gateway.new(
+ :login => 'login',
+ :password => 'password'
+ )
+
+ @creditcard = credit_card('4242424242424242')
+
+ @address = { :address1 => '1234 My Street',
+ :address2 => 'Apt 1',
+ :company => 'Widgets Inc',
+ :city => 'Ottawa',
+ :state => 'ON',
+ :zip => 'K1C2N6',
+ :country => 'Canada',
+ :phone => '(555)555-5555'
+ }
+ end
+
+ def test_successful_request
+ @creditcard.number = 1
+ assert response = @gateway.purchase(AMOUNT, @creditcard, {})
+ assert_success response
+ assert_equal '5555', response.authorization
+ assert response.test?
+ end
+
+ def test_unsuccessful_request
+ @creditcard.number = 2
+ assert response = @gateway.purchase(AMOUNT, @creditcard, {})
+ assert_failure response
+ assert response.test?
+ end
+
+ def test_request_error
+ @creditcard.number = 3
+ assert_raise(Error){ @gateway.purchase(AMOUNT, @creditcard, {}) }
+ end
+end
@@ -0,0 +1,56 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class Remote<%= class_name %>Test < Test::Unit::TestCase
+ AMOUNT = 100
+
+ def setup
+ @gateway = <%= class_name %>Gateway.new(fixtures(:<%= class_name.underscore %>))
+
+ @creditcard = credit_card('4000100011112224')
+
+ @declined_card = credit_card('4000300011112220')
+
+ @options = { :address => { :address1 => '1234 Shady Brook Lane',
+ :zip => '90210'
+ }
+ }
+ end
+
+ def test_successful_purchase
+ assert response = @gateway.purchase(AMOUNT, @creditcard, @options)
+ assert_equal 'REPLACE WITH SUCCESS MESSAGE', response.message
+ assert_success response
+ end
+
+ def test_unsuccessful_purchase
+ assert response = @gateway.purchase(AMOUNT, @declined_card, @options)
+ assert_equal 'REPLACE WITH FAILED PURCHASE MESSAGE', response.message
+ assert_failure response
+ end
+
+ def test_authorize_and_capture
+ amount = AMOUNT
+ assert auth = @gateway.authorize(amount, @creditcard, @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 = <%= class_name %>Gateway.new({
+ :login => '',
+ :password => ''
+ })
+ assert response = gateway.purchase(AMOUNT, @creditcard, @options)
+ assert_equal 'REPLACE WITH FAILURE MESSAGE', response.message
+ assert_failure response
+ end
+end
@@ -0,0 +1,5 @@
+Description:
+
+
+Usage:
+
@@ -0,0 +1,68 @@
+class IntegrationGenerator < RubiGen::Base
+ BASE_DIR = "lib/active_merchant/billing/integrations/"
+ TEST_DIR = "test/unit/integrations/"
+
+ default_options :author => nil
+
+ attr_reader :name
+
+ def initialize(runtime_args, runtime_options = {})
+ super
+ usage if args.size < 1
+ @name = args.shift
+ extract_options
+ end
+
+ def class_name
+ name.classify
+ end
+
+ def lib_dir
+ BASE_DIR + name
+ end
+
+ def manifest
+ record do |m|
+ # Ensure appropriate folder(s) exists
+ m.directory lib_dir
+ m.directory TEST_DIR
+ m.directory TEST_DIR + "helpers"
+ m.directory TEST_DIR + "notifications"
+
+ m.template 'integration.rb', "#{lib_dir}.rb"
+ m.template 'helper.rb', lib_dir + "/helper.rb"
+ m.template 'notification.rb', lib_dir + "/notification.rb"
+
+ m.template 'module_test.rb', TEST_DIR + "#{name}_module_test.rb"
+ m.template 'helper_test.rb', TEST_DIR + "helpers/#{name}_helper_test.rb"
+ m.template 'notification_test.rb', TEST_DIR + "notifications/#{name}_notification_test.rb"
+ end
+ end
+
+ protected
+ def banner
+ <<-EOS
+Creates a ...
+
+USAGE: #{$0} #{spec.name} name"
+EOS
+ end
+
+ def add_options!(opts)
+ # opts.separator ''
+ # opts.separator 'Options:'
+ # For each option below, place the default
+ # at the top of the file next to "default_options"
+ # opts.on("-a", "--author=\"Your Name\"", String,
+ # "Some comment about this option",
+ # "Default: none") { |options[:author]| }
+ # opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
+ end
+
+ def extract_options
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
+ # Templates can access these value via the attr_reader-generated methods, but not the
+ # raw instance variable value.
+ # @author = options[:author]
+ end
+end
@@ -0,0 +1,34 @@
+module ActiveMerchant #:nodoc:
+ module Billing #:nodoc:
+ module Integrations #:nodoc:
+ module <%= class_name %>
+ class Helper < ActiveMerchant::Billing::Integrations::Helper
+ # Replace with the real mapping
+ mapping :account, ''
+ mapping :amount, ''
+
+ mapping :order, ''
+
+ mapping :customer, :first_name => '',
+ :last_name => '',
+ :email => '',
+ :phone => ''
+
+ mapping :billing_address, :city => '',
+ :address1 => '',
+ :address2 => '',
+ :state => '',
+ :zip => '',
+ :country => ''
+
+ mapping :notify_url, ''
+ mapping :return_url, ''
+ mapping :cancel_return_url, ''
+ mapping :description, ''
+ mapping :tax, ''
+ mapping :shipping, ''
+ end
+ end
+ end
+ end
+end
Oops, something went wrong.

0 comments on commit 4948e15

Please sign in to comment.