lib/active_merchant/billing/gateways/data_cash.rb in activemerchant-1.1.0 vs lib/active_merchant/billing/gateways/data_cash.rb in activemerchant-1.2.0

- old
+ new

@@ -1,17 +1,24 @@ # Author:: MoneySpyder, http://moneyspyder.co.uk module ActiveMerchant module Billing - # ActiveMerchant Datacash Gateway - # - # Datacash allows a policy for CV2 checks. There is currently no way - # to modify this programatically. The policy may be changed in the - # add_credit_card method. - # class DataCashGateway < Gateway + self.default_currency = 'GBP' + self.supported_countries = ['GB'] + # From the DataCash docs; Page 13, the following cards are + # usable: + # American Express, ATM, Carte Blanche, Diners Club, Discover, + # EnRoute, GE Capital, JCB, Laser, Maestro, Mastercard, Solo, + # Switch, Visa, Visa Delta, VISA Electron, Visa Purchasing + self.supported_cardtypes = [ :visa, :master, :american_express, :discover, :diners_club, :jcb, + :maestro, :switch, :solo, :laser ] + + self.homepage_url = 'http://www.datacash.com/' + self.display_name = 'DataCash' + # Datacash server URLs TEST_URL = 'https://testserver.datacash.com/Transaction' LIVE_URL = 'https://mars.transaction.datacash.com/Transaction' # Different Card Transaction Types @@ -23,144 +30,94 @@ # Constant strings for use in the ExtendedPolicy complex element for # CV2 checks POLICY_ACCEPT = 'accept' POLICY_REJECT = 'reject' - #Datacash success code + # Datacash success code DATACASH_SUCCESS = '1' # Class attributes attr_reader :url attr_reader :response attr_reader :options - # Create a new DataCashGateway + # Creates a new DataCashGateway # - # The gateway requires that a valid :login and :password be passed - # in the options hash + # The gateway requires that a valid login and password be passed + # in the +options+ hash. # - # Parameters: - # -options: - # :login - the Datacash account login - # :password - the Datacash account password - # :test - boolean, use the test or live Datacash url + # ==== Options + # + # * <tt>:login</tt> -- The Datacash account login. + # * <tt>:password</tt> -- The Datacash account password. + # * <tt>:test => +true+ or +false+</tt> -- Use the test or live Datacash url. # def initialize(options = {}) requires!(options, :login, :password) @options = options super end - # Purchase the item straight away + # Perform a purchase, which is essentially an authorization and capture in a single operation. # - # Parameters: - # -money: Money object for the total to be charged - # -credit_card: ActiveMerchant::Billing::CreditCard details for the transaction - # -options: + # ==== Parameters # - # Returns: - # -ActiveRecord::Billing::Response object - # + # * <tt>money</tt> -- The amount to be purchased. Either an Integer value in cents or a Money object. + # * <tt>credit_card</tt> -- The CreditCard details for the transaction. + # * <tt>options</tt> -- A hash of optional parameters. def purchase(money, credit_card, options = {}) if result = test_result_from_cc_number(credit_card.number) return result end request = build_purchase_or_authorization_request(AUTH_TYPE, money, credit_card, options) commit(request) end - # Authorize the transaction - # - # Reserves the funds on the customer's credit card, but does not + # Performs an authorization, which reserves the funds on the customer's credit card, but does not # charge the card. # - # Parameters: - # -money: Money object for the total to be charged - # -credit_card: ActiveMerchant::Billing::CreditCard details for the transaction - # -options: + # ==== Parameters # - # Returns: - # -ActiveRecord::Billing::Response object - # + # * <tt>money</tt> -- The amount to be authorized. Either an Integer value in cents or a Money object. + # * <tt>credit_card</tt> -- The CreditCard details for the transaction. + # * <tt>options</tt> -- A hash of optional parameters. def authorize(money, credit_card, options = {}) if result = test_result_from_cc_number(credit_card.number) return result end request = build_purchase_or_authorization_request(PRE_TYPE, money, credit_card, options) commit(request) end - # Datacash requires both the reference and the authcode of the original - # authorization. To maintain the same interface as the other - # gateways the two numbers are concatenated together with an ; separator as - # the authorization number returned by authorization - - # Captures the funds from an authorized transaction. - # authorization must be a valid Datacash reference and :authcode must be - # a valid Datacash authcode from a prior authorized transaction. + # Captures the funds from an authorized transaction. # - # This needs to create a 'historic txn' to fulfill - # - # Parameters: - # -money: Money object for the total to be charged - # -authorization: the Datacash reference and authcode from the previous authorization + # ==== Parameters # - # Returns: - # -ActiveRecord::Billing::Response object - # + # * <tt>money</tt> -- The amount to be captured. Either an Integer value in cents or a Money object. + # * <tt>authorization</tt> -- The authorization returned from the previous authorize request. def capture(money, authorization, options = {}) request = build_void_or_capture_request(FULFILL_TYPE, money, authorization, options) commit(request) end # Void a previous transaction # - # This needs to create a 'historic txn' to fulfil - # - # Parameters: - # -authorization: the Datacash reference from the previous authorization + # ==== Parameters # - # Returns: - # -ActiveRecord::Billing::Response object - # + # * <tt>authorization</tt> - The authorization returned from the previous authorize request. def void(authorization, options = {}) request = build_void_or_capture_request(CANCEL_TYPE, nil, authorization, options) commit(request) end - # From the DataCash docs; Page 13, the following cards are - # usable - # - # American Express, ATM, Carte Blanche, Diners Club, Discover, - # EnRoute, GE Capital, JCB, Laser, Maestro, Mastercard, Solo, - # Switch, Unknown, Visa, Visa Delta, VISA Electron, Visa Purchasing - # - # Parameters: - # -none - # - # Returns: - # -the list of all supported cards - # - def self.supported_cardtypes - [ :visa, :master, :american_express, :discover, :diners_club, :jcb, - :switch, :solo ] - end - - # Return whether or not the gateway is in test mode - # - # Parameters: - # -none - # - # Returns: - # -boolean - # + # Is the gateway running in test mode? def test? @options[:test] || Base.gateway_mode == :test end private @@ -211,11 +168,11 @@ end if money xml.tag! :TxnDetails do xml.tag! :merchantreference, format_reference_number(options[:order_id]) - xml.tag! :amount, amount(money), :currency => currency(money) + xml.tag! :amount, amount(money), :currency => options[:currency] || currency(money) end end end end xml.target! @@ -294,11 +251,11 @@ add_credit_card(xml, credit_card, options[:billing_address] || options[:address]) end xml.tag! :TxnDetails do xml.tag! :merchantreference, format_reference_number(options[:order_id]) - xml.tag! :amount, amount(money), :currency => currency(money) + xml.tag! :amount, amount(money), :currency => options[:currency] || currency(money) end end end xml.target! end @@ -400,22 +357,9 @@ Response.new(success, message, @response, :test => test?, :authorization => "#{@response[:datacash_reference]};#{@response[:authcode]}" ) - end - - # Find the currency of the Money object passed - # - # Parameters: - # -money: The money object that we are looking at - # - # Returns: - # -string: The three digit currency code (These are - # ISO 4217 codes) - # - def currency(money) - money.respond_to?(:currency) ? money.currency : 'GBP' end # Returns a date string in the format Datacash expects # # Parameters: