lib/active_merchant/billing/gateway.rb in activemerchant-1.43.3 vs lib/active_merchant/billing/gateway.rb in activemerchant-1.44.0

- old
+ new

@@ -8,23 +8,20 @@ # == Description # The Gateway class is the base class for all ActiveMerchant gateway implementations. # # The standard list of gateway functions that most concrete gateway subclasses implement is: # - # * <tt>purchase(money, creditcard, options = {})</tt> - # * <tt>authorize(money, creditcard, options = {})</tt> + # * <tt>purchase(money, credit_card, options = {})</tt> + # * <tt>authorize(money, credit_card, options = {})</tt> # * <tt>capture(money, authorization, options = {})</tt> # * <tt>void(identification, options = {})</tt> - # * <tt>credit(money, identification, options = {})</tt> + # * <tt>refund(money, identification, options = {})</tt> + # * <tt>verify(credit_card, options = {})</tt> # - # Some gateways include features for recurring billing - # - # * <tt>recurring(money, creditcard, options = {})</tt> - # # Some gateways also support features for storing credit cards: # - # * <tt>store(creditcard, options = {})</tt> + # * <tt>store(credit_card, options = {})</tt> # * <tt>unstore(identification, options = {})</tt> # # === Gateway Options # The options hash consists of the following options: # @@ -55,26 +52,29 @@ # # See the {ActiveMerchant Guide to Contributing}[https://github.com/Shopify/active_merchant/wiki/Contributing] # class Gateway include PostsData - include RequiresParameters include CreditCardFormatting - include Utils DEBIT_CARDS = [ :switch, :solo ] CURRENCIES_WITHOUT_FRACTIONS = [ 'BIF', 'BYR', 'CLP', 'CVE', 'DJF', 'GNF', 'HUF', 'ISK', 'JPY', 'KMF', 'KRW', 'PYG', 'RWF', 'TWD', 'UGX', 'VND', 'VUV', 'XAF', 'XOF', 'XPF' ] CREDIT_DEPRECATION_MESSAGE = "Support for using credit to refund existing transactions is deprecated and will be removed from a future release of ActiveMerchant. Please use the refund method instead." + RECURRING_DEPRECATION_MESSAGE = "Recurring functionality in ActiveMerchant is deprecated and will be removed in a future version. Please contact the ActiveMerchant maintainers if you have an interest in taking ownership of a separate gem that continues support for it." cattr_reader :implementations @@implementations = [] def self.inherited(subclass) super @@implementations << subclass end + def generate_unique_id + SecureRandom.hex(16) + end + # The format of the amounts used by the gateway # :dollars => '12.50' # :cents => '1250' class_attribute :money_format self.money_format = :dollars @@ -144,20 +144,42 @@ # Are we running in test mode? def test? (@options.has_key?(:test) ? @options[:test] : Base.test?) end + protected # :nodoc: all + + def normalize(field) + case field + when "true" then true + when "false" then false + when "" then nil + when "null" then nil + else field + end + end + + def user_agent + @@ua ||= JSON.dump({ + :bindings_version => ActiveMerchant::VERSION, + :lang => 'ruby', + :lang_version => "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})", + :platform => RUBY_PLATFORM, + :publisher => 'active_merchant' + }) + end + private # :nodoc: all def name self.class.name.scan(/\:\:(\w+)Gateway/).flatten.first end def amount(money) return nil if money.nil? cents = if money.respond_to?(:cents) - deprecated "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents" + ActiveMerchant.deprecated "Support for Money objects is deprecated and will be removed from a future release of ActiveMerchant. Please use an Integer value in cents" money.cents else money end @@ -193,9 +215,22 @@ end def requires_start_date_or_issue_number?(credit_card) return false if card_brand(credit_card).blank? DEBIT_CARDS.include?(card_brand(credit_card).to_sym) + end + + def requires!(hash, *params) + params.each do |param| + if param.is_a?(Array) + raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first) + + valid_options = param[1..-1] + raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(:words_connector => 'or')}") unless valid_options.include?(hash[param.first]) + else + raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param) + end + end end end end end