diff --git a/.travis.yml b/.travis.yml index 16a532e..2e792bf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,12 +22,7 @@ before_script: - git submodule update --remote --recursive script: - - bundle exec rake spec:ci - - bundle exec rake spec:aim - - bundle exec rake spec:api - - bundle exec rake spec:cim - - bundle exec rake spec:reporting - - bundle exec rake spec:testrunner + - bundle exec rake spec:testrunner env: global: diff --git a/authorizenet.gemspec b/authorizenet.gemspec index f6b7789..9aa47dd 100644 --- a/authorizenet.gemspec +++ b/authorizenet.gemspec @@ -1,8 +1,8 @@ Gem::Specification.new do |s| s.name = "authorizenet" - s.version = "1.9.7" + s.version = "2.0.0" s.platform = Gem::Platform::RUBY - s.date = "2018-12-05" + s.date = "2019-03-05" s.summary = "Authorize.Net Payments SDK" s.description = "Authorize.Net SDK includes standard payments, recurring billing, and customer profiles" s.authors = ["Authorize.Net"] diff --git a/lib/authorize_net.rb b/lib/authorize_net.rb index 2eaa003..a8b5b0a 100644 --- a/lib/authorize_net.rb +++ b/lib/authorize_net.rb @@ -19,67 +19,22 @@ $LOAD_PATH.unshift File.dirname(__FILE__) require "authorize_net/authorize_net" -require "authorize_net/payment_methods/credit_card" -require "authorize_net/payment_methods/echeck" -require "authorize_net/addresses/address" -require "authorize_net/addresses/shipping_address" -require "authorize_net/customer" -require "authorize_net/email_receipt" -require "authorize_net/order" -require "authorize_net/line_item" -require "authorize_net/cim/payment_profile" -require "authorize_net/cim/customer_profile" -require "authorize_net/reporting/batch" -require "authorize_net/reporting/batch_statistics" -require "authorize_net/reporting/transaction_details" -require "authorize_net/reporting/fds_filter" -require "authorize_net/reporting/returned_item" +# require "authorize_net/customer" +# require "authorize_net/email_receipt" +# require "authorize_net/order" +# require "authorize_net/line_item" require "authorize_net/response" -require "authorize_net/key_value_response" +# require "authorize_net/key_value_response" require "authorize_net/xml_response" require "authorize_net/transaction" -require "authorize_net/key_value_transaction" +# require "authorize_net/key_value_transaction" require "authorize_net/xml_transaction" -require "authorize_net/fields" - -# AIM - -require "authorize_net/aim/transaction" -require "authorize_net/aim/response" # API require "authorize_net/api/schema" require "authorize_net/api/api_transaction" require "authorize_net/api/transaction" -# SIM - -require "authorize_net/sim/hosted_payment_form" -require "authorize_net/sim/hosted_receipt_page" -require "authorize_net/sim/transaction" -require "authorize_net/sim/response" - -# ARB - -require "authorize_net/arb/paging" -require "authorize_net/arb/sorting" -require "authorize_net/arb/subscription_list_response" -require "authorize_net/arb/subscription_detail" -require "authorize_net/arb/fields" -require "authorize_net/arb/subscription" -require "authorize_net/arb/response" -require "authorize_net/arb/transaction" - -# CIM - -require "authorize_net/cim/response" -require "authorize_net/cim/transaction" - -# Reporting - -require "authorize_net/reporting/response" -require "authorize_net/reporting/transaction" - # Load our Rails plugin if defined?(Rails) diff --git a/lib/authorize_net/addresses/address.rb b/lib/authorize_net/addresses/address.rb deleted file mode 100644 index fedadae..0000000 --- a/lib/authorize_net/addresses/address.rb +++ /dev/null @@ -1,25 +0,0 @@ -module AuthorizeNet - # Models an address. - class Address - include AuthorizeNet::Model - - attr_accessor :first_name, :last_name, :company, :street_address, :city, :state, :zip, :country, :phone, :fax, :customer_address_id - - def to_hash - hash = { - first_name: @first_name, - last_name: @last_name, - company: @company, - address: @street_address, - city: @city, - state: @state, - zip: @zip, - country: @country, - phone: @phone, - fax: @fax, - customer_address_id: @customer_address_id - } - hash.delete_if { |_k, v| v.nil? } - end - end -end diff --git a/lib/authorize_net/addresses/shipping_address.rb b/lib/authorize_net/addresses/shipping_address.rb deleted file mode 100644 index 9b0508d..0000000 --- a/lib/authorize_net/addresses/shipping_address.rb +++ /dev/null @@ -1,22 +0,0 @@ -module AuthorizeNet - # Models a shipping address. - class ShippingAddress < Address - include AuthorizeNet::Model - - def to_hash - hash = { - ship_to_first_name: @first_name, - ship_to_last_name: @last_name, - ship_to_company: @company, - ship_to_address: @street_address, - ship_to_city: @city, - ship_to_state: @state, - ship_to_zip: @zip, - ship_to_country: @country, - ship_to_phone: @phone, - ship_to_fax: @fax - } - hash.delete_if { |_k, v| v.nil? } - end - end -end diff --git a/lib/authorize_net/aim/response.rb b/lib/authorize_net/aim/response.rb deleted file mode 100644 index 46dc029..0000000 --- a/lib/authorize_net/aim/response.rb +++ /dev/null @@ -1,120 +0,0 @@ -module AuthorizeNet::AIM - # The AIM response class. Handles parsing the response from the gateway. - class Response < AuthorizeNet::KeyValueResponse - # Our MD5 digest generator. - @@digest = OpenSSL::Digest.new('md5') - - include AuthorizeNet::AIM::Fields - - # Fields to convert to/from booleans. - @@boolean_fields = [:tax_exempt] - - # Fields to convert to/from BigDecimal. - @@decimal_fields = %i[amount tax freight duty requested balance_on_card] - - # Constructs a new response object from a +raw_response+ and the +transaction+ that generated - # the +raw_response+. You don't typically construct this object yourself, as AuthorizeNet::AIM::Transaction - # will build one for you when it makes the request to the gateway. - def initialize(raw_response, transaction) - @version = transaction.version - raise "AuthorizeNet gem only supports AIM version 3.1" unless @version.to_s == '3.1' - @raw_response = raw_response - @fields = {} - @transaction = transaction - custom_field_names = transaction.custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym) - @custom_fields = {} - split_on = transaction.delimiter - if @raw_response.is_a?(Net::HTTPOK) || @raw_response.is_a?(Nokogiri::XML::Element) - if @raw_response.is_a?(Net::HTTPOK) - raw_data = @raw_response.body - else - raw_data = @raw_response.text - end - unless transaction.encapsulation_character.nil? - split_on = transaction.encapsulation_character + split_on + transaction.encapsulation_character - raw_data = raw_data[1..raw_data.length - 2] - end - raw_data.split(split_on).each_with_index do |field, index| - if transaction.cp_version.nil? - field_desc = FIELDS - else - field_desc = CP_FIELDS - end - if index < field_desc.length - @fields[field_desc[index]] = field - else - @custom_fields[custom_field_names[index - field_desc.length]] = field - end - end - @fields.delete(nil) - @fields.each do |k, v| - if @@boolean_fields.include?(k) - @fields[k] = value_to_boolean(v) - elsif @@decimal_fields.include?(k) - @fields[k] = value_to_decimal(v) - end - end - end - end - - # Returns True if the MD5 hash found in the response payload validates using - # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY). - def valid_md5?(api_login, merchant_value) - return false if @fields[:md5_hash].nil? - @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:transaction_id]}#{@transaction.fields[:amount]}").casecmp(@fields[:md5_hash]).zero? - end - - # Returns the current API version that we are adhering to. - attr_reader :version - - # Check to see if the response indicated success. Success is defined as a 200 OK response indicating - # that the transaction was approved. - def success? - !connection_failure? && approved? - end - - # Returns true if we failed to open a connection to the gateway or got back a non-200 OK HTTP response. - def connection_failure? - !@raw_response.is_a?(Net::HTTPOK) && !@raw_response.is_a?(Nokogiri::XML::Element) - end - - # Returns the underlying Net::HTTPResponse object. This has the original response body along with - # headers and such. Note that if an exception is generated while making the request (which happens - # if there is no internet connection for example), you will get the exception object here instead of - # a Net::HTTPResponse object. - def raw - @raw_response - end - - # Returns the AuthorizeNet::Transaction instance that owns this response. - attr_reader :transaction - - # Returns the transaction's authorization code. This should be shown to the - # end user. - def authorization_code - @fields[:authorization_code] - end - - # Returns the transaction's authorization id. You will need this for future void, refund - # and prior authorization capture requests. - def transaction_id - @fields[:transaction_id] - end - - # Returns the customer id from the response. - def customer_id - @fields[:customer_id] - end - - # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification - # Service checks. - def avs_response - @fields[:avs_response] - end - - # Returns the credit card type used in the transaction. The values returned can be found in CardType. - def card_type - @fields[:card_type] - end - end -end diff --git a/lib/authorize_net/aim/transaction.rb b/lib/authorize_net/aim/transaction.rb deleted file mode 100644 index 82d7de9..0000000 --- a/lib/authorize_net/aim/transaction.rb +++ /dev/null @@ -1,171 +0,0 @@ -module AuthorizeNet::AIM - # The AIM transaction class. Handles building the transaction payload and - # transmitting it to the gateway. - class Transaction < AuthorizeNet::KeyValueTransaction - # The default options for the constructor. - @@option_defaults = { - transaction_type: Type::AUTHORIZE_AND_CAPTURE, - gateway: :production, - test: false, - allow_split: false, - delimiter: ',', - encapsulation_character: nil, - verify_ssl: true, - device_type: DeviceType::UNKNOWN, - market_type: MarketType::RETAIL - } - - # Fields to convert to/from booleans. - @@boolean_fields = %i[tax_exempt test_request recurring_billing allow_partial_auth delim_data email_customer relay_response] - - # Fields to convert to/from BigDecimal. - @@decimal_fields = [:amount] - - # Constructs an AIM transaction. You can use the new AIM transaction object - # to issue a request to the payment gateway and parse the response into a new - # AuthorizeNet::AIM::Response object. - # - # +api_login_id+:: Your API login ID, as a string. - # +api_transaction_key+:: Your API transaction key, as a string. - # +options+:: A hash of options. See below for values. - # - # Options - # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly. - # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::AIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :card_present_test, :card_present_live, :card_present_sandbox, :card_present_production, :production, or :live (:test is an alias for :sandbox, :card_present_test is an alias for :card_present_sandbox, :card_present_production is an alias for :card_present_live, and :live is an alias for :production). - # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false). - # +allow_split+:: A boolean indicating if split transactions should be allowed (defaults to false). - # +delimiter+:: A single character (as a string) that will be used to delimit the response from the gateway. Defaults to ','. - # +encapsulation_character+:: A single character (as a string) that will be used to encapsulate each field in the response from the gateway. Defaults to nil. - # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true. - # +device_type+:: A constant from DeviceType indicating the type of POS device used in a card present transaction. Defaults to DeviceType::UNKNOWN. - # +market_type+:: A constant from MarketType indicating your industry. Used for card present transactions. Defaults to MarketType::RETAIL. - # - def initialize(api_login_id, api_transaction_key, options = {}) - ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction" - super() - options = @@option_defaults.merge(options) - @api_login_id = api_login_id - @api_transaction_key = api_transaction_key - @test_mode = options[:test] - @response ||= nil - @delimiter = options[:delimiter] - @type = options[:transaction_type] - @cp_version = nil - case options[:gateway] - when :sandbox, :test - @gateway = Gateway::TEST - when :production, :live - @gateway = Gateway::LIVE - when :card_present_live, :card_present_production - @gateway = Gateway::CARD_PRESENT_LIVE - @cp_version = '1.0' - when :card_present_test, :card_present_sandbox - @gateway = Gateway::CARD_PRESENT_TEST - @cp_version = '1.0' - else - @gateway = options[:gateway] - end - @allow_split_transaction = options[:allow_split] - @encapsulation_character = options[:encapsulation_character] - @verify_ssl = options[:verify_ssl] - @market_type = options[:market_type] - @device_type = options[:device_type] - @solution_id = options[:solution_id] - end - - # Checks if the transaction has been configured for test mode or not. Return TRUE if the - # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox - # are considered test transactions. - def test? - super || @gateway == Gateway::TEST - end - - # Returns TRUE if split transactions are allowed, FALSE otherwise. - def split_transaction_allowed? - !!@allow_split_transaction - end - - # Returns the current encapsulation character unless there is none, in which case Nil is returned. - attr_reader :encapsulation_character - - # Returns the gateway to be used for this transaction. - attr_reader :gateway - - # Checks to see if the transaction has a response (meaning it has been submitted to the gateway). - # Returns TRUE if a response is present, FALSE otherwise. - def has_response? - !@response.nil? - end - - # Retrieve the response object (or Nil if transaction hasn't been sent to the gateway). - attr_reader :response - - # Returns the current delimiter we are using to parse the fields returned by the - # gateway. - attr_reader :delimiter - - # Sets the delimiter used to parse the response from the gateway. - attr_writer :delimiter - - # Submits the transaction to the gateway for processing. Returns a response object. If the transaction - # has already been run, it will return nil. - def run - make_request - end - - # Returns the current card present API version that we are adhering to. - attr_reader :cp_version - - attr_reader :solution_id - - #:enddoc: - protected - - # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response. - def make_request - return nil if has_response? - url = URI.parse(@gateway) - fields = @fields.merge(type: @type, delim_char: @delimiter, delim_data: "TRUE", login: @api_login_id, tran_key: @api_transaction_key, relay_response: "FALSE") - - if @cp_version.nil? - fields[:version] = @version - else - fields.merge!(cp_version: @cp_version, market_type: @market_type, device_type: @device_type, response_format: "1") - end - fields[:test_request] = boolean_to_value(@test_mode) - fields[:allow_partial_auth] = 'TRUE' if @allow_split_transaction - fields[:encap_char] = @encapsulation_character unless @encapsulation_character.nil? - fields[:solution_id] = @solution_id unless @solution_id.nil? - fields.each do |k, v| - if @@boolean_fields.include?(k) - fields[k] = boolean_to_value(v) - elsif @@decimal_fields.include?(k) - fields[k] = decimal_to_value(v) - end - end - data = fields.collect do |key, val| - to_param(key, val) - end - custom_field_keys = @custom_fields.keys.collect(&:to_s).sort.collect(&:to_sym) - for key in custom_field_keys - data += [to_param(key, @custom_fields[key.to_sym], '')] - end - data.flatten! - request = Net::HTTP::Post.new(url.path) - request.content_type = 'application/x-www-form-urlencoded' - request.body = data.join("&") - connection = Net::HTTP.new(url.host, url.port) - connection.use_ssl = true - if @verify_ssl - connection.verify_mode = OpenSSL::SSL::VERIFY_PEER - else - connection.verify_mode = OpenSSL::SSL::VERIFY_NONE - end - begin - @response = AuthorizeNet::AIM::Response.new((connection.start { |http| http.request(request) }), self) - rescue StandardError - @response = AuthorizeNet::AIM::Response.new($ERROR_INFO, self) - end - end - end -end diff --git a/lib/authorize_net/api/constants.yml b/lib/authorize_net/api/constants.yml index 5fa02e2..05dbb08 100644 --- a/lib/authorize_net/api/constants.yml +++ b/lib/authorize_net/api/constants.yml @@ -1 +1 @@ -clientId: sdk-ruby-1.9.7 +clientId: sdk-ruby-2.0.0 diff --git a/lib/authorize_net/arb/fields.rb b/lib/authorize_net/arb/fields.rb deleted file mode 100644 index 49e0029..0000000 --- a/lib/authorize_net/arb/fields.rb +++ /dev/null @@ -1,24 +0,0 @@ -module AuthorizeNet::ARB - module Fields - EntityDescription = Struct.new(:node_structure, :entity_class, :arg_mapping) - - SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION = EntityDescription.new( - [ - { id: :id }, - { name: :name }, - { status: :status }, - { createTimeStampUTC: :create_time_stamp_utc }, - { firstName: :first_name }, - { lastName: :last_name }, - { totalOccurrences: :total_occurrences }, - { pastOccurrences: :past_occurrences }, - { paymentMethod: :payment_method }, - { accountNumber: :account_number }, - { invoice: :invoice }, - { amount: :amount }, - { currencyId: :currency_id } - ], - AuthorizeNet::ARB::SubscriptionDetail - ) - end -end diff --git a/lib/authorize_net/arb/paging.rb b/lib/authorize_net/arb/paging.rb deleted file mode 100644 index ee4c730..0000000 --- a/lib/authorize_net/arb/paging.rb +++ /dev/null @@ -1,29 +0,0 @@ -module AuthorizeNet::ARB - class Paging - # Models Paging - include AuthorizeNet::Model - - attr_accessor :offset, :limit - - # Initializes Paging object. - # - # Typical usage: - # paging = AuthorizeNet::ARB::Paging.new(1,1000) - # - # Valid values for offset: 1 to 100000 - # Valid values for limit: 1 to 1000 - # - def initialize(offset, limit) - @offset = offset - @limit = limit - end - - def to_hash - hash = { - offset: @offset, - limit: @limit - } - hash.delete_if { |_k, v| v.nil? } - end - end -end diff --git a/lib/authorize_net/arb/response.rb b/lib/authorize_net/arb/response.rb deleted file mode 100644 index d5488f7..0000000 --- a/lib/authorize_net/arb/response.rb +++ /dev/null @@ -1,26 +0,0 @@ -module AuthorizeNet::ARB - # The ARB response class. - class Response < AuthorizeNet::XmlResponse - # Constructs a new response object from a +raw_response. You don't typically - # construct this object yourself, as AuthorizeNet::ARB::Transaction will - # build one for you when it makes the request to the gateway. - def initialize(raw_response, transaction) - super - unless connection_failure? - begin - @subscription_id = node_content_unless_nil(@root.at_css('subscriptionId')) - @subscription_status = node_content_unless_nil(@root.at_css('Status')) - rescue StandardError - @raw_response = $ERROR_INFO - end - end - end - - # Returns the subscriptionId from the response if there is one. Otherwise returns nil. - attr_reader :subscription_id - - # Returns the status of the Subscription from the response if there is one. Otherwise returns nil. This value - # is only returned in response to a get_status transaction. - attr_reader :subscription_status - end -end diff --git a/lib/authorize_net/arb/sorting.rb b/lib/authorize_net/arb/sorting.rb deleted file mode 100644 index 4db351d..0000000 --- a/lib/authorize_net/arb/sorting.rb +++ /dev/null @@ -1,39 +0,0 @@ -module AuthorizeNet::ARB - class Sorting - # Models Sorting - include AuthorizeNet::Model - - attr_accessor :order_by, :order_descending - - # Initializes Sorting object. - # - # Typical usage: - # sorting = AuthorizeNet::ARB::Sorting.new('name',true) - # - # Valid values for order_by values of the AuthorizeNet::ARB::Sorting: - # id - # name - # status - # createTimeStampUTC - # lastName - # firstName - # accountNumber - # amount - # pastOccurrences - # - # Valid values for order_descending: true, false, 1, 0 - # - def initialize(order_by, order_descending) - @order_by = order_by - @order_descending = order_descending - end - - def to_hash - hash = { - order_by: @order_by, - order_descending: @order_descending - } - hash.delete_if { |_k, v| v.nil? } - end - end -end diff --git a/lib/authorize_net/arb/subscription.rb b/lib/authorize_net/arb/subscription.rb deleted file mode 100644 index 1871ef0..0000000 --- a/lib/authorize_net/arb/subscription.rb +++ /dev/null @@ -1,68 +0,0 @@ -module AuthorizeNet::ARB - # Models an ARB subscription. - class Subscription - # Use this constant for the value of total_occurrences to get a subscription with no end. - UNLIMITED_OCCURRENCES = 9999 - - # Constants for the various interval units supported by the ARB API. - module IntervalUnits - MONTH = 'months'.freeze - DAY = 'days'.freeze - end - - # Constants for the various statuses a subscription can have. These are returned by the get_status call. - module Status - ACTIVE = 'active'.freeze - EXPIRED = 'expired'.freeze - SUSPENDED = 'suspended'.freeze - CANCELED = 'canceled'.freeze - TERMINATED = 'terminated'.freeze - end - - include AuthorizeNet::Model - - attr_accessor :name, :length, :unit, :start_date, :total_occurrences, :trial_occurrences, :amount, :trial_amount, :invoice_number, :description, :subscription_id, :credit_card, :billing_address, :shipping_address, :customer - - # Override the total_occurrences setter to provide support for :unlimited shortcut. - def total_occurrences=(new_total_occurrences) #:nodoc: - if new_total_occurrences == :unlimited - @total_occurrences = UNLIMITED_OCCURRENCES - else - @total_occurrences = new_total_occurrences - end - end - - # Override the unit setter to provide support for :day, :days, :month, :months shortcut. Do not document this method in rdoc. - def unit=(new_unit) #:nodoc: - case new_unit - when :day, :days - @unit = IntervalUnits::DAY - when :month, :months - @unit = IntervalUnits::MONTH - else - @unit = new_unit - end - end - - def to_hash - hash = { - subscription_name: @name, - subscription_length: @length, - subscription_unit: @unit, - subscription_start_date: @start_date, - subscription_total_occurrences: @total_occurrences, - subscription_trial_occurrences: @trial_occurrences, - subscription_amount: @amount, - subscription_trial_amount: @trial_amount, - invoice_num: @invoice_number, - description: @description, - subscription_id: @subscription_id - } - hash.merge!(@credit_card.to_hash) unless @credit_card.nil? - hash.merge!(@billing_address.to_hash) unless @billing_address.nil? - hash.merge!(@shipping_address.to_hash) unless @shipping_address.nil? - hash.merge!(@customer.to_hash) unless @customer.nil? - hash.delete_if { |_k, v| v.nil? } - end - end -end diff --git a/lib/authorize_net/arb/subscription_detail.rb b/lib/authorize_net/arb/subscription_detail.rb deleted file mode 100644 index a9c0cd6..0000000 --- a/lib/authorize_net/arb/subscription_detail.rb +++ /dev/null @@ -1,10 +0,0 @@ -module AuthorizeNet::ARB - # Models Subscription Detail. - class SubscriptionDetail - include AuthorizeNet::Model - - attr_accessor :id, :name, :status, :create_time_stamp_utc, :first_name, - :last_name, :total_occurrences, :past_occurrences, - :payment_method, :account_number, :invoice, :amount, :currency_id - end -end diff --git a/lib/authorize_net/arb/subscription_list_response.rb b/lib/authorize_net/arb/subscription_list_response.rb deleted file mode 100644 index cdb10bb..0000000 --- a/lib/authorize_net/arb/subscription_list_response.rb +++ /dev/null @@ -1,36 +0,0 @@ -module AuthorizeNet::ARB - class SubscriptionListResponse < AuthorizeNet::XmlResponse - # Constructs a new response object from a +raw_response. You don't typically - # construct this object yourself, as AuthorizeNet::ARB::Transaction will - # build one for you when it makes the request to the gateway. - def initialize(raw_response, transaction) - super - unless connection_failure? - begin - @subscription_details = @root.at_css('subscriptionDetails') - @subscription_detail = @root.at_css('subscriptionDetail') - @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet')) - rescue StandardError - @raw_response = $ERROR_INFO - end - end - end - - # Returns total number of subscriptions matching the search criteria - attr_reader :total_num_in_resultset - - # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned. - def subscription_details - unless @subscription_details.nil? - subscription_details = [] - @subscription_details.element_children.each do |child| - next if child.nil? - subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION) - - subscription_details <<= subscription_detail - end - return subscription_details unless subscription_details.empty? - end - end - end -end diff --git a/lib/authorize_net/arb/transaction.rb b/lib/authorize_net/arb/transaction.rb deleted file mode 100644 index 3c7af98..0000000 --- a/lib/authorize_net/arb/transaction.rb +++ /dev/null @@ -1,171 +0,0 @@ -module AuthorizeNet::ARB - # The ARB transaction class. - class Transaction < AuthorizeNet::XmlTransaction - include AuthorizeNet::ARB::Fields - - # The default options for the constructor. - @@option_defaults = { - gateway: :production, - verify_ssl: true, - reference_id: nil - } - - # Fields to convert to/from booleans. - @@boolean_fields = [] - - # Fields to convert to/from BigDecimal. - @@decimal_fields = %i[amount trial_amount] - - # Fields to convert to/from Date. - @@date_fields = [:subscription_start_date] - - # The class to wrap our response in. - @response_class = AuthorizeNet::ARB::Response - - # Constructs an ARB transaction. You can use the new ARB transaction object - # to issue a request to the payment gateway and parse the response into a new - # AuthorizeNet::ARB::Response object. - # - # +api_login_id+:: Your API login ID, as a string. - # +api_transaction_key+:: Your API transaction key, as a string. - # +options+:: A hash of options. See below for values. - # - # Options - # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::ARB::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production). - # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true. - # +reference_id+:: A string that can be used to identify a particular transaction with its response. Will be echo'd in the response, only if it was provided in the transaction. Defaults to nil. - # - def initialize(api_login_id, api_transaction_key, options = {}) - ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction" - super - end - - # Sets up and submits a start of subscription (ARBCreateSubscriptionRequest) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. - # - # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the recurring payment you would like to create. - # - # - # Typical usage: - # - # subscription = AuthorizeNet::ARB::Subscription.new( - # :name => "Monthly Gift Basket", - # :length => 1, - # :unit => :month, - # :start_date => Date.today, - # :total_occurrences => :unlimited, - # :amount => 100.00, - # :invoice_number => '1234567', - # :description => "John Doe's Monthly Gift Basket", - # :credit_card => AuthorizeNet::CreditCard.new('4111111111111111', '1120'), - # :billing_address => AuthorizeNet::Address.new(:first_name => 'John', :last_name => 'Doe') - # ) - # response = transaction.create(subscription) - # - def create(subscription) - @type = Type::ARB_CREATE - set_fields(subscription.to_hash) - run - end - - # Sets up and submits a subscription update (ARBUpdateSubscriptionRequest) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. - # - # +subscription+:: An instance of AuthorizeNet::ARB::Subscription describing the changes to make. It must have a value for subscription_id so that the API knows what subscription to update. Note that some information (intervals, start dates, etc) can't be changed. See the ARB guide for more details. - # - # - # Typical usage: - # - # subscription = AuthorizeNet::ARB::Subscription.new( - # :billing_address => AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe'), - # :subscription_id => '123456' - # ) - # response = transaction.update(subscription) - # - def update(subscription) - @type = Type::ARB_UPDATE - set_fields(subscription.to_hash) - run - end - - # Sets up and submits a subscription status query (ARBGetSubscriptionStatusRequest) transaction. Returns a response object (which contains the subscription status). If the transaction - # has already been run, it will return nil. - # - # +subscription_id+:: Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it. - # - # - # Typical usage: - # - # response = transaction.get_status('123456') - # response.subscription_status # A value from AuthorizeNet::ARB::Subscription::Status - # - def get_status(subscription_id) - @type = Type::ARB_GET_STATUS - handle_subscription_id(subscription_id) - run - end - - # Sets up and submits a subscription list query (ARBGetSubscriptionListRequest). Returns a response object - # which contains the list of subscription details and the total number of subscriptions matching the search - # criteria. Sorting and Paging are optional parameters. - # - # Valid values for search type parameter: - # cardExpiringThisMonth - # subscriptionActive - # subscriptionExpiringThisMonth - # subscriptionInactive - # - # Typical usage: - # - # sorting = AuthorizeNet::ARB::Sorting.new('name',true) - # paging = AuthorizeNet::ARB::Paging.new(1,1000) - # response = transaction.get_subscription_list('subscriptionActive',sorting,paging) - # - def get_subscription_list(search_type, sorting = nil, paging = nil) - unless search_type.nil? - self.class.instance_variable_set(:@response_class, SubscriptionListResponse) - @type = Type::ARB_GET_SUBSCRIPTION_LIST - set_fields(search_type: search_type.to_s) - set_fields(sorting.to_hash) unless sorting.nil? - set_fields(paging.to_hash) unless paging.nil? - run - end - response - end - - # Sets up and submits a subscription cancelation (ARBCancelSubscriptionRequest) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. - # - # +subscription_id+:: Either the subscription id of the subscription to get the status of as a string, or a Subscription instance with a value for subscription_id set on it. - # - # - # Typical usage: - # - # response = transaction.cancel('123456') - # - def cancel(subscription_id) - @type = Type::ARB_CANCEL - handle_subscription_id(subscription_id) - run - end - - #:enddoc: - protected - - # Internal method to handle multiple types of subscription id arguments. - def handle_subscription_id(subscription_id) - case subscription_id - when Subscription - set_fields(subscription_id: subscription_id.subscription_id.to_s) - else - set_fields(subscription_id: subscription_id.to_s) - end - end - - # An internal method that builds the POST body, submits it to the gateway, and constructs a Response object with the response. - def make_request - set_fields(reference_id: @reference_id) - super - end - end -end diff --git a/lib/authorize_net/cim/customer_profile.rb b/lib/authorize_net/cim/customer_profile.rb deleted file mode 100644 index 8c1b5e2..0000000 --- a/lib/authorize_net/cim/customer_profile.rb +++ /dev/null @@ -1,15 +0,0 @@ -module AuthorizeNet::CIM - # Models a customer profile. - class CustomerProfile < AuthorizeNet::Customer - include AuthorizeNet::Model - - attr_accessor :customer_profile_id, :payment_profiles - - def to_hash - hash = super - hash.delete_if { |_k, v| v.nil? } - hash[:payment_profiles] = handle_multivalue_hashing(@payment_profiles) - hash - end - end -end diff --git a/lib/authorize_net/cim/payment_profile.rb b/lib/authorize_net/cim/payment_profile.rb deleted file mode 100644 index deed278..0000000 --- a/lib/authorize_net/cim/payment_profile.rb +++ /dev/null @@ -1,35 +0,0 @@ -module AuthorizeNet::CIM - # Models a payment profile. - class PaymentProfile - module CustomerType - INDIVIDUAL = 'individual'.freeze - BUSINESS = 'business'.freeze - end - - include AuthorizeNet::Model - - attr_accessor :cust_type, :billing_address, :payment_method, :customer_payment_profile_id - - def cust_type=(type) #:nodoc: - case type - when :business - @cust_type = CustomerType::BUSINESS - when :individual - @cust_type = CustomerType::INDIVIDUAL - else - @cust_type = type - end - end - - def to_hash - hash = { - cust_type: @cust_type, - customer_payment_profile_id: @customer_payment_profile_id - } - hash.delete_if { |_k, v| v.nil? } - hash.merge!(@billing_address.to_hash) unless @billing_address.nil? - hash.merge!(@payment_method.to_hash) unless @payment_method.nil? - hash - end - end -end diff --git a/lib/authorize_net/cim/response.rb b/lib/authorize_net/cim/response.rb deleted file mode 100644 index 73feb0d..0000000 --- a/lib/authorize_net/cim/response.rb +++ /dev/null @@ -1,111 +0,0 @@ -module AuthorizeNet::CIM - # The CIM response class. - class Response < AuthorizeNet::XmlResponse - include AuthorizeNet::CIM::Fields - - # Constructs a new response object from raw_response in the context of transaction. - # You don‘t typically construct this object yourself, as AuthorizeNet::CIM::Transaction - # will build one for you when it makes the request to the gateway. - def initialize(raw_response, transaction) - super - unless connection_failure? - begin - @customer_profile_id = node_content_unless_nil(@root.at_css('customerProfileId')) - @customer_payment_profile_id = node_content_unless_nil(@root.at_css('customerPaymentProfileId')) - @customer_payment_profile_id_list = node_child_content_unless_nil(@root.at_css('customerPaymentProfileIdList')) - @customer_shipping_address_id_list = node_child_content_unless_nil(@root.at_css('customerShippingAddressIdList')) - @customer_address_id = node_content_unless_nil(@root.at_css('customerAddressId')) - @validation_direct_response_list = @root.at_css('validationDirectResponseList') - @validation_direct_response = @root.at_css('validationDirectResponse') - @direct_response = @root.at_css('directResponse') - @customer_profile_id_list = node_child_content_unless_nil(@root.at_css('ids')) - @address = @root.at_css('address') - @payment_profile = @root.at_css('paymentProfile') - @profile = @root.at_css('profile') - @token = node_content_unless_nil(@root.at_css('token')) - rescue StandardError - @raw_response = $ERROR_INFO - end - end - end - - # Returns a CustomerProfile ID if one was returned by the gateway. Returns nil otherwise. - # Note that this method will return nil if we got back a list of IDs (see profile_ids). - def profile_id - @customer_profile_id - end - - # Returns a list of CustomerProfile IDs if any were returned by the gateway. Returns nil otherwise. - def profile_ids - @customer_profile_id_list - end - - # Returns an Address ID if one was returned by the gateway. Returns nil otherwise. - # Note that this method will return nil if we got back a list of IDs (see address_ids). - def address_id - @customer_address_id - end - - # Returns a list of Address IDs if any were returned by the gateway. Returns nil otherwise. - def address_ids - @customer_shipping_address_id_list - end - - # Returns a PaymentProfile ID if one was returned by the gateway. Returns nil otherwise. - # Note that this method will return nil if we got back a list of IDs (see payment_profile_ids). - def payment_profile_id - @customer_payment_profile_id - end - - # Returns a list of PaymentProfile IDs if any were returned by the gateway. Returns nil otherwise. - def payment_profile_ids - @customer_payment_profile_id_list - end - - # Returns hosted profile access token when requested. Returns nil otherwise. - attr_reader :token - - # Returns a validation response as an AuthorizeNet::AIM::Response object if a validation response was returned - # by the gateway. Returns nil otherwise. - # Note that this method will return nil if we got back a list of IDs (see validation_responses). - def validation_response - AuthorizeNet::AIM::Response.new(@validation_direct_response.dup, @transaction) unless @validation_direct_response.nil? - end - - # Returns a list of validation response as an AuthorizeNet::AIM::Response objects if a list of validation response was returned - # by the gateway. Returns nil otherwise. - def validation_responses - unless @validation_direct_response_list.nil? - responses = [] - @validation_direct_response_list.element_children.each do |child| - responses <<= AuthorizeNet::AIM::Response.new(child.dup, @transaction) unless child.nil? - end - return responses unless responses.empty? - end - end - - # Returns the direct response as an AuthorizeNet::AIM::Response object if a direct response was returned - # by the gateway. Returns nil otherwise. - def direct_response - AuthorizeNet::AIM::Response.new(@direct_response.dup, @transaction) unless @direct_response.nil? - end - - # Returns a CustomerProfile built from the entity returned by the gateway. Returns nil otherwise. - def profile - build_entity(@profile, Fields::PROFILE_ENTITY_DESCRIPTION) unless @profile.nil? - end - - # Returns a PaymentProfile built from the entity returned by the gateway. Returns nil otherwise. - def payment_profile - build_entity(@payment_profile, Fields::PAYMENT_PROFILE_ENTITY_DESCRIPTION) unless @payment_profile.nil? - end - - # Returns an Address built from the entity returned by the gateway. Returns nil otherwise. - def address - build_entity(@address, Fields::ADDRESS_ENTITY_DESCRIPTION) unless @address.nil? - end - - #:enddoc: - protected - end -end diff --git a/lib/authorize_net/cim/transaction.rb b/lib/authorize_net/cim/transaction.rb deleted file mode 100644 index cfacb57..0000000 --- a/lib/authorize_net/cim/transaction.rb +++ /dev/null @@ -1,721 +0,0 @@ -module AuthorizeNet::CIM - # The CIM transaction class. - class Transaction < AuthorizeNet::XmlTransaction - include AuthorizeNet::CIM::Fields - - # The class to wrap our response in. - @response_class = AuthorizeNet::CIM::Response - - # The default options for the constructor. - @@option_defaults = { - gateway: :production, - verify_ssl: true, - reference_id: nil - } - - # Constructs a CIM transaction. You can use the new CIM transaction object - # to issue a request to the payment gateway and parse the response into a new - # AuthorizeNet::CIM::Response object. - # - # +api_login_id+:: Your API login ID, as a string. - # +api_transaction_key+:: Your API transaction key, as a string. - # +options+:: A hash of options. See below for values. - # - # Options - # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::CIM::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production). - # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true. - # +reference_id+:: A string that can be used to identify a particular transaction with its response. Will be echo'd in the response, only if it was provided in the transaction. Defaults to nil. - # - def initialize(api_login_id, api_transaction_key, options = {}) - ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction" - super - @delim_char = ',' - @encap_char = nil - @custom_fields = {} - end - - # The default options for create_profile. - @@create_profile_option_defaults = { - validation_mode: :none - } - - # The default options for get_hosted_profile_token. - @@get_hosted_profile_token_option_defaults = { - border_visible: true, - validation_mode: :none - } - - # The default options for create_payment_profile. - @@create_payment_profile_option_defaults = { - validation_mode: :none - } - - # The default options for update_payment_profile. - @@update_payment_profile_option_defaults = { - validation_mode: :none - } - - # The default options for create_transaction and the various type specific create transaction methods. - @@create_transaction_option_defaults = { - address_id: nil, - split_tender_id: nil, - aim_options: nil, - custom_fields: nil - } - - # The default options for validate_payment_profile. - @@validate_payment_profile_option_defaults = { - address_id: nil, - card_code: nil, - validation_mode: :testMode - } - - # A list of keys that should be stored if passed as aim_options. - @@aim_response_options = %i[delim_char encap_char] - - # Sets up and submits a createCustomerProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have a profile_id if the request was successful. If any PaymentProfiles or Addresses - # were included, you can find their IDs in the response objects payment_profile_ids and address_ids methods. - # - # +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to create. - # +options+:: An optional hash of options. - # - # Options: - # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile) - # - # Typical usage: - # - # profile = AuthorizeNet::CIM::CustomerProfile.new( - # :email => 'test@example.com', - # :id => 'userassignedid' - # ) - # response = transaction.create_profile(profile) - # puts response.profile_id if response.success? - # - def create_profile(profile, options = {}) - options = @@create_profile_option_defaults.merge(options) - @type = Type::CIM_CREATE_PROFILE - @fields.merge!(profile.to_hash) - set_fields(validation_mode: options[:validation_mode]) - make_request - end - - # Sets up and submits a getCustomerProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have the CustomerProfile object requested available via its profile method if - # the request was successful. - # - # - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to retrieve, or a CustomerProfile object with the ID populated. - # Typical usage: - # - # response = transaction.get_profile('123456') - # profile = response.profile if response.success? - # - def get_profile(profile_id) - @type = Type::CIM_GET_PROFILE - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a updateCustomerProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. Note that - # any PaymentProfiles will NOT be updated using this method. This is a limitation of the CIM API. See - # update_payment_profile if you need to update a PaymentProfile. - # - # - # +profile+:: An AuthorizeNet::CIM::CustomerProfile object describing the profile to update. It must contain the customer_profile_id of the record to update. - # Typical usage: - # - # profile.fax = '5555551234' - # response = transaction.update_profile(profile) - # puts response.success? - # - def update_profile(profile) - @type = Type::CIM_UPDATE_PROFILE - @fields.merge!(profile.to_hash) - make_request - end - - # Sets up and submits a deleteCustomerProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated. - # Typical usage: - # - # response = transaction.delete_profile('123456') - # puts response.success? - # - def delete_profile(profile_id) - @type = Type::CIM_DELETE_PROFILE - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a getHostedProfilePageRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile you want to delete, or a CustomerProfile object with the ID populated. - # - # Options: - # +return_url+:: Enter the URL for the page that the customer returns to when the hosted session ends. Do not pass this setting for iframes or popups. - # +return_url_text+:: Enter the text to display on the button that returns the customer to your web site. The value can be any text up to 200 characters. - # If you do not pass this parameter, the default button text is Continue. Do not pass this setting for iframes or popups. - # +heading_color+:: Enter a hex color string such as #e0e0e0. The background color of the section headers changes from gray to a custom color. - # +border_visible+:: Enter true or false. Must be false for iframes or popups, and must be true for redirects. - # +iframe_communicator_url+:: Enter the URL to a page that can communicate with the merchant’s main page using javascript. - # This parameter enables you to dynamically change the size of the popup so that there are no scroll bars. - # This parameter is required only for iframe or lightbox applications. - # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to set hostedProfileValidationMode mode - - def get_hosted_profile_token(profile_id, options = {}) - options = @@get_hosted_profile_token_option_defaults.merge(options) - @type = Type::CIM_GET_HOSTED_PROFILE - handle_profile_id(profile_id) - handle_hosted_profile_settings(options) - make_request - end - - # Sets up and submits a createCustomerPaymentProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have a payment_profile_id if the request was successful. - # - # +profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to create. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who will own the PaymentProfile, or a CustomerProfile object with the ID populated. - # +options+:: An optional hash of options. - # - # Options: - # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do (assuming a PaymentProfile is included with the CustomerProfile) - # - # Typical usage: - # - # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '0120') - # payment_profile = AuthorizeNet::CIM::PaymentProfile.new(:payment_method => credit_card) - # response = transaction.create_payment_profile(payment_profile, '123456') - # puts response.payment_profile_id if response.success? - # - def create_payment_profile(payment_profile, profile_id, options = {}) - options = @@create_payment_profile_option_defaults.merge(options) - @type = Type::CIM_CREATE_PAYMENT - @fields.merge!(payment_profile.to_hash) - set_fields(validation_mode: options[:validation_mode]) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a getCustomerPaymentProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have the PaymentProfile object requested available via its payment_profile method if - # the request was successful. - # - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # response = transaction.get_payment_profile('654321', '123456') - # payment_profile = response.payment_profile if response.success? - # - def get_payment_profile(payment_profile_id, profile_id) - @type = Type::CIM_GET_PAYMENT - handle_payment_profile_id(payment_profile_id) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a updateCustomerPaymentProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # - # +payment_profile+:: An AuthorizeNet::CIM::PaymentProfile object describing the profile to update. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # payment_profile.cust_type = :business - # response = transaction.update_payment_profile(payment_profile, '123456') - # puts response.success? - # - # Options: - # +validation_mode+:: Set to :testMode, :liveMode or :none (the default) to indicate what sort of PaymentProfile validation to do. - # - def update_payment_profile(payment_profile, profile_id, options = {}) - options = @@create_payment_profile_option_defaults.merge(options) - @type = Type::CIM_UPDATE_PAYMENT - @fields.merge!(payment_profile.to_hash) - set_fields(validation_mode: options[:validation_mode]) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a deleteCustomerPaymentProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to retrieve, or a PaymentProfile object with the ID populated. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # response = transaction.delete_profile('123456') - # puts response.success? - # - def delete_payment_profile(payment_profile_id, profile_id) - @type = Type::CIM_DELETE_PAYMENT - handle_payment_profile_id(payment_profile_id) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a validateCustomerPaymentProfileRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The results - # of the validation can be obtained via the direct_response method of the response object. - # - # - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to validate, or a PaymentProfile object with the ID populated. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this PaymentProfile, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # response = transaction.validate_payment_profile('654321', '123456') - # puts response.direct_response.success? if response.success? - # - # Options: - # +validation_mode+:: Set to :testMode (the default) or :liveMode to indicate what sort of PaymentProfile validation to do. - # +address_id+:: Set a shipping Address to be part of the validation transaction. - # +card_code+:: Set a CCV code if one is needed for validation. Defaults to nil. - # - def validate_payment_profile(payment_profile_id, profile_id, options = {}) - @type = Type::CIM_VALIDATE_PAYMENT - options = @@validate_payment_profile_option_defaults.merge(options) - handle_payment_profile_id(payment_profile_id) - handle_profile_id(profile_id) - handle_address_id(options[:address_id]) unless options[:address_id].nil? - set_fields(validation_mode: options[:validation_mode]) - set_fields(card_code: options[:card_code]) unless options[:card_code].nil? - make_request - end - - # Sets up and submits a createCustomerShippingAddressRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have a address_id if the request was successful. - # - # +address+:: An AuthorizeNet::Address object describing the profile to create. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who will own this Address, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # address = AuthorizeNet::Address.new(:first_name => 'Jane', :last_name => 'Doe', :address => '123 Fake St', :city => 'Raccoon Junction', :state => 'WY', :zip => '99999') - # response = transaction.create_address(address, '123456') - # puts response.address_id if response.success? - # - def create_address(address, profile_id) - @type = Type::CIM_CREATE_ADDRESS - @fields.merge!(address.to_hash) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a getCustomerShippingAddressRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have the Address object requested available via its address method if - # the request was successful. - # - # - # +address_id+:: Takes either a String containing the ID of the Address you want to retrieve, or an Address object with the ID populated. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # response = transaction.get_address('654321', '123456') - # address = response.address if response.success? - # - def get_address(address_id, profile_id) - @type = Type::CIM_GET_ADDRESS - handle_address_id(address_id) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a updateCustomerShippingAddressRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # - # +address+:: An Address object describing the address to update. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # address.city = 'Somewhere Else' - # response = transaction.update_address(address, '123456') - # puts response.success? - # - def update_address(address, profile_id) - @type = Type::CIM_UPDATE_ADDRESS - @fields.merge!(address.to_hash) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a deleteCustomerShippingAddressRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. - # - # - # +address_id+:: Takes either a String containing the ID of the Address you want to delete, or an Address object with the ID populated. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns this Address, or a CustomerProfile object with the ID populated. - # - # Typical usage: - # - # response = transaction.delete_address('654321', '123456') - # puts response.success? - # - def delete_address(address_id, profile_id) - @type = Type::CIM_DELETE_ADDRESS - handle_address_id(address_id) - handle_profile_id(profile_id) - make_request - end - - # Sets up and submits a createCustomerProfileTransactionRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. It is recommend - # to use the connivence methods for each type of payment transaction rather than this method. - # - # +type+:: The type of payment transaction to run. Can be :auth_capture, :auth_only, :prior_auth_capture, :void, or :refund. - # +amount+:: The amount of the transaction. This is required for every transaction type except :void. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated. - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated. - # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order. - # +options+:: An optional hash of options. - # - # Options: - # +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil. - # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil. - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction(:auth_capture, 10.00, '123456', '654321', nil) - # if response.success? - # puts response.direct_response if direct_response.success? - # - # - def create_transaction(type, amount, profile_id, payment_profile_id, order, options = {}) - @type = Type::CIM_CREATE_TRANSACTION - options = @@create_transaction_option_defaults.merge(options) - handle_profile_id(profile_id) - handle_payment_profile_id(payment_profile_id) - handle_address_id(options[:address_id]) unless options[:address_id].nil? - set_fields(split_tender_id: options[:split_tender_id]) - @transaction_type = type - @fields.merge!(order.to_hash) unless order.nil? - set_fields(amount: amount) - handle_aim_options(options[:aim_options]) - handle_custom_fields(options[:custom_fields]) - make_request - end - - # Sets up and submits an AUTHORIZE_AND_CAPTURE transaction using stored payment information. If this - # transaction has already been run, this method will return nil. Otherwise it will return an - # AuthorizeNet::CIM::Response object. - # - # +amount+:: The amount of the transaction. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated. - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated. - # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order. - # +options+:: An optional hash of options. - # - # Options: - # +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil. - # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil. - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction_auth_capture(10.00, '123456', '654321', nil) - # if response.success? - # puts response.direct_response if direct_response.success? - # - def create_transaction_auth_capture(amount, profile_id, payment_profile_id, order = nil, options = {}) - create_transaction(:auth_capture, amount, profile_id, payment_profile_id, order, options) - end - - # Sets up and submits an AUTH_ONLY transaction using stored payment information. If this - # transaction has already been run, this method will return nil. Otherwise it will return an - # AuthorizeNet::CIM::Response object. - # - # +amount+:: The amount of the transaction. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be charged, or a CustomerProfile object with the ID populated. - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to charge, or a PaymentProfile object with the ID populated. - # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order. - # +options+:: An optional hash of options. - # - # Options: - # +address_id+:: Takes either a String containing the ID of an Address, or an Address object with the ID populated. Used as the shipping address for the payment transaction. Defaults to nil. - # +split_tender_id+:: A split tender transaction ID as a string. If the transaction is to be part of a split tender batch, this must be included. Defaults to nil. - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction_auth_only(10.00, '123456', '654321', nil) - # if response.success? - # puts response.direct_response if direct_response.success? - # - def create_transaction_auth_only(amount, profile_id, payment_profile_id, order = nil, options = {}) - create_transaction(:auth_only, amount, profile_id, payment_profile_id, order, options) - end - - # Sets up and submits a PRIOR_AUTHORIZATION_AND_CAPTURE transaction using stored payment information. If this - # transaction has already been run, this method will return nil. Otherwise it will return an - # AuthorizeNet::CIM::Response object. - # - # +transaction_id+:: A string containing a transaction ID that was generated via an AUTH_ONLY transaction. - # +amount+:: The amount to capture. Must be <= the amount authorized via the AUTH_ONLY transaction. - # +order+:: An Order object describing the order that this payment transaction is for. Pass nil for no order. - # +options+:: An optional hash of options. - # - # Options: - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction_prior_auth_capture('111222', 10.00) - # if response.success? - # puts response.direct_response if direct_response.success? - # - def create_transaction_prior_auth_capture(transaction_id, amount, order = nil, options = {}) - handle_transaction_id(transaction_id) - create_transaction(:prior_auth_capture, amount, nil, nil, order, options) - end - - # Sets up and submits a VOID transaction using stored payment information. If this - # transaction has already been run, this method will return nil. Otherwise it will return an - # AuthorizeNet::CIM::Response object. - # - # +transaction_id+:: A string containing a transaction ID to void. - # +options+:: An optional hash of options. - # - # Options: - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction_void('111222') - # if response.success? - # puts response.direct_response if direct_response.success? - # - def create_transaction_void(transaction_id, options = {}) - handle_transaction_id(transaction_id) - create_transaction(:void, nil, nil, nil, nil, options) - end - - # Sets up and submits a REFUND transaction using stored payment information. If this - # transaction has already been run, this method will return nil. Otherwise it will return an - # AuthorizeNet::CIM::Response object. - # - # +transaction_id+:: A string containing a transaction ID to refund. Pass nil for an unlinked refund. - # +amount+:: The amount to refund. - # +profile_id+:: Takes either a String containing the ID of the CustomerProfile who owns the PaymentProfile to be credited, or a CustomerProfile object with the ID populated. Pass nil for an unlinked refund. - # +payment_profile_id+:: Takes either a String containing the ID of the PaymentProfile you want to credit, or a PaymentProfile object with the ID populated. Pass nil for an unlinked refund. - # +order+:: An Order object describing the order that is being refunded. Pass nil for no order. - # +options+:: An optional hash of options. - # - # Options: - # +aim_options+:: A hash of AIM options to be included with the payment transaction. Since the payment transactions in CIM are just encapsulated AIM transactions, any field used by AIM can be set here. Defaults to nil. - # +custom_fields+:: A hash of custom fields to pass along with the payment transaction. These fields will be stored with the AIM transaction generated by the CIM transaction. Defaults to nil. - # - # Typical usage: - # - # response = transaction.create_transaction_refund('111222', 10.00, '123456', '654321') - # if response.success? - # puts response.direct_response if direct_response.success? - # - def create_transaction_refund(transaction_id, amount, profile_id, payment_profile_id, order = nil, options = {}) - handle_transaction_id(transaction_id) - create_transaction(:refund, amount, profile_id, payment_profile_id, order, options) - end - - # Sets up and submits a updateSplitTenderGroupRequest transaction. Use this to end or void a split - # tender batch. If this transaction has already been run, this method will return nil. Otherwise - # it will return an AuthorizeNet::CIM::Response object. - # - # +split_tender_id+:: The split tender batch ID you want to change the status of. - # +status+:: The new status to set for the batch. Options are :voided or :completed. - # - # Typical usage: - # - # response = transaction.update_split_tender('1111111', :voided) - # puts response if response.success? - # - def update_split_tender(split_tender_id, status) - @type = Type::CIM_UPDATE_SPLIT - set_fields(split_tender_id: split_tender_id, split_tender_status: status.to_s) - make_request - end - - # Sets up and submits a getCustomerProfileIdsRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::CIM::Response object. The - # response object will have a list of all CustomerProfile IDs available via its profile_ids method on success. - # - # Typical usage: - # - # response = transaction.get_profile_ids() - # puts response.profile_ids if response.success? - # - def get_profile_ids - @type = Type::CIM_GET_PROFILE_IDS - make_request - end - - # :stopdoc: - # Duck-type as an AIM transaction so we can build AIM responses easily - - # No encapsulation_character. - def encapsulation_character - @encap_char - end - - # Comma delimited. - def delimiter - @delim_char - end - - # Custom fields accessor. - attr_reader :custom_fields - - # Always version 3.1. - def version - 3.1 - end - - # Always nil. - def cp_version - nil - end - # :startdoc: - - #:enddoc: - protected - - # Handles profile id type massaging. - def handle_profile_id(id) - case id - when CustomerProfile - set_fields(customer_profile_id: id.customer_profile_id.to_s) - when nil - nil - else - set_fields(customer_profile_id: id.to_s) - end - end - - # Handles payment profile id type massaging. - def handle_payment_profile_id(id) - case id - when PaymentProfile - set_fields(customer_payment_profile_id: id.customer_payment_profile_id.to_s) - when nil - nil - else - set_fields(customer_payment_profile_id: id.to_s) - end - end - - # Handles address id type massaging. - def handle_address_id(id) - case id - when AuthorizeNet::Address - set_fields(customer_address_id: id.customer_address_id.to_s) - when nil - nil - else - set_fields(customer_address_id: id.to_s) - end - end - - # Handles tranasction id type massaging. - def handle_transaction_id(id) - case id - when AuthorizeNet::AIM::Response - set_fields(trans_id: id.transaction_id.to_s) - else - set_fields(trans_id: id.to_s) - end - end - - # Handles packing up aim options. - def handle_aim_options(options) - encoded_options = [] - case options - when Hash - options.each_pair do |k, v| - if @@aim_response_options.include?(k) - instance_variable_set(('@' + k.to_s).to_sym, v) - end - end - when nil - return - else - return handle_aim_options(options.to_hash) - end - - @fields[:extra_options] ||= {} - @fields[:extra_options].merge!(options) - end - - def handle_hosted_profile_settings(options) - options_mapping = { - return_url: :hostedProfileReturnUrl, - return_url_text: :hostedProfileReturnUrlText, - heading_color: :hostedProfileHeadingBgColor, - border_visible: :hostedProfilePageBorderVisible, - iframe_communicator_url: :hostedProfileIFrameCommunicatorUrl, - validation_mode: :hostedProfileValidationMode - } - set_fields( - hosted_settings: options.select do |k, _| - options_mapping.keys.include? k - end.map do |k, v| - { setting_name: options_mapping[k], setting_value: v } - end - ) - end - - # Handles packing up custom fields. - def handle_custom_fields(options) - encoded_options = [] - case options - when Hash - @custom_fields.merge!(options) - when nil - return - else - return handle_custom_fields(options.to_hash) - end - end - - # Callback for creating the right node structure for a given transaction type. `node` is ignored for now. - def select_transaction_type_fields(_node) - case @transaction_type - when :auth_only - TRANSACTION_AUTH_FIELDS - when :auth_capture - TRANSACTION_AUTH_CAPTURE_FIELDS - when :void - TRANSACTION_VOID_FIELDS - when :refund - TRANSACTION_REFUND_FIELDS - when :capture_only - TRASNACTION_CAPTURE_FIELDS - when :prior_auth_capture - TRANSACTION_PRIOR_AUTH_CAPTURE_FIELDS - end - end - end -end diff --git a/lib/authorize_net/customer.rb b/lib/authorize_net/customer.rb deleted file mode 100644 index 37d8b19..0000000 --- a/lib/authorize_net/customer.rb +++ /dev/null @@ -1,24 +0,0 @@ -module AuthorizeNet - # Models a customer. - class Customer - attr_accessor - include AuthorizeNet::Model - - attr_accessor :phone, :fax, :email, :id, :ip, :address, :description - - def to_hash - hash = { - phone: @phone, - fax: @fax, - email: @email, - cust_id: @id, - customer_ip: @ip, - description: @description, - customer_profile_id: @customer_profile_id - } - hash.delete_if { |_k, v| v.nil? } - hash.merge!(@address.to_hash) unless @address.nil? - hash - end - end -end diff --git a/lib/authorize_net/email_receipt.rb b/lib/authorize_net/email_receipt.rb deleted file mode 100644 index cec86ec..0000000 --- a/lib/authorize_net/email_receipt.rb +++ /dev/null @@ -1,20 +0,0 @@ -module AuthorizeNet - # Models an email receipt. - class EmailReceipt - include AuthorizeNet::Model - - attr_accessor :header, :footer, :merchant_email, :email_customer - - def to_hash - hash = { - header: @header, - footer: @footer, - merchant_email: @merchant_email, - email_customer: @email_customer - } - hash.delete_if { |_k, v| v.nil? } - hash.merge(@address.to_hash) unless @address.nil? - hash - end - end -end diff --git a/lib/authorize_net/fields.rb b/lib/authorize_net/fields.rb deleted file mode 100644 index c0d7d74..0000000 --- a/lib/authorize_net/fields.rb +++ /dev/null @@ -1,760 +0,0 @@ -module AuthorizeNet - EntityDescription = Struct.new(:node_structure, :entity_class, :arg_mapping) - - module AIM - # Contains the various lists of fields needed by the AIM API. - module Fields - # Enumeration of the fields found in the AIM response. The index - # of the field name corresponds to its position (+ 1) in the AIM response. - FIELDS = [ - :response_code, - :response_subcode, - :response_reason_code, - :response_reason_text, - :authorization_code, - :avs_response, - :transaction_id, - :invoice_number, - :description, - :amount, - :method, - :transaction_type, - :customer_id, - :first_name, - :last_name, - :company, - :address, - :city, - :state, - :zip_code, - :country, - :phone, - :fax, - :email_address, - :ship_to_first_name, - :ship_to_last_name, - :ship_to_company, - :ship_to_address, - :ship_to_city, - :ship_to_state, - :ship_to_zip_code, - :ship_to_country, - :tax, - :duty, - :freight, - :tax_exempt, - :purchase_order_number, - :md5_hash, - :card_code_response, - :cardholder_authentication_verification_response, - :solution_id, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - :account_number, - :card_type, - :split_tender_id, - :requested, - :balance_on_card, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil # Merchant defined fields come after this field (68) - ].freeze - - # Enumeration of the fields found in the card present AIM response. The index - # of the field name corresponds to its position (+ 1) in the card present AIM response. - CP_FIELDS = [ - :cp_version, - :response_code, - :response_reason_code, - :response_reason_text, - :authorization_code, - :avs_response, - :card_code_response, - :transaction_id, - :md5_hash, - :reference_id, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - nil, - :account_number, - :card_type, - :split_tender_id, - :requested, - :approved_amount, - :balance_on_card - ].freeze - end - end - - module SIM - # Contains the various lists of fields needed by the SIM API. - module Fields - # List of the fields found in a SIM response. Any field not in this list - # is treated as a Merchant Defined Field. - FIELDS = %i[ - x_response_code - x_response_subcode - x_response_reason_code - x_response_reason_text - x_auth_code - x_avs_code - x_trans_id - x_invoice_num - x_description - x_amount - x_method - x_type - x_cust_id - x_first_name - x_last_name - x_company - x_address - x_city - x_state - x_zip - x_country - x_phone - x_fax - x_email - x_ship_to_first_name - x_ship_to_last_name - x_ship_to_company - x_ship_to_address - x_ship_to_city - x_ship_to_state - x_ship_to_zip - x_ship_to_country - x_tax - x_duty - x_freight - x_tax_exempt - x_po_num - x_MD5_Hash - x_cvv2_resp_code - x_cavv_response - ].freeze - end - end - - module ARB - # Contains the various lists of fields needed by the ARB API. - module Fields - # Describes the order and nesting of fields in the ARB Subscription XML. - SUBSCRIPTION_FIELDS = { subscription: [ - { name: :subscription_name }, - { paymentSchedule: [ - { interval: [ - { length: :subscription_length }, - { unit: :subscription_unit } - ] }, - { startDate: :subscription_start_date }, - { totalOccurrences: :subscription_total_occurrences }, - { trialOccurrences: :subscription_trial_occurrences } - ] }, - { amount: :subscription_amount }, - { trialAmount: :subscription_trial_amount }, - { payment: [ - { creditCard: [ - { cardNumber: :card_num }, - { expirationDate: :exp_date }, - { cardCode: :card_code } - ] }, - { bankAccount: [ - { accountType: :bank_acct_type }, - { routingNumber: :bank_aba_code }, - { accountNumber: :bank_acct_num }, - { nameOnAccount: :bank_acct_name }, - { echeckType: :echeck_type }, - { bankName: :bank_name } - ] } - ] }, - { order: [ - { invoiceNumber: :invoice_num }, - { description: :description } - ] }, - { customer: [ - { id_: :cust_id }, - { email: :email }, - { phoneNumber: :phone }, - { faxNumber: :fax } - ] }, - { billTo: [ - { firstName: :first_name }, - { lastName: :last_name }, - { company: :company }, - { address: :address }, - { city: :city }, - { state: :state }, - { zip: :zip }, - { country: :country } - ] }, - { shipTo: [ - { firstName: :ship_to_first_name }, - { lastName: :ship_to_last_name }, - { company: :ship_to_company }, - { address: :ship_to_address }, - { city: :ship_to_city }, - { state: :ship_to_state }, - { zip: :ship_to_zip }, - { country: :ship_to_country } - ] } - ] }.freeze - - # Describes the order and nesting of fields in the ARB ARBCreateSubscriptionRequest XML. - CREATE_FIELDS = [ - { refId: :reference_id }, - SUBSCRIPTION_FIELDS - ].freeze - - # Describes the order and nesting of fields in the ARB ARBUpdateSubscriptionRequest XML. - UPDATE_FIELDS = [ - { refId: :reference_id }, - { subscriptionId: :subscription_id }, - SUBSCRIPTION_FIELDS - ].freeze - - # Describes the order and nesting of fields in the ARB ARBGetSubscriptionStatusRequest XML. - GET_STATUS_FIELDS = [ - { refId: :reference_id }, - { subscriptionId: :subscription_id } - ].freeze - - # Describes the order and nesting of fields in the ARB ARBCancelSubscriptionRequest XML. - CANCEL_FIELDS = [ - { refId: :reference_id }, - { subscriptionId: :subscription_id } - ].freeze - - # Describes the order and nesting of fields in the ARB ARBGetSubscriptionListRequest XML. - GET_SUBSCRIPTION_LIST_FIELDS = [ - { refId: :reference_id }, - { searchType: :search_type }, - { sorting: [ - { orderBy: :order_by }, - { orderDescending: :order_descending } - ] }, - { paging: [ - { limit: :limit }, - { offset: :offset } - ] } - ].freeze - - FIELDS = { - AuthorizeNet::XmlTransaction::Type::ARB_CREATE => CREATE_FIELDS, - AuthorizeNet::XmlTransaction::Type::ARB_UPDATE => UPDATE_FIELDS, - AuthorizeNet::XmlTransaction::Type::ARB_GET_STATUS => GET_STATUS_FIELDS, - AuthorizeNet::XmlTransaction::Type::ARB_CANCEL => CANCEL_FIELDS, - AuthorizeNet::XmlTransaction::Type::ARB_GET_SUBSCRIPTION_LIST => GET_SUBSCRIPTION_LIST_FIELDS - }.freeze - end - end - - module CIM - module Fields - REFID_FIELDS = { refId: :reference_id }.freeze - - VALIDATION_MODE_FIELDS = { validationMode: :validation_mode }.freeze - - CUSTOMER_PROFILE_ID_FIELDS = { customerProfileId: :customer_profile_id }.freeze - - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS = { customerPaymentProfileId: :customer_payment_profile_id }.freeze - - BILL_TO_FIELDS = { billTo: [ - { firstName: :first_name }, - { lastName: :last_name }, - { company: :company }, - { address: :address }, - { city: :city }, - { state: :state }, - { zip: :zip }, - { country: :country }, - { phoneNumber: :phone }, - { faxNumber: :fax } - ] }.freeze - - SHIP_TO_FIELDS = { shipTo: [ - { firstName: :ship_to_first_name }, - { lastName: :ship_to_last_name }, - { company: :ship_to_company }, - { address: :ship_to_address }, - { city: :ship_to_city }, - { state: :ship_to_state }, - { zip: :ship_to_zip }, - { country: :ship_to_country }, - { phoneNumber: :ship_to_phone }, - { faxNumber: :ship_to_fax } - ], _multivalue: :addresses }.freeze - - ADDRESS_FIELDS = { address: [ - { firstName: :first_name }, - { lastName: :last_name }, - { company: :company }, - { address: :address }, - { city: :city }, - { state: :state }, - { zip: :zip }, - { country: :country }, - { phoneNumber: :phone }, - { faxNumber: :fax } - ] }.freeze - - PAYMENT_PROFILE_FIELDS = [ - { customerType: :cust_type }, - BILL_TO_FIELDS, - { payment: [ - { creditCard: [ - { cardNumber: :card_num }, - { expirationDate: :exp_date }, - { cardCode: :card_code } - ] }, - { bankAccount: [ - { accountType: :bank_acct_type }, - { routingNumber: :bank_aba_code }, - { accountNumber: :bank_acct_num }, - { nameOnAccount: :bank_acct_name }, - { echeckType: :echeck_type }, - { bankName: :bank_name } - ] } - ] } - ].freeze - - PROFILE_FIELDS = { profile: [ - { merchantCustomerId: :cust_id }, - { description: :description }, - { email: :email }, - { paymentProfiles: PAYMENT_PROFILE_FIELDS, _multivalue: :payment_profiles }, - SHIP_TO_FIELDS - ] }.freeze - - TRANSACTION_FIELDS = [ - { amount: :amount }, - { tax: [ - { amount: :tax }, - { name: :tax_name }, - { description: :tax_description } - ] }, - { shipping: [ - { amount: :freight }, - { name: :freight_name }, - { description: :freight_description } - ] }, - { duty: [ - { amount: :duty }, - { name: :duty_name }, - { description: :duty_description } - ] }, - { lineItems: [ - { itemId: :line_item_id }, - { name: :line_item_name }, - { description: :line_item_description }, - { quantity: :line_item_quantity }, - { unitPrice: :line_item_unit_price }, - { taxable: :line_item_taxable } - ], _multivalue: :line_items }, - CUSTOMER_PROFILE_ID_FIELDS, - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS, - { customerShippingAddressId: :customer_address_id }, - { creditCardNumberMasked: :card_num_masked }, - { bankRoutingNumberMasked: :bank_aba_code_masked }, - { bankAccountNumberMasked: :bank_acct_num_masked }, - { order: [ - { invoiceNumber: :invoice_num }, - { description: :description }, - { purchaseOrderNumber: :po_num } - ] }, - { taxExempt: :tax_exempt }, - { recurringBilling: :recurring_billing }, - { cardCode: :card_code }, - { splitTenderId: :split_tender_id }, - { approvalCode: :auth_code }, - { transId: :trans_id } - ].freeze - - TRANSACTION_AUTH_FIELDS = [ - { profileTransAuthOnly: TRANSACTION_FIELDS } - ].freeze - - TRANSACTION_AUTH_CAPTURE_FIELDS = [ - { profileTransAuthCapture: TRANSACTION_FIELDS } - ].freeze - - TRANSACTION_CAPTURE_FIELDS = [ - { profileTransCaptureOnly: TRANSACTION_FIELDS } - ].freeze - - TRANSACTION_PRIOR_AUTH_CAPTURE_FIELDS = [ - { profileTransPriorAuthCapture: TRANSACTION_FIELDS } - ].freeze - - TRANSACTION_REFUND_FIELDS = [ - { profileTransRefund: TRANSACTION_FIELDS } - ].freeze - - TRANSACTION_VOID_FIELDS = [ - { profileTransVoid: [ - CUSTOMER_PROFILE_ID_FIELDS, - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS, - { transId: :trans_id } - ] } - ].freeze - - CREATE_PROFILE_FIELDS = [ - REFID_FIELDS, - PROFILE_FIELDS, - VALIDATION_MODE_FIELDS - ].freeze - - CREATE_PAYMENT_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - { paymentProfile: PAYMENT_PROFILE_FIELDS }, - VALIDATION_MODE_FIELDS - ].freeze - - CREATE_ADDRESS_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - ADDRESS_FIELDS - ].freeze - - CREATE_TRANSACTION_FIELDS = [ - REFID_FIELDS, - { transaction: [], _conditional: :select_transaction_type_fields }, - { extraOptions: :extra_options } - ].freeze - - DELETE_PROFILE_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS - ].freeze - - DELETE_PAYMENT_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS - ].freeze - - DELETE_ADDRESS_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - { customerAddressId: :customer_address_id } - ].freeze - - GET_PROFILE_IDS_FIELDS = [].freeze - - GET_PROFILE_FIELDS = [ - CUSTOMER_PROFILE_ID_FIELDS - ].freeze - - GET_PAYMENT_FIELDS = [ - CUSTOMER_PROFILE_ID_FIELDS, - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS - ].freeze - - GET_ADDRESS_FIELDS = [ - CUSTOMER_PROFILE_ID_FIELDS, - { customerAddressId: :customer_address_id } - ].freeze - - GET_HOSTED_PROFILE_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - { hostedProfileSettings: [{ setting: [{ settingName: :setting_name }, { settingValue: :setting_value }], _multivalue: :hosted_settings }] } - ].freeze - - UPDATE_PROFILE_FIELDS = [ - REFID_FIELDS, - { profile: [ - { merchantCustomerId: :cust_id }, - { description: :description }, - { email: :email }, - CUSTOMER_PROFILE_ID_FIELDS - ] } - ].freeze - - UPDATE_PAYMENT_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - { paymentProfile: PAYMENT_PROFILE_FIELDS + [CUSTOMER_PAYMENT_PROFILE_ID_FIELDS] }, - VALIDATION_MODE_FIELDS - ].freeze - - UPDATE_ADDRESS_FIELDS = [ - REFID_FIELDS, - CUSTOMER_PROFILE_ID_FIELDS, - { address: [ - { firstName: :first_name }, - { lastName: :last_name }, - { company: :company }, - { address: :address }, - { city: :city }, - { state: :state }, - { zip: :zip }, - { country: :country }, - { phoneNumber: :phone }, - { faxNumber: :fax }, - { customerAddressId: :customer_address_id } - ] } - ].freeze - - UPDATE_SPLIT_FIELDS = [ - { splitTenderId: :split_tender_id }, - { splitTenderStatus: :split_tender_status } - ].freeze - - VALIDATE_PAYMENT_FIELDS = [ - CUSTOMER_PROFILE_ID_FIELDS, - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS, - { customerShippingAddressId: :customer_address_id }, - { cardCode: :card_code }, - VALIDATION_MODE_FIELDS - ].freeze - - FIELDS = { - AuthorizeNet::XmlTransaction::Type::CIM_CREATE_PROFILE => CREATE_PROFILE_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_CREATE_PAYMENT => CREATE_PAYMENT_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_CREATE_ADDRESS => CREATE_ADDRESS_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_CREATE_TRANSACTION => CREATE_TRANSACTION_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_DELETE_PROFILE => DELETE_PROFILE_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_DELETE_PAYMENT => DELETE_PAYMENT_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_DELETE_ADDRESS => DELETE_ADDRESS_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_GET_PROFILE_IDS => GET_PROFILE_IDS_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_GET_PROFILE => GET_PROFILE_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_GET_PAYMENT => GET_PAYMENT_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_GET_ADDRESS => GET_ADDRESS_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_GET_HOSTED_PROFILE => GET_HOSTED_PROFILE_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_UPDATE_PROFILE => UPDATE_PROFILE_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_UPDATE_PAYMENT => UPDATE_PAYMENT_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_UPDATE_ADDRESS => UPDATE_ADDRESS_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_UPDATE_SPLIT => UPDATE_SPLIT_FIELDS, - AuthorizeNet::XmlTransaction::Type::CIM_VALIDATE_PAYMENT => VALIDATE_PAYMENT_FIELDS - }.freeze - - ADDRESS_ENTITY_DESCRIPTION = EntityDescription.new( - [ - { firstName: :first_name }, - { lastName: :last_name }, - { company: :company }, - { address: :street_address }, - { city: :city }, - { state: :state }, - { zip: :zip }, - { country: :country }, - { phoneNumber: :phone }, - { faxNumber: :fax } - ], - AuthorizeNet::Address - ) - - CREDIT_CARD_ENTITY_DESCRIPTION = EntityDescription.new( - [ - { cardNumber: :card_num }, - { expirationDate: :exp_date }, - { cardCode: :card_code }, - { cardType: :card_type } - ], - AuthorizeNet::CreditCard, - %i[card_num exp_date] - ) - - ECHECK_ENTITY_DESCRIPTION = EntityDescription.new( - [ - { accountType: :account_type }, - { routingNumber: :routing_number }, - { accountNumber: :account_number }, - { nameOnAccount: :account_holder_name }, - { echeckType: :echeck_type }, - { bankName: :bank_name } - ], - AuthorizeNet::ECheck, - %i[routing_number account_number bank_name account_holder_name] - ) - - PAYMENT_PROFILE_ENTITY_DESCRIPTION = EntityDescription.new( - [ - CUSTOMER_PAYMENT_PROFILE_ID_FIELDS, - { customerType: :cust_type }, - { billTo: ADDRESS_ENTITY_DESCRIPTION, _value: :billing_address }, - { payment: [ - { creditCard: CREDIT_CARD_ENTITY_DESCRIPTION, _value: :payment_method }, - { bankAccount: ECHECK_ENTITY_DESCRIPTION, _value: :payment_method } - ] } - ], - AuthorizeNet::CIM::PaymentProfile - ) - - PROFILE_ENTITY_DESCRIPTION = EntityDescription.new( - [ - { merchantCustomerId: :id }, - { description: :description }, - { email: :email }, - CUSTOMER_PROFILE_ID_FIELDS, - { paymentProfiles: PAYMENT_PROFILE_ENTITY_DESCRIPTION, _multivalue: :payment_profiles }, - { shipTo: ADDRESS_ENTITY_DESCRIPTION, _multivalue: :addresses } - ], - AuthorizeNet::CIM::CustomerProfile - ) - end - end - - module Reporting - module Fields - GET_BATCH_LIST = [ - { includeStatistics: :include_statistics }, - { firstSettlementDate: :first_settlement_date }, - { lastSettlementDate: :last_settlement_date } - ].freeze - - GET_TRANSACTION_LIST = [ - { batchId: :batch_id } - ].freeze - - GET_UNSETTLED_TRANSACTION_LIST = [ - ].freeze - - GET_TRANSACTION_DETAILS = [ - { transId: :transaction_id } - ].freeze - - BATCH_STATISTICS_ENTITY_DESCRIPTION = EntityDescription.new([ - { accountType: :account_type }, - { chargeAmount: :charge_amount, _converter: :value_to_decimal }, - { chargeCount: :charge_count, _converter: :value_to_integer }, - { refundAmount: :refund_amount, _converter: :value_to_decimal }, - { refundCount: :refund_count, _converter: :value_to_integer }, - { voidCount: :void_count, _converter: :value_to_integer }, - { declineCount: :decline_count, _converter: :value_to_integer }, - { errorCount: :error_count, _converter: :value_to_integer }, - { returnedItemAmount: :returned_item_amount, _converter: :value_to_decimal }, - { returnedItemCount: :returned_item_count, _converter: :value_to_integer }, - { chargebackAmount: :chargeback_amount, _converter: :value_to_decimal }, - { chargebackCount: :chargeback_count, _converter: :value_to_integer }, - { correctionNoticeCount: :correction_notice_count, _converter: :value_to_integer }, - { chargeChargeBackAmount: :charge_chargeback_amount, _converter: :value_to_decimal }, - { chargeChargeBackCount: :charge_chargeback_count, _converter: :value_to_integer }, - { refundChargeBackAmount: :refund_chargeback_amount, _converter: :value_to_decimal }, - { refundChargeBackCount: :refund_chargeback_count, _converter: :value_to_integer }, - { chargeReturnedItemsAmount: :charge_returned_items_amount, _converter: :value_to_decimal }, - { chargeReturnedItemsCount: :charge_returned_items_count, _converter: :value_to_integer }, - { refundReturnedItemsAmount: :refund_returned_items_amount, _converter: :value_to_decimal }, - { refundReturnedItemsCount: :refund_returned_items_count, _converter: :value_to_integer } - ], - AuthorizeNet::Reporting::BatchStatistics) - - BATCH_ENTITY_DESCRIPTION = EntityDescription.new([ - { batchId: :id }, - { settlementTimeUTC: :settled_at, _converter: :value_to_datetime }, - { settlementState: :state }, - { paymentMethod: :payment_method }, - { statistics: [{ statistic: BATCH_STATISTICS_ENTITY_DESCRIPTION, _multivalue: :statistics }] } - ], - AuthorizeNet::Reporting::Batch) - - FDSFILTER_ENTITY_DESCRIPTION = EntityDescription.new([ - { name: :name }, - { action: :action } - ], - AuthorizeNet::Reporting::FDSFilter) - - CUSTOMER_ENTITY_DESCRIPTION = EntityDescription.new([ - { id: :id }, - { email: :email } - ], - AuthorizeNet::CIM::CustomerProfile) - - ORDER_ENTITY_DESCRIPTION = EntityDescription.new([ - { invoice_number: :invoice_num }, - { description: :description }, - { purchaseOrderNumber: :po_num } - ], - AuthorizeNet::Order) - - LINE_ITEM_ENTITY_DESCRIPTION = EntityDescription.new([ - { itemId: :id }, - { name: :name }, - { description: :description }, - { quantity: :quantity, _convert: :value_to_integer }, - { unityPrice: :price, _convert: :value_to_decimal }, - { taxable: :taxable, _convert: :value_to_boolean } - ], - AuthorizeNet::LineItem) - - attr_accessor :id, :date_utc, :date_local, :code, :description - RETURNED_ITEM_ENTITY_DESCRIPTION = EntityDescription.new([ - { id: :id }, - { dateUTC: :date_utc }, - { dateLocal: :date_local }, - { code: :code }, - { description: :description } - ], - AuthorizeNet::Reporting::ReturnedItem) - - TRANSACTION_DETAILS_ENTITY_DESCRIPTION = EntityDescription.new([ - { transId: :id }, - { refTransId: :reference_id }, - { splitTenderId: :split_tender_id }, - { transactionType: :type }, - { responseCode: :response_code }, - { responseReasonCode: :response_reason_code }, - { authCode: :auth_code }, - { AVSResponse: :avs_response }, - { cardCodeResponse: :card_code_response }, - { CAVVResponse: :cavv_response }, - { FDSFilterAction: :fds_filter_action }, - { FDSFilters: [{ FDSFilter: FDSFILTER_ENTITY_DESCRIPTION, _multivalue: :fds_filters }] }, - { batch: BATCH_ENTITY_DESCRIPTION, _value: :batch }, - { responseReasonDescription: :response_reason_description }, - { submitTimeUTC: :submitted_at, _converter: :value_to_datetime }, - { transactionStatus: :status }, - { accountType: :account_type }, - { accountNumber: :account_number }, - { order: ORDER_ENTITY_DESCRIPTION, _value: :order }, - { requestedAmount: :requested_amount, _converter: :value_to_decimal }, - { authAmount: :auth_amount, _converter: :value_to_decimal }, - { settleAmount: :settle_amount, _converter: :value_to_decimal }, - { prepaidBalanceRemaining: :prepaid_balance_remaining, _converter: :value_to_decimal }, - { payment: [ - { creditCard: AuthorizeNet::CIM::Fields::CREDIT_CARD_ENTITY_DESCRIPTION, _value: :payment_method }, - { bankAccount: AuthorizeNet::CIM::Fields::ECHECK_ENTITY_DESCRIPTION, _value: :payment_method } - ] }, - { customer: CUSTOMER_ENTITY_DESCRIPTION, _value: :customer }, - { billTo: AuthorizeNet::CIM::Fields::ADDRESS_ENTITY_DESCRIPTION, _value: :bill_to }, - { shipTo: AuthorizeNet::CIM::Fields::ADDRESS_ENTITY_DESCRIPTION, _value: :ship_to }, - { recurringBilling: :recurring_billing, _convert: :value_to_boolean }, - { hasReturnedItems: :returns, _convert: :value_to_boolean } - ], - AuthorizeNet::Reporting::TransactionDetails) - - FIELDS = { - AuthorizeNet::XmlTransaction::Type::REPORT_GET_BATCH_LIST => GET_BATCH_LIST, - AuthorizeNet::XmlTransaction::Type::REPORT_GET_TRANSACTION_LIST => GET_TRANSACTION_LIST, - AuthorizeNet::XmlTransaction::Type::REPORT_GET_UNSETTLED_TRANSACTION_LIST => GET_UNSETTLED_TRANSACTION_LIST, - AuthorizeNet::XmlTransaction::Type::REPORT_GET_TRANSACTION_DETAILS => GET_TRANSACTION_DETAILS - }.freeze - end - end -end diff --git a/lib/authorize_net/key_value_response.rb b/lib/authorize_net/key_value_response.rb deleted file mode 100644 index 355d3d6..0000000 --- a/lib/authorize_net/key_value_response.rb +++ /dev/null @@ -1,109 +0,0 @@ -module AuthorizeNet - # The core, key/value response class. You shouldn't instantiate this one. - # Instead you should use AuthorizeNet::AIM::Response or AuthorizeNet::SIM::Response. - class KeyValueResponse < AuthorizeNet::Response - # Defines constants for each response code. - module ResponseCode - APPROVED = '1'.freeze - DECLINED = '2'.freeze - ERROR = '3'.freeze - HELD = '4'.freeze - end - - # Defines constants for each address verification response code. - module AVSResponseCode - ADDRESS_MATCH_NOT_ZIP = 'A'.freeze - NO_INFO = 'B'.freeze - ERROR = 'E'.freeze - NON_US = 'G'.freeze - NO_MATCH = 'N'.freeze - NOT_APPLICABLE = 'P'.freeze - RETRY = 'R'.freeze - NOT_SUPPOPRTED = 'S'.freeze - UNAVAILABLE = 'U'.freeze - ZIP9_MATCH_NOT_ADDRESS = 'W'.freeze - ADDRESS_AND_ZIP9_MATCH = 'X'.freeze - ADDRESS_AND_ZIP5_MATCH = 'Y'.freeze - ZIP5_MATCH_NOT_ADDRESS = 'Z'.freeze - end - - # Defines constants for each supported credit card type. - module CardType - VISA = 'Visa'.freeze - MASTER_CARD = 'MasterCard'.freeze - AMEX = 'American Express'.freeze - DISCOVER = 'Discover'.freeze - DINERS_CLUB = 'Diners Club'.freeze - JCB = 'JCB'.freeze - end - - # Defines constants for CCV code validation responses. - module CCVResponseCode - MATCH = 'M'.freeze - NO_MATCH = 'N'.freeze - NOT_PROCESSED = 'P'.freeze - SHOULD_HAVE_BEEN_PRESENT = 'S'.freeze - UNABLE_TO_PROCESS = 'U'.freeze - end - - # Defines constants for CAVV code validation responses. - module CAVVResponseCode - ERRONEOUS_DATA = '0'.freeze - FAILED_VALIDATION = '1'.freeze - PASSED_VALIDATION = '2'.freeze - ISSUER_ATTEMPT_INCOMPLETE = '3'.freeze - ISSUER_SYSTEM_ERROR = '4'.freeze - FAILED_ISSUER_AVAILABLE = '7'.freeze - PASSED_ISSUER_AVAILABLE = '8'.freeze - FAILED_ISSUER_UNAVAILABLE = '9'.freeze - PASSED_ISSUER_UNAVAILABLE = 'A'.freeze - PASSED_NO_LIABILITY_SHIFT = 'B'.freeze - end - - # Check to see if the transaction was approved. - def approved? - @fields[:response_code] == ResponseCode::APPROVED - end - - # Check to see if the transaction was declined. - def declined? - @fields[:response_code] == ResponseCode::DECLINED - end - - # Check to see if the transaction was returned with an error. - def error? - @fields[:response_code] == ResponseCode::ERROR - end - - # Check to see if the transaction was held for review by Authorize.Net. - def held? - @fields[:response_code] == ResponseCode::HELD - end - - # Returns the response code received from the gateway. Note: its better to use - # success?, approved?, etc. to check the response code. - def response_code - @fields[:response_code] - end - - # Returns the response reason code received from the gateway. This code can be used - # to identify why something failed by referencing the AIM documentation. - def response_reason_code - @fields[:response_reason_code] - end - - # Returns the response reason text received from the gateway. This is a brief, human readable - # explanation of why you got the response code that you got. Note that these strings tend to be - # a bit vague. More detail can be gleaned from the response_reason_code. - def response_reason_text - @fields[:response_reason_text] - end - - # Returns all the fields returned in the response, keyed by their API name. Custom fields are NOT - # included (see custom_fields). - attr_reader :fields - - # Returns all the custom fields returned in the response, keyed by their field name. - attr_reader :custom_fields - end -end diff --git a/lib/authorize_net/key_value_transaction.rb b/lib/authorize_net/key_value_transaction.rb deleted file mode 100644 index 76f7b09..0000000 --- a/lib/authorize_net/key_value_transaction.rb +++ /dev/null @@ -1,281 +0,0 @@ -module AuthorizeNet - # The core, key/value transaction class. You shouldn't instantiate this one. - # Instead you should use AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction. - class KeyValueTransaction < AuthorizeNet::Transaction - # Constants for both the various Authorize.Net payment gateways are defined here. - module Gateway - LIVE = 'https://secure2.authorize.net/gateway/transact.dll'.freeze - TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze - CARD_PRESENT_LIVE = 'https://cardpresent.authorize.net/gateway/transact.dll'.freeze - CARD_PRESENT_TEST = 'https://test.authorize.net/gateway/transact.dll'.freeze - end - - # Constants for both the various Authorize.Net payment transaction types are defined here. - module Type - AUTHORIZE_AND_CAPTURE = "AUTH_CAPTURE".freeze - AUTHORIZE_ONLY = "AUTH_ONLY".freeze - CAPTURE_ONLY = "CAPTURE_ONLY".freeze - CREDIT = "CREDIT".freeze - PRIOR_AUTHORIZATION_AND_CAPTURE = "PRIOR_AUTH_CAPTURE".freeze - VOID = "VOID".freeze - end - - # Constants for the various device types used in card present transactions. - module DeviceType - UNKNOWN = 1 - UNATTENDED = 2 - SELF_SERVICE = 3 - CASH_REGISTER = 4 - PC_TERMINAL = 5 - AIRPAY = 6 - WIRELESS_POS = 7 - WEBSITE_TERMINAL = 8 - DIAL_TERMINAL = 9 - VIRTUAL_TERMINAL = 10 - end - - # Constants for the various market types used in card present transactions. - module MarketType - RETAIL = 2 - end - - # The default options for purchase. - @@purchase_option_defaults = { - cardholder_auth_value: nil, - cardholder_auth_indicator: nil - } - - # The default options for authorize. - @@authorize_option_defaults = { - cardholder_auth_value: nil, - cardholder_auth_indicator: nil - } - - # Fields to convert to/from booleans. - @@boolean_fields = [] - - # Fields to convert to/from BigDecimal. - @@decimal_fields = [] - - # DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction or AuthorizeNet::SIM::Transaction instead. - def initialize - super - @custom_fields ||= {} - @test_mode ||= false - @version = '3.1' - end - - # Checks if the transaction has been configured for test mode or not. Return TRUE if the - # transaction is a test transaction, FALSE otherwise. All transactions run against the sandbox - # are considered test transactions. - def test? - !!@test_mode - end - - # Returns the current API version that we are adhering to - attr_reader :version - - # Sets arbitrary custom fields, overwriting existing values if they exist. Takes a hash of key/value pairs, - # where the keys are the field names. You can set a field to Nil to unset it. - def set_custom_fields(fields = {}) - @custom_fields.merge!(fields) - end - - # Returns the current hash of custom fields. - attr_reader :custom_fields - - # Convenience method for adding line items to a transaction. - def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) - line_item = "#{id}<|>#{name}<|>#{description}<|>#{quantity}<|>#{price}<|>#{taxable}" - if @fields.key?(:line_item) - @fields[:line_item] = @fields[:line_item].to_a << line_item - else - @fields[:line_item] = [line_item] - end - end - - # Takes an instance of AuthorizeNet::EmailReceipt and adds it to the transaction. - def set_email_receipt(email) - @fields.merge!(email.to_hash) - end - - # Returns the type of transaction. - attr_reader :type - - # Sets the type of transaction. - def type=(type) - case type - when :authorize, :auth_only - @type = Type::AUTHORIZE_ONLY - when :purchase, :auth_and_capture - @type = Type::AUTHORIZE_AND_CAPTURE - when :refund, :credit - @type = Type::CREDIT - when :void - @type = Type::VOID - when :capture, :capture_only - @type = Type::CAPTURE_ONLY - when :prior_auth_capture - @type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE - else - @type = type - end - end - - # Sets up and submits a standard purchase (AUTHORIZE_AND_CAPTURE) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. - # - # +amount+:: The amount to charge. Accepts a string in the format "%0.2f", a Float or a BigDecimal. - # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields). - # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases. - # - # - # Typical usage: - # - # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120') - # response = transaction.purchase(10.0, credit_card) - # - def purchase(amount, credit_card, options = {}) - handle_payment_argument(credit_card) - options = @@purchase_option_defaults.merge(options) - handle_cavv_options(options) - set_fields(amount: amount) - self.type = Type::AUTHORIZE_AND_CAPTURE - run - end - - # Sets up and submits a refund (CREDIT) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. - # - # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal. - # +transaction+:: The transaction ID to apply the refund to. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response. - # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. In many cases you only need the last 4 digits of the credit card here. - # - # - # Typical usage: - # - # response = transaction.refund(10.0, '123456789', '1212') - # - def refund(amount, transaction, credit_card) - handle_payment_argument(credit_card) - handle_transaction_argument(transaction) - set_fields(amount: amount) - self.type = Type::CREDIT - run - end - - # Sets up and submits a refund (CREDIT) transaction for a transaction that was not originally - # submitted via the payment gateway. Note that this is a special feature which requires your - # account to support ECC (expanded credits capability) transactions. - # - # +amount+:: The amount to refund. Accepts a string in the format "%0.2f", a Float or a BigDecimal. - # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits. - # - # Typical usage: - # - # response = transaction.unlinked_credit(10.0, '4111111111111111') - # - def unlinked_credit(amount, credit_card) - handle_payment_argument(credit_card) - set_fields(amount: amount) - self.type = Type::CREDIT - run - end - - # Sets up and submits a void (VOID) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. Note that you can only void unsettled transactions. - # - # +transaction+:: The transaction ID of the transaction to void. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response. - # - # - # Typical usage: - # - # response = transaction.void('123456789') - # - def void(transaction) - handle_transaction_argument(transaction) - self.type = Type::VOID - run - end - - # Sets up and submits an authorize (AUTH_ONLY) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. Use this to put a hold on funds, but don't actually charge - # the card yet. - # - # +amount+:: The amount to authorize. Accepts a string in the format "%0.2f", a Float or a BigDecimal. - # +credit_card+:: The credit card or eCheck to charge. Accepts an instance of AuthorizeNet::CreditCard, AuthorizeNet::ECheck, or a string of digits (in which case the expiration should be added using set_fields). - # +options+:: A hash with any of following keys: cardholder_auth_indicator, cardholder_auth_value. These are for CAVV and can be ignored in most cases. - # - # - # Typical usage: - # - # credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120') - # response = transaction.authorize(10.0, credit_card) - # - def authorize(amount, credit_card, options = {}) - handle_payment_argument(credit_card) - options = @@authorize_option_defaults.merge(options) - handle_cavv_options(options) - set_fields(amount: amount) - self.type = Type::AUTHORIZE_ONLY - run - end - - # Sets up and submits a capture (CAPTURE_ONLY) transaction. Returns a response object. If the transaction - # has already been run, it will return nil. Note that you can not capture a transaction that was made - # though the AIM API using this method. Use prior_auth_capture instead. - # - # +amount+:: The amount to capture. Accepts a string in the format "%0.2f", a Float or a BigDecimal. - # +authorization_code+:: The authorization code of the transaction to capture. Accepts a string. - # - # - # Typical usage: - # - # response = transaction.capture(10.0, '123FAKE') - # - def capture(amount, authorization_code) - set_fields(amount: amount, auth_code: authorization_code) - self.type = Type::CAPTURE_ONLY - run - end - - # Sets up and submits a capture (PRIOR_AUTH_CAPTURE) transaction. Returns a response object. Use this method - # to actually charge a card that you previously put a hold on (using authorize). - # - # +transaction+:: The transaction ID to capture. Accepts a string of the transaction ID, an instance of AuthorizeNet::Transaction or AuthorizeNet::Response. - # +amount+:: The amount to capture (only if less than the amount originally authorized, otherwise leave as Nil). Accepts a string in the format "%0.2f", a Float, a BigDecimal or Nil. - # - # - # Typical usage: - # - # response = transaction.prior_auth_capture('123456789') - # - def prior_auth_capture(transaction, amount = nil) - handle_transaction_argument(transaction) - set_fields(amount: amount) - self.type = Type::PRIOR_AUTHORIZATION_AND_CAPTURE - run - end - - #:enddoc: - protected - - # Internal method to handle multiple types of transaction arguments. - def handle_transaction_argument(transaction) - case transaction - when Transaction - set_fields(trans_id: transaction.response.transaction_id) - when Response - set_fields(trans_id: transaction.transaction_id) - else - set_fields(trans_id: transaction) - end - end - - # Internal method to handle CAVV options. - def handle_cavv_options(options) - set_fields(authentication_indicator: options[:cardholder_auth_indicator]) unless options[:cardholder_auth_indicator].nil? - set_fields(cardholder_authentication_value: options[:cardholder_auth_value]) unless options[:cardholder_auth_value].nil? - end - end -end diff --git a/lib/authorize_net/line_item.rb b/lib/authorize_net/line_item.rb deleted file mode 100644 index c547187..0000000 --- a/lib/authorize_net/line_item.rb +++ /dev/null @@ -1,21 +0,0 @@ -module AuthorizeNet - # Models an line item. - class LineItem - include AuthorizeNet::Model - - attr_accessor :id, :name, :description, :quantity, :price, :taxable - - def to_hash - hash = { - line_item_id: @id, - line_item_name: @name, - line_item_description: @description, - line_item_quantity: @quantity, - line_item_unit_price: @price, - line_item_taxable: @taxable - } - hash.delete_if { |_k, v| v.nil? } - hash - end - end -end diff --git a/lib/authorize_net/order.rb b/lib/authorize_net/order.rb deleted file mode 100644 index 4603511..0000000 --- a/lib/authorize_net/order.rb +++ /dev/null @@ -1,38 +0,0 @@ -module AuthorizeNet - # Models an order. - class Order - include AuthorizeNet::Model - - attr_accessor :invoice_num, :description, :tax, :tax_name, :tax_description, :freight, :freight_name, :freight_description, :duty, :duty_name, :duty_description, :tax_exempt, :po_num, :line_items - - def add_line_item(id = nil, name = nil, description = nil, quantity = nil, price = nil, taxable = nil) - if id.is_a?(AuthorizeNet::LineItem) - line_item = id - else - line_item = AuthorizeNet::LineItem.new(id: id, name: name, description: description, quantity: quantity, price: price, taxable: taxable) - end - @line_items = @line_items.to_a << line_item - end - - def to_hash - hash = { - invoice_num: @invoice_num, - description: @description, - tax: @tax, - tax_name: @tax_name, - tax_description: @tax_description, - freight: @freight, - freight_name: @freight_name, - freight_description: @freight_description, - duty: @duty, - duty_name: @duty_name, - duty_description: @duty_description, - tax_exempt: @tax_exempt, - po_num: @po_num, - line_items: handle_multivalue_hashing(@line_items) - } - hash.delete_if { |_k, v| v.nil? } - hash - end - end -end diff --git a/lib/authorize_net/payment_methods/credit_card.rb b/lib/authorize_net/payment_methods/credit_card.rb deleted file mode 100644 index 9904ffa..0000000 --- a/lib/authorize_net/payment_methods/credit_card.rb +++ /dev/null @@ -1,61 +0,0 @@ -module AuthorizeNet - # Defines constants for each payment method type. - module PaymentMethodType - CREDIT_CARD = 'CC'.freeze - end - - # Models a credit card. - class CreditCard - PAYMENT_METHOD_CODE = AuthorizeNet::PaymentMethodType::CREDIT_CARD - - # The option defaults for the constructor. - @@option_defaults = { - card_code: nil, - card_type: nil - } - - attr_accessor :card_number, :expiration, :card_code, :card_type, :track_1, :track_2 - - # Constructs a new credit card object. Takes a credit card number - # and an expiration date. The CCV code can be passed as an option. So can - # the data tracks (1 & 2). When passing in data tracks, please pass the - # whole track. Sentinels and the LRC will be removed by the SDK. Track data - # must be passed along as ASCII. The raw bit stream from the card is not acceptable. - # - # Field separators on - # - # +card_number+:: The credit card number as a string. - # +expiration+:: The credit card expiration date as a string with format MMYY. - # +options+:: A hash of options. - # - # Options - # +card_code+:: Sets the CCV code for the credit card. - # +card_type+:: Sets the type of card (Visa, MasterCard, Dinners Club, etc.) - # +track_1+:: Sets the track 1 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change). - # +track_2+:: Sets the track 2 data. Either track 1 or track 2 data needs to be included for card present transactions (otherwise fee structure will change). - # - # - def initialize(card_number, expiration, options = {}) - @card_number = card_number - @expiration = expiration - options = @@option_defaults.merge(options) - @card_code = options[:card_code] - @card_type = options[:card_type] - @track_1 = options[:track_1] - @track_2 = options[:track_2] - end - - def to_hash - {}.tap do |ch| - ch[:method] = PAYMENT_METHOD_CODE - ch[:card_num] = @card_number - ch[:exp_date] = @expiration - ch[:card_code] = @card_code if @card_code - ch[:track1] = @track_1.match(/(%|^)(.*?)(\?|$)/)[2] if @track_1 - ch[:track2] = @track_2.match(/(;|^)(.*?)(\?|$)/)[2] if @track_2 - # ch[:track1] = @track_1.match(/^%(?.)(?

[\d]{1,19}+)\^(?.{2,26})\^(?[\d]{0,4}|\^)(?[\d]{0,3}|\^)(?

.*)\?\Z/) if @track_1 - # ch[:track2] = @track_2.match(/\A;(?[\d]{1,19}+)=(?[\d]{0,4}|=)(?[\d]{0,3}|=)(?.*)\?\Z/) if @track_2 - end - end - end -end diff --git a/lib/authorize_net/payment_methods/echeck.rb b/lib/authorize_net/payment_methods/echeck.rb deleted file mode 100644 index c17d9fe..0000000 --- a/lib/authorize_net/payment_methods/echeck.rb +++ /dev/null @@ -1,70 +0,0 @@ -module AuthorizeNet - # Defines constants for each payment method type. - module PaymentMethodType - ECHECK = 'ECHECK'.freeze - end - - # Models an eCheck. - class ECheck - PAYMENT_METHOD_CODE = AuthorizeNet::PaymentMethodType::ECHECK - - # Defines constants for each bank account type. - module AccountType - CHECKING = 'CHECKING'.freeze - SAVINGS = 'SAVINGS'.freeze - BUSINESS_CHECKING = 'BUSINESSCHECKING'.freeze - end - - # Defines constants for each check type. - module CheckType - ACCOUNTS_RECEIVABLE_CONVERSION = 'ARC'.freeze - BACK_OFFICE_CONVERSION = 'BOC'.freeze - CASH_CONCENTRATION_DISBURSEMENT = 'CCD'.freeze - PREARRANGED_PAYMENT_DEPOSIT = 'PPD'.freeze - TELEPHONE_INITIATED = 'TEL'.freeze - INTERNET_INITIATED = 'WEB'.freeze - end - - # The option defaults for the constructor. - @@option_defaults = { - echeck_type: CheckType::INTERNET_INITIATED, - check_number: nil, - account_type: AccountType::CHECKING - } - - attr_accessor :routing_number, :account_number, :bank_name, :account_holder_name, :echeck_type, :check_number, :account_type - - # Constructs a new eCheck object. - # - # +routing_number+:: The bank routing number as a string. - # +account_number+:: The bank account number as a string. - # +bank_name+:: The legal name of the bank. This should match the name associated with the +routing_number+. - # +account_holder_name+:: The full name on the bank account represented by +account_number+. - # +options+:: A hash of options. Accepts +echeck_type+ (the type of check, can usually be ignored), +check_number+ (the number on the check, only needed for some check types), and +account_type+ (the type of bank account the check draws from). All values should be passed as strings. - # - def initialize(routing_number, account_number, bank_name, account_holder_name, options = {}) - @routing_number = routing_number - @account_number = account_number - @bank_name = bank_name - @account_holder_name = account_holder_name - options = @@option_defaults.merge(options) - @echeck_type = options[:echeck_type] - @check_number = options[:check_number] - @account_type = options[:account_type] - end - - def to_hash - hash = { - method: PAYMENT_METHOD_CODE, - bank_aba_code: @routing_number, - bank_acct_num: @account_number, - bank_acct_type: @account_type, - bank_name: @bank_name, - bank_acct_name: @account_holder_name, - echeck_type: @echeck_type - } - hash[:bank_check_number] = @check_number unless @check_number.nil? - hash - end - end -end diff --git a/lib/authorize_net/reporting/batch.rb b/lib/authorize_net/reporting/batch.rb deleted file mode 100644 index 501ab06..0000000 --- a/lib/authorize_net/reporting/batch.rb +++ /dev/null @@ -1,16 +0,0 @@ -module AuthorizeNet::Reporting - # Models a batch of credit cards. - class Batch - include AuthorizeNet::Model - - attr_accessor :id, :settled_at, :state, :statistics, :payment_method - - def settled_at=(time) - if time.is_a?(DateTime) - @settled_at = time - else - @settled_at = DateTime.parse(time.to_s) - end - end - end -end diff --git a/lib/authorize_net/reporting/batch_statistics.rb b/lib/authorize_net/reporting/batch_statistics.rb deleted file mode 100644 index 19e29d8..0000000 --- a/lib/authorize_net/reporting/batch_statistics.rb +++ /dev/null @@ -1,15 +0,0 @@ -module AuthorizeNet::Reporting - # Models a batch of credit cards. - class BatchStatistics - include AuthorizeNet::Model - - attr_accessor :account_type, :charge_count, :charge_amount, :refund_count, - :refund_amount, :void_count, :decline_count, :error_count, - :returned_item_amount, :returned_item_count, :chargeback_count, - :chargeback_amount, :correction_notice_count, :charge_chageback_count, - :charge_chargeback_amount, :refund_chargeback_amount, - :refund_chargeback_count, :charge_returned_items_amount, - :charge_returned_items_count, :refund_returned_items_amount, - :refund_returned_items_count - end -end diff --git a/lib/authorize_net/reporting/fds_filter.rb b/lib/authorize_net/reporting/fds_filter.rb deleted file mode 100644 index b924787..0000000 --- a/lib/authorize_net/reporting/fds_filter.rb +++ /dev/null @@ -1,8 +0,0 @@ -module AuthorizeNet::Reporting - # Models a fraud detection filter. - class FDSFilter - include AuthorizeNet::Model - - attr_accessor :name, :action - end -end diff --git a/lib/authorize_net/reporting/response.rb b/lib/authorize_net/reporting/response.rb deleted file mode 100644 index 2ab514e..0000000 --- a/lib/authorize_net/reporting/response.rb +++ /dev/null @@ -1,157 +0,0 @@ -module AuthorizeNet::Reporting - # The CIM response class. - class Response < AuthorizeNet::XmlResponse - include AuthorizeNet::CIM::Fields - - # Constructs a new response object from raw_response in the context of transaction. - # You don‘t typically construct this object yourself, as AuthorizeNet::Reeporting::Transaction - # will build one for you when it makes the request to the gateway. - def initialize(raw_response, transaction) - super - unless connection_failure? - begin - @batch_list = @root.at_css('batchList') - @transactions = @root.at_css('transactions') - @transaction = @root.at_css('transaction') - rescue StandardError - @raw_response = $ERROR_INFO - end - end - end - - # Returns an Array of Batch objects built from the entities returned in the response. Returns nil if no batchList was returned. - def batch_list - unless @batch_list.nil? - batches = [] - @batch_list.element_children.each do |child| - batches <<= build_entity(child, Fields::BATCH_ENTITY_DESCRIPTION) unless child.nil? - end - return batches unless batches.empty? - end - end - - # Returns an Array of TransactionDetail objects built from the entities returned in the response. Returns nil if no transactions were returned. - def transactions - unless @transactions.nil? - transactions = [] - @transactions.element_children.each do |child| - next if child.nil? - transaction = build_entity(child, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION) - - # handle some stuff thats too tricky for EntityDecription to handle - first_name = node_content_unless_nil(child.at_css('firstName')) - last_name = node_content_unless_nil(child.at_css('lastName')) - unless first_name.nil? && last_name.nil? - address = AuthorizeNet::Address.new(first_name: first_name, last_name: last_name) - transaction.customer = AuthorizeNet::Customer.new(address: address) - end - invoice_number = node_content_unless_nil(child.at_css('invoiceNumber')) - unless invoice_number.nil? - transaction.order = AuthorizeNet::Order.new(invoice_num: invoice_number) - end - subscription = child.at_css('subscription') - unless subscription.nil? - subscription_id = node_content_unless_nil(child.at_css('subscription').at_css('id')) - transaction.subscription_id = subscription_id unless subscription_id.nil? - - pay_num = node_content_unless_nil(child.at_css('subscription').at_css('payNum')) - transaction.subscription_paynum = pay_num unless pay_num.nil? - end - - transactions <<= transaction - end - return transactions unless transactions.empty? - end - end - - # Builds and returns a TransactionDetail entity built from the response. If no transaction was found, returns nil. - def transaction - unless @transaction.nil? - transaction = build_entity(@transaction, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION) - - ip = node_content_unless_nil(@transaction.at_css('customerIP')) - unless ip.nil? - transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new - transaction.customer.ip = ip - end - - tax_exempt = node_content_unless_nil(@transaction.at_css('taxExempt')) - unless tax_exempt.nil? - transaction.order ||= AuthorizeNet::Order.new - transaction.order.tax_exempt = value_to_boolean(tax_exempt) - end - - tax = @transaction.at_css('tax') - unless tax.nil? - transaction.order ||= AuthorizeNet::Order.new - tax_amount = node_content_unless_nil(tax.at_css('amount')) - transaction.order.tax = value_to_decimal(tax_amount) unless tax_amount.nil? - transaction.order.tax_name = node_content_unless_nil(tax.at_css('name')) - transaction.order.tax_description = node_content_unless_nil(tax.at_css('description')) - end - - shipping = @transaction.at_css('shipping') - unless shipping.nil? - transaction.order ||= AuthorizeNet::Order.new - shipping_amount = node_content_unless_nil(shipping.at_css('amount')) - transaction.order.freight = value_to_decimal(shipping_amount) unless shipping_amount.nil? - transaction.order.freight_name = node_content_unless_nil(shipping.at_css('name')) - transaction.order.freight_description = node_content_unless_nil(shipping.at_css('description')) - end - - duty = @transaction.at_css('duty') - unless duty.nil? - transaction.order ||= AuthorizeNet::Order.new - duty_amount = node_content_unless_nil(duty.at_css('amount')) - transaction.order.duty = value_to_decimal(duty_amount) unless duty_amount.nil? - transaction.order.duty_name = node_content_unless_nil(duty.at_css('name')) - transaction.order.duty_description = node_content_unless_nil(duty.at_css('description')) - end - - line_items = @transaction.at_css('lineItems') - unless line_items.nil? - transaction.order ||= AuthorizeNet::Order.new - line_items.element_children.each do |child| - line_item = build_entity(child, Fields::LINE_ITEM_ENTITY_DESCRIPTION) - transaction.order.add_line_item(line_item) - end - end - - # Really not sure what to do with customer type here. It should go on a payment - customer_type = node_content_unless_nil(@transaction.at_css('customer type')) - unless customer_type.nil? - transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new - transaction.customer.payment_profiles = [AuthorizeNet::CIM::PaymentProfile.new(cust_type: customer_type)] - end - - subscription = @transaction.at_css('subscription') - unless subscription.nil? - subscription_id = node_content_unless_nil(@transaction.at_css('subscription').at_css('id')) - transaction.subscription_id = value_to_decimal(subscription_id) unless subscription_id.nil? - - pay_num = node_content_unless_nil(@transaction.at_css('subscription').at_css('payNum')) - transaction.subscription_paynum = value_to_decimal(pay_num) unless pay_num.nil? - end - - solution = @transaction.at_css('solution') - unless solution.nil? - solution_id = node_content_unless_nil(@transaction.at_css('solution').at_css('id')) - transaction.solution_id = solution_id unless solution_id.nil? - - transaction.solution_name = node_content_unless_nil(@transaction.at_css('solution').at_css('name')) - end - - returned_items = @transaction.at_css('returnedItems') - unless returned_items.nil? - transaction.returns ||= AuthorizeNet::Reporting::ReturnedItem.new - returned_items.element_children.each do |child| - returned_item = build_entity(child, Fields::RETURNED_ITEM_ENTITY_DESCRIPTION) - transaction.returns.add_returned_item(returned_item) - end - end - - transaction - end - end - end -end diff --git a/lib/authorize_net/reporting/returned_item.rb b/lib/authorize_net/reporting/returned_item.rb deleted file mode 100644 index 42c46c7..0000000 --- a/lib/authorize_net/reporting/returned_item.rb +++ /dev/null @@ -1,45 +0,0 @@ -module AuthorizeNet::Reporting - class ReturnedItem - include AuthorizeNet::Model - - attr_accessor :id, :date_utc, :date_local, :code, :description, :returned_items - - def date_utc=(time) - if time.is_a?(DateTime) - @date_utc = time - else - @date_utc = DateTime.parse(time.to_s) - end - end - - def date_local=(time) - if time.is_a?(DateTime) - @date_local = time - else - @date_local = DateTime.parse(time.to_s) - end - end - - def add_returned_item(id = nil, date_utc = nil, date_local = nil, code = nil, description = nil) - if id.is_a?(AuthorizeNet::Reporting::ReturnedItem) - returned_item = id - else - returned_item = AuthorizeNet::Reporting::ReturnedItem.new(return_item_id: id, return_item_date_utc: date_utc, return_item_date_local: date_local, return_item_code: code, line_item_description: description) - end - @returned_items = @returned_items.to_a << returned_item - end - - def to_hash - hash = { - id: @id, - date_utc: @date_utc, - date_local: @date_local, - code: @code, - description: @description, - returned_items: handle_multivalue_hashing(@returned_items) - } - hash.delete_if { |_k, v| v.nil? } - hash - end - end -end diff --git a/lib/authorize_net/reporting/transaction.rb b/lib/authorize_net/reporting/transaction.rb deleted file mode 100644 index ce8b81d..0000000 --- a/lib/authorize_net/reporting/transaction.rb +++ /dev/null @@ -1,131 +0,0 @@ -module AuthorizeNet::Reporting - # The Reporting API transaction class. - class Transaction < AuthorizeNet::XmlTransaction - include AuthorizeNet::Reporting::Fields - - # The class to wrap our response in. - @response_class = AuthorizeNet::Reporting::Response - - # Fields to convert to/from Date. - @@datetime_fields = %i[first_settlement_date last_settlement_date] - - # Constructs a Reporting transaction. You can use the new Reporting transaction object - # to issue a request to the payment gateway and parse the response into a new - # AuthorizeNet::Reporting::Response object. - # - # +api_login_id+:: Your API login ID, as a string. - # +api_transaction_key+:: Your API transaction key, as a string. - # +options+:: A hash of options. See below for values. - # - # Options - # +gateway+:: The gateway to submit the transaction to. Can be a URL string, an AuthorizeNet::Reporting::Transaction::Gateway constant, or one of the convenience symbols :sandbox, :test, :production, or :live (:test is an alias for :sandbox, and :live is an alias for :production). - # +verify_ssl+:: A boolean indicating if the SSL certificate of the +gateway+ should be verified. Defaults to true. - # +reference_id+:: A string that can be used to identify a particular transaction with its response. Will be echo'd in the response, only if it was provided in the transaction. Defaults to nil. - # - def initialize(api_login_id, api_transaction_key, options = {}) - ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction" - super - end - - # Sets up and submits a getSettledBatchListRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::Reporting::Response object. The - # response object will have an array of Batch objects available via its batch_list method if - # the request was successful. - # - # - # +from_date+:: Takes either a DateTime or a String representing a date and time. Only settled batches >= this value will be returned. Defaults to nil (which returns >= 24hrs ago). A to_date must be specified if a from_date is. - # +to_date+:: Takes either a DateTime or a String representing a date and time. Only settled batches <= this value will be returned. Defaults to nil. The maximum date range is 31 days, and a from_date must be supplied if a to_date is. - # +include_stats+:: Takes a Boolean. Determines if BatchStatistics should be returned with the Batch objects. Defaults to false. - # - # Typical usage: - # - # response = transaction.get_settled_batch_list(DateTime.now() - (1 * 3600 * 48), DateTime.now(), true) - # batches = response.batch_list if response.success? - # - def get_settled_batch_list(from_date = nil, to_date = nil, include_stats = false) - @type = Type::REPORT_GET_BATCH_LIST - set_fields(first_settlement_date: from_date, last_settlement_date: to_date, include_statistics: include_stats) - make_request - end - - # Sets up and submits a getTransactionListRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::Reporting::Response object. The - # response object will have an array of TransactionDetail objects available via its transactions method if - # the request was successful. These TransactionDetail objects will not be fully populated. Use get_transaction_details - # to get all the details. - # - # - # +batch_id+:: Takes either a Batch object with its id attribute populated, or a String representing the ID of the batch to retrieve the transaction list from. - # - # Typical usage: - # - # response = transaction.get_transaction_list('123456') - # transactions = response.transactions if response.success? - # - def get_transaction_list(batch_id) - @type = Type::REPORT_GET_TRANSACTION_LIST - handle_batch_id(batch_id) - make_request - end - - # Sets up and submits a getUnsettledTransactionListRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::Reporting::Response object. The - # response object will have an array of TransactionDetail objects available via its transactions method if - # the request was successful. These TransactionDetail objects will not be fully populated. Use get_transaction_details - # to get all the details. - # - # - # Typical usage: - # - # response = transaction.get_unsettled_transaction_list - # transactions = response.transactions if response.success? - # - def get_unsettled_transaction_list - @type = Type::REPORT_GET_UNSETTLED_TRANSACTION_LIST - make_request - end - - # Sets up and submits a getTransactionDetailsRequest transaction. If this transaction has already been - # run, this method will return nil. Otherwise it will return an AuthorizeNet::Reporting::Response object. The - # response object will have a TransactionDetail object available via its transactions method if - # the request was successful. This TransactionDetail object will have more data than the limited version - # returned by get_transaction_list. - # - # - # +transaction_id+:: Takes either a TransactionDetail object with its id attribute populated, or a String representing the ID of the transaction to retrieve the details from. - # - # Typical usage: - # - # response = transaction.get_transaction_details('123456789') - # transactions = response.transactions if response.success? - # - def get_transaction_details(transaction_id) - @type = Type::REPORT_GET_TRANSACTION_DETAILS - handle_transaction_id(transaction_id) - make_request - end - - #:enddoc: - protected - - # Handles batch id type massaging. - def handle_batch_id(id) - case id - when Batch - set_fields(batch_id: id.id.to_s) - else - set_fields(batch_id: id.to_s) - end - end - - # Handles transaction id type massaging. - def handle_transaction_id(id) - case id - when TransactionDetails - set_fields(transaction_id: id.id.to_s) - else - set_fields(transaction_id: id.to_s) - end - end - end -end diff --git a/lib/authorize_net/reporting/transaction_details.rb b/lib/authorize_net/reporting/transaction_details.rb deleted file mode 100644 index f7a45b6..0000000 --- a/lib/authorize_net/reporting/transaction_details.rb +++ /dev/null @@ -1,22 +0,0 @@ -module AuthorizeNet::Reporting - # Models the details of a transaction. - class TransactionDetails - include AuthorizeNet::Model - - attr_accessor :id, :submitted_at, :status, :order, :customer, :account_type, - :account_number, :settle_amount, :reference_id, :split_tender_id, - :type, :response_code, :response_reason_code, :response_reason_description, - :auth_code, :avs_response, :card_code_response, :cavv_response, - :fds_filter_action, :fds_filters, :batch, :prepaid_balance_remaining, - :payment_method, :recurring_billing, :bill_to, :ship_to, :auth_amount, - :subscription_id, :subscription_paynum, :solution_id, :solution_name, :returns - - def submitted_at=(time) - if time.is_a?(DateTime) - @submitted_at = time - else - @submitted_at = DateTime.parse(time.to_s) - end - end - end -end diff --git a/lib/authorize_net/response.rb b/lib/authorize_net/response.rb index 5c9e376..e379765 100644 --- a/lib/authorize_net/response.rb +++ b/lib/authorize_net/response.rb @@ -1,7 +1,6 @@ module AuthorizeNet - # The core, API agnostic response class. You shouldn't instantiate - # this one. Instead you should use AuthorizeNet::AIM::Response, - # AuthorizeNet::ARB::Response or AuthorizeNet::SIM::Response. + # The core, API agnostic response class. + # You shouldn't instantiate this one. class Response include AuthorizeNet::TypeConversions @@ -11,8 +10,7 @@ class Response # Fields to convert to/from BigDecimal. @@decimal_fields = [] - # DO NOT USE. Instantiate AuthorizeNet::AIM::Response or - # AuthorizeNet::SIM::Response instead. + # DO NOT USE. def initialize raise "#{self.class} should not be instantiated directly." end diff --git a/lib/authorize_net/sim/hosted_payment_form.rb b/lib/authorize_net/sim/hosted_payment_form.rb deleted file mode 100644 index e78b128..0000000 --- a/lib/authorize_net/sim/hosted_payment_form.rb +++ /dev/null @@ -1,34 +0,0 @@ -module AuthorizeNet::SIM - # Models a hosted payment form. - class HostedPaymentForm - include AuthorizeNet::Model - - attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :rename - - # Convenience method for adding field rename requests to the transaction. This renames a field shown on - # the hosted payment form. - def add_rename(field, name) - rename = "#{field},#{name}" - if @rename.nil? - @rename = [rename] - else - @rename = @rename.to_a << rename - end - end - - def to_hash - hash = { - header_html_payment_form: @header_html, - footer_html_payment_form: @footer_html, - color_background: @color_background, - color_link: @color_link, - color_text: @color_text, - logo_url: @logo_url, - background_url: @background_url, - rename: @rename - } - hash.delete_if { |_k, v| v.nil? } - hash - end - end -end diff --git a/lib/authorize_net/sim/hosted_receipt_page.rb b/lib/authorize_net/sim/hosted_receipt_page.rb deleted file mode 100644 index 2931c20..0000000 --- a/lib/authorize_net/sim/hosted_receipt_page.rb +++ /dev/null @@ -1,32 +0,0 @@ -module AuthorizeNet::SIM - # Models a hosted receipt page. - class HostedReceiptPage - # Defines constants for each of the link methods used by the hosted receipt page. - module LinkMethod - LINK = 'LINK'.freeze - POST = 'POST'.freeze - GET = 'GET'.freeze - end - - include AuthorizeNet::Model - - attr_accessor :header_html, :footer_html, :color_background, :color_link, :color_text, :logo_url, :background_url, :link_method, :link_text, :link_url - - def to_hash - hash = { - header_html_receipt: @header_html, - footer_html_receipt: @footer_html, - color_background: @color_background, - color_link: @color_link, - color_text: @color_text, - logo_url: @logo_url, - background_url: @background_url, - receipt_link_method: @link_method, - receipt_link_text: @link_text, - receipt_link_url: @link_url - } - hash.delete_if { |_k, v| v.nil? } - hash - end - end -end diff --git a/lib/authorize_net/sim/response.rb b/lib/authorize_net/sim/response.rb deleted file mode 100644 index e1190ae..0000000 --- a/lib/authorize_net/sim/response.rb +++ /dev/null @@ -1,133 +0,0 @@ -module AuthorizeNet::SIM - # The SIM response class. Handles parsing the response from the gateway. Also - # provides a few relay response helpers used to implement Direct Post Method. - class Response < AuthorizeNet::KeyValueResponse - # Our MD5 digest generator. - @@digest = OpenSSL::Digest.new('md5') - - include AuthorizeNet::SIM::Fields - - # Constructs a new response object from a +raw_response+. Provides utility methods - # for validating the response as authentic, and for handling the Direct Post Method - # relay response. - # - # +raw_response+:: The raw response, either a string in POST body or GET query string format, or a hash of key/value pairs. - # - # Typical usage: - # response = AuthorizeNet::SIM::Response("x_first_name=John&x_last_name=Doe") - def initialize(raw_response) - @raw_response = raw_response - @custom_fields = {} - @fields = {} - parse_response(@raw_response) - end - - # Returns True if the MD5 hash found in the response payload validates using - # the supplied api_login and secret merchant_value (THIS IS NOT YOUR API KEY). - def valid_md5?(api_login, merchant_value) - return false if @fields[:MD5_Hash].nil? - @@digest.hexdigest("#{merchant_value}#{api_login}#{@fields[:trans_id]}#{@fields[:amount]}").casecmp(@fields[:MD5_Hash]).zero? - end - - # Returns an HTML string that can be returned to the gateway during the Relay Response, - # and will send the user on to URL you specify. Takes a hash of options, currently the - # only option is :include, which can be True to include all fields returned in the response - # as query string parameters, or it can be an array of fields to include. - def direct_post_reply(url, options = {}) - url = direct_post_url(url, options[:include]) if options.key?(:include) - js_url = url.tr("'", '\'') - html_url = url.gsub('&', '&').tr('"', "\"") - html = <<-HTML - -HTML - end - - # Returns an URL with the fields found in the response and specified in include_fields attached as - # part of the URL's query string. If you pass true instead of an array of fields, all fields will be - # attached. - def direct_post_url(base_url, include_fields = true) - url = base_url - if include_fields - fields = [] - case include_fields - when TrueClass - fields = FIELDS.collect do |k| - k_str = k.to_s - k_str[2..k_str.length].to_sym - end - when Array - fields = include_fields - else - fields = include_fields.to_a - end - parsed_url = URI.parse(url) - if parsed_url.query.nil? - parsed_url.query = '' - elsif !parsed_url.query.empty? - parsed_url.query = parsed_url.query.chomp('&') + '&' - end - parsed_url.query += ((fields.select { |k| @fields.key?(k) }).collect { |k| to_param(k, @fields[k]) }).join('&') - parsed_url.query.chomp('&') - url = parsed_url.to_s - end - url - end - - # Check to see if the response indicated success. Success is defined as a valid MD5 hash - # and an response code of AuthorizeNet::Response::ResponseCode::APPROVED. - def success?(api_login, merchant_value) - valid_md5?(api_login, merchant_value) && approved? - end - - # Returns the transaction's authorization code. This should be shown to the - # end user. - def authorization_code - @fields[:auth_code] - end - - # Returns the transaction's authorization id. You will need this for future void, refund - # and prior authorization capture requests. - def transaction_id - @fields[:trans_id] - end - - # Returns the customer id from the response. - def customer_id - @fields[:cust_id] - end - - # Returns a response code (from AVSResponseCode) indicating the result of any Address Verification - # Service checks. - def avs_response - @fields[:avs_code] - end - - #:enddoc: - protected - - # Internal helper to parse the raw response object. It handles both raw POST bodies and - # hashes. - def parse_response(raw_response) - case raw_response - when Hash - raw_response.each do |k, v| - k = k.to_sym - if FIELDS.include?(k) - @fields[to_internal_field(k)] = v # remove x_ from sym and stick in @fields - else - @custom_fields[k] = v - end - end - when String - # convert to hash and re-parse - hash = CGI.parse(raw_response) - hash.each do |k, v| - hash[k] = v[0] if v.is_a?(Array) && v.length == 1 - end - parse_response(hash) - else - parse_response(@raw_response.to_s) - end - end - end -end diff --git a/lib/authorize_net/sim/transaction.rb b/lib/authorize_net/sim/transaction.rb deleted file mode 100644 index 080f4a0..0000000 --- a/lib/authorize_net/sim/transaction.rb +++ /dev/null @@ -1,128 +0,0 @@ -module AuthorizeNet::SIM - # The SIM transaction class. Handles building the transaction payload and - # generating a set of hidden form fields to be POSTed to the gateway. - class Transaction < AuthorizeNet::KeyValueTransaction - RANDOM_SEQUENCE_MAX = (1 << 32) - 1 - - # Our MD5 digest generator. - @@digest = OpenSSL::Digest.new('md5') - - # The default options for the constructor. - @@option_defaults = { - sequence: nil, - timestamp: nil, - test: false, - hosted_payment_form: false, - relay_response: true, - relay_url: nil, - transaction_type: Type::AUTHORIZE_AND_CAPTURE - } - - # Constructs a SIM transaction. You can use the new SIM transaction object - # to build the hidden field payload needed to process a SIM transaction with - # the gateway. In particular, this class handles generating the MD5 fingerprint - # used to authenticate transactions at the gateway. Since the fingerprint includes - # the amount to charge, you should not construct this object until you know EXACTLY - # how much you want to charge (or authorize). - # - # +api_login_id+:: Your API login ID, as a string. - # +api_transaction_key+:: Your API transaction key, as a string. - # +amount+:: The amount of the transaction, as a string, Float or BigDecimal. - # +options+:: A hash of options. See below for values. - # - # Options - # +sequence+:: The sequence number of the transaction as a string or Integer. This is usually something like an invoice number. If none is provided, the SDK generates one at random. - # +timestamp+:: The time the transaction was initiated as a string or Integer. This needs to be within 15 minutes of when the gateway receives the transaction. If no value is provided, the SDK defaults it to Time.now(). - # +test+:: A boolean indicating if the transaction should be run in test mode or not (defaults to false). - # +hosted_payment_form+:: A boolean indicating if the transaction should use a hosted payment form (defaults to false). - # +relay_response+:: A boolean indicating if the transaction should use the relay response feature to return a receipt to the customer (defaults to true). Direct Post Method requires using a relay response. - # +relay_url+:: A string of the URL that the gateway should hit to get the relay response (defaults to nil). - # +transaction_type+:: The type of transaction to perform. Defaults to AuthorizeNet::Type::AUTHORIZE_AND_CAPTURE. This value is only used if run is called directly. - # - def initialize(api_login_id, api_transaction_key, amount, options = {}) - ActiveSupport::Deprecation.warn "use AuthorizeNet::API::Transaction" - super() - @api_transaction_key = api_transaction_key - @api_login_id = api_login_id - @amount = decimal_to_value(amount) - options = @@option_defaults.merge(options) - @sequence = options[:sequence] - @timestamp = options[:timestamp] - @test_mode = options[:test] - @hosted_payment_form = options[:hosted_payment_form] - @relay_url = options[:relay_url] - @type = options[:transaction_type] - if @relay_url.nil? - @relay_response = !!options[:relay_response] - else - @relay_response = true - end - @delim_data = !@relay_response - end - - # Calculates and returns the HMAC-MD5 fingerprint needed to authenticate the transaction - # with the SIM gateway. - def fingerprint - @timestamp = Time.now.to_i if @timestamp.nil? - - @sequence = rand(RANDOM_SEQUENCE_MAX) if @sequence.nil? - OpenSSL::HMAC.hexdigest(@@digest, @api_transaction_key, "#{@api_login_id.to_s.rstrip}^#{@sequence.to_s.rstrip}^#{@timestamp.to_s.rstrip}^#{@amount.to_s.rstrip}^") - end - - # Returns all the fields needed for the fingerprint. These must all be passed to the SIM - # exactly as returned. And these values are time sensitive. - def fingerprint_fields - { - login: @api_login_id, - fp_hash: fingerprint, - fp_sequence: @sequence, - fp_timestamp: @timestamp, - amount: @amount - } - end - - # Returns all the fields (including custom) exactly as they should be named - # in the SIM form. Fields with multiple values are returned with an array - # for the key's value. - def form_fields - form_fields = {} - form_fields[:x_test_request] = boolean_to_value(@test_mode) - form_fields[:x_show_form] = 'PAYMENT_FORM' if @hosted_payment_form - if @relay_response && !@relay_url.nil? - form_fields[:x_relay_url] = @relay_url - end - fields.merge(type: @type, version: @version, delim_data: boolean_to_value(@delim_data), relay_response: boolean_to_value(@relay_response)).each do |k, v| - form_fields[to_external_field(k)] = v - end - fingerprint_fields.each do |k, v| - form_fields[to_external_field(k)] = v - end - form_fields.merge(custom_fields) - end - - # Takes an instance of AuthorizeNet::SIM::HostedPaymentForm and adds it to the transaction. Note that - # many of the fields in AuthorizeNet::SIM::HostedPaymentForm are shared with those in - # AuthorizeNet::SIM::HostedReceiptPage. For the duplicate fields, which ever value - # is added to the transaction last will be the one used. - def set_hosted_payment_form(form) - @fields.merge!(form.to_hash) - @hosted_payment_form = true - end - - # Takes an instance of AuthorizeNet::SIM::HostedReceiptPage and adds it to the transaction. Note that - # many of the fields in AuthorizeNet::SIM::HostedReceiptPage are shared with those in - # AuthorizeNet::SIM::HostedPaymentForm. For the duplicate fields, which ever value - # is added to the transaction last will be the one used. If you set a hosted payment receipt, - # the relay response will be disabled. - def set_hosted_payment_receipt(form) - @fields.merge!(form.to_hash) - @relay_response = false - @delim_data = true - end - - # An alias for form_fields. - def run - form_fields - end - end -end diff --git a/lib/authorize_net/transaction.rb b/lib/authorize_net/transaction.rb index b1c5399..67eb17d 100644 --- a/lib/authorize_net/transaction.rb +++ b/lib/authorize_net/transaction.rb @@ -1,7 +1,6 @@ module AuthorizeNet - # The core, API agnostic transaction class. You shouldn't instantiate this one. - # Instead you should use AuthorizeNet::AIM::Transaction, - # AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction. + # The core, API agnostic transaction class. + # You shouldn't instantiate this one. class Transaction include AuthorizeNet::TypeConversions @@ -11,8 +10,7 @@ class Transaction # Fields to convert to/from BigDecimal. @@decimal_fields = [] - # DO NOT USE. Instantiate AuthorizeNet::AIM::Transaction, - # AuthorizeNet::SIM::Transaction or AuthorizeNet::ARB::Transaction instead. + # DO NOT USE. def initialize @fields ||= {} end diff --git a/lib/generators/authorize_net/direct_post/direct_post_generator.rb b/lib/generators/authorize_net/direct_post/direct_post_generator.rb deleted file mode 100644 index 2e48e9e..0000000 --- a/lib/generators/authorize_net/direct_post/direct_post_generator.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'rails/generators' -require 'rails/generators/named_base' - -module AuthorizeNet - module Generators - class DirectPostGenerator < Rails::Generators::NamedBase - source_root File.expand_path('templates', __dir__) - p '__FILE__:' + __FILE__ - p 'source_root:' + source_root - argument :api_login_id, type: :string, desc: 'Your Authorize.Net API login ID.', optional: true - argument :api_transaction_key, type: :string, desc: 'Your Authorize.Net API transaction key.', optional: true - argument :merchant_hash_value, type: :string, desc: 'Your Authorize.Net merchant hash value.', optional: true - desc <<-DESC -Description - Generates a simple implementation of Authorize.Net's Direct Post Method integration method. - -Example: - rails generate authorize_net:direct_post payments API_LOGIN_ID API_TRANSACTION_KEY MERCHANT_HASH_VALUE - - This will create: - create README-AuthorizeNet - create app/views/payments - create app/views/payments/payment.erb - create app/views/payments/receipt.erb - create app/views/payments/relay_response.erb - create app/views/layouts/authorize_net.erb - create config/authorize_net.yml - create config/initializers/authorize_net.rb - create app/controllers/payments_controller.rb - route match '/payments/receipt', :to => 'payments#receipt', :as => 'payments_receipt', :via => [:get] - route match '/payments/relay_response', :to => 'payments#relay_response', :as => 'payments_relay_response', :via => [:post] - route match '/payments/payment', :to => 'payments#payment', :as => 'paymentspayment', :via => [:get] - -DESC - - def manifest - copy_file "README-AuthorizeNet", "README-AuthorizeNet" - empty_directory "app/views/#{file_name}" - copy_file "payment.rails3.erb", "app/views/#{file_name}/payment.erb" - copy_file "receipt.erb", "app/views/#{file_name}/receipt.erb" - copy_file "relay_response.erb", "app/views/#{file_name}/relay_response.erb" - copy_file "layout.erb", "app/views/layouts/authorize_net.erb" - template "config.yml.rails3.erb", "config/authorize_net.yml" - copy_file "initializer.rb", "config/initializers/authorize_net.rb" - template "controller.rb.erb", "app/controllers/#{file_name}_controller.rb" - route "match '/#{plural_name}/receipt', :to => '#{file_name}#receipt', :as => '#{singular_name}_receipt', :via => [:get]" - route "match '/#{plural_name}/relay_response', :to => '#{file_name}#relay_response', :as => '#{singular_name}_relay_response', :via => [:post]" - route "match '/#{plural_name}/payment', :to => '#{file_name}#payment', :as => '#{singular_name}payment', :via => [:get]" - end - end - end -end diff --git a/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet b/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet deleted file mode 100644 index 1f75061..0000000 --- a/lib/generators/authorize_net/direct_post/templates/README-AuthorizeNet +++ /dev/null @@ -1,49 +0,0 @@ -= Authorize.Net Ruby SDK - -The Authorize.Net Ruby SDK is meant to offer an alternate object-oriented -model of development with the Authorize.net APIs (Version 3.1). The SDK is -based entirely off the name-value pair API, but performs the core payment -activities (such as error handling/parsing, network communication, and data -encoding) behind the scenes. Providing the end developer with this allows the -developer to start integrating immediately without having to write out a mass -of boiler plate code. - -== Prerequisites - -* Ruby 1.8.7 or higher -* RubyGem 1.3.7 or higher (to build the gem) -* RDoc 1.0 or higher (to build documentation) -* Rake 0.8.7 or higher (to use the rake tasks) - -== Installation - -Goto the Authorize.Net SDK download page and download the Ruby gem. Then - - > gem install authorize-net-1.0.0.gem - -== Usage - -A generator is provided to aid in setting up a Direct Post Method application. In the example below 'payments' is the name of the controller to generate. - - > sudo gem install rails -v '~> 2.1' - > rails my_direct_post_app - > cd my_direct_post_app - > script/generate authorize_net_direct_post payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY - > script/server - -After running the generator you will probably want to customize the payment form found in 'app/views/payments/payment.erb' and the receipt found in 'app/views/payments/receipt.erb'. - -There is also a default layout generated, 'app/views/layouts/authorize_net.erb'. If you already have your own layout, you can delete that file and the reference to it in the controller ('app/controllers/payments_controller.rb'). - - -== Credit Card Test Numbers - -For your reference, you can use the following test credit card numbers. -The expiration date must be set to the present date or later. Use 123 for -the CCV code. - -American Express:: 370000000000002 -Discover:: 6011000000000012 -Visa:: 4007000000027 -JCB:: 3088000000000017 -Diners Club/ Carte Blanche:: 38000000000006 \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/config.yml.erb b/lib/generators/authorize_net/direct_post/templates/config.yml.erb deleted file mode 100644 index f4dea4c..0000000 --- a/lib/generators/authorize_net/direct_post/templates/config.yml.erb +++ /dev/null @@ -1,8 +0,0 @@ -default: - api_login_id: <%= args[0] %> - api_transaction_key: <%= args[1] %> - merchant_hash_value: <%= args[2] %> - -development: -test: -production: diff --git a/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb b/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb deleted file mode 100644 index 715a762..0000000 --- a/lib/generators/authorize_net/direct_post/templates/config.yml.rails3.erb +++ /dev/null @@ -1,8 +0,0 @@ -default: - api_login_id: <%= self.api_login_id %> - api_transaction_key: <%= self.api_transaction_key %> - merchant_hash_value: <%= self.merchant_hash_value %> - -development: -test: -production: diff --git a/lib/generators/authorize_net/direct_post/templates/controller.rb.erb b/lib/generators/authorize_net/direct_post/templates/controller.rb.erb deleted file mode 100644 index 3c67282..0000000 --- a/lib/generators/authorize_net/direct_post/templates/controller.rb.erb +++ /dev/null @@ -1,31 +0,0 @@ -class <%= class_name %>Controller < ApplicationController - - layout 'authorize_net' - helper :authorize_net - protect_from_forgery :except => :relay_response - - # GET - # Displays a payment form. - def payment - @amount = 10.00 - @sim_transaction = AuthorizeNet::SIM::Transaction.new(AUTHORIZE_NET_CONFIG['api_login_id'], AUTHORIZE_NET_CONFIG['api_transaction_key'], @amount, :relay_url => <%= singular_name %>_relay_response_url(:only_path => false)) - end - - # POST - # Returns relay response when Authorize.Net POSTs to us. - def relay_response - sim_response = AuthorizeNet::SIM::Response.new(params) - if sim_response.success?(AUTHORIZE_NET_CONFIG['api_login_id'], AUTHORIZE_NET_CONFIG['merchant_hash_value']) - render :text => sim_response.direct_post_reply(<%= singular_name %>_receipt_url(:only_path => false), :include => true) - else - render - end - end - - # GET - # Displays a receipt. - def receipt - @auth_code = params[:x_auth_code] - end - -end \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/initializer.rb b/lib/generators/authorize_net/direct_post/templates/initializer.rb deleted file mode 100644 index 0a0b25d..0000000 --- a/lib/generators/authorize_net/direct_post/templates/initializer.rb +++ /dev/null @@ -1,4 +0,0 @@ -yml = YAML.load_file("#{Rails.root}/config/authorize_net.yml") -AUTHORIZE_NET_CONFIG = yml['default'] -AUTHORIZE_NET_CONFIG.merge!(yml[Rails.env]) unless yml[Rails.env].nil? -AUTHORIZE_NET_CONFIG.freeze diff --git a/lib/generators/authorize_net/direct_post/templates/layout.erb b/lib/generators/authorize_net/direct_post/templates/layout.erb deleted file mode 100644 index 8ec3d05..0000000 --- a/lib/generators/authorize_net/direct_post/templates/layout.erb +++ /dev/null @@ -1,18 +0,0 @@ - - - - Direct Post Sample App - - - - <%= yield %> - - \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/payment.erb b/lib/generators/authorize_net/direct_post/templates/payment.erb deleted file mode 100644 index 2bce899..0000000 --- a/lib/generators/authorize_net/direct_post/templates/payment.erb +++ /dev/null @@ -1,10 +0,0 @@ -<% form_for :sim_transaction, :url => AuthorizeNet::SIM::Transaction::Gateway::TEST do |f| %> - <%= sim_fields(@sim_transaction) %> - <%= label_tag 'x_amount', "Total: #{number_to_currency(@amount)}" %> - <%= label_tag 'x_card_num', 'Credit Card Number'%> - <%= text_field_tag 'x_card_num' %> - <%= label_tag 'x_exp_date', 'Expiration Date (MMYY)'%> - <%= text_field_tag 'x_exp_date' %> -
- <%= f.submit 'Purchase'%> -<% end %> \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb b/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb deleted file mode 100644 index 0e4bda8..0000000 --- a/lib/generators/authorize_net/direct_post/templates/payment.rails3.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= form_for :sim_transaction, :url => AuthorizeNet::SIM::Transaction::Gateway::TEST do |f| %> - <%= sim_fields(@sim_transaction) %> - <%= label_tag 'x_amount', "Total: #{number_to_currency(@amount)}" %> - <%= label_tag 'x_card_num', 'Credit Card Number'%> - <%= text_field_tag 'x_card_num' %> - <%= label_tag 'x_exp_date', 'Expiration Date (MMYY)'%> - <%= text_field_tag 'x_exp_date' %> -
- <%= f.submit 'Purchase'%> -<% end %> \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/receipt.erb b/lib/generators/authorize_net/direct_post/templates/receipt.erb deleted file mode 100644 index 0602186..0000000 --- a/lib/generators/authorize_net/direct_post/templates/receipt.erb +++ /dev/null @@ -1 +0,0 @@ -Thanks for your purchase! Your authorization code is <%=h @auth_code %>. \ No newline at end of file diff --git a/lib/generators/authorize_net/direct_post/templates/relay_response.erb b/lib/generators/authorize_net/direct_post/templates/relay_response.erb deleted file mode 100644 index 32d82cb..0000000 --- a/lib/generators/authorize_net/direct_post/templates/relay_response.erb +++ /dev/null @@ -1 +0,0 @@ -Sorry, something went wrong, please try your transaction again. \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/sim_generator.rb b/lib/generators/authorize_net/sim/sim_generator.rb deleted file mode 100644 index 9714ee3..0000000 --- a/lib/generators/authorize_net/sim/sim_generator.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'rails/generators' -require 'rails/generators/named_base' - -module AuthorizeNet - module Generators - class SimGenerator < Rails::Generators::NamedBase - source_root File.expand_path('templates', __dir__) - argument :api_login_id, type: :string, desc: 'Your Authorize.Net API login ID.', optional: true - argument :api_transaction_key, type: :string, desc: 'Your Authorize.Net API transaction key.', optional: true - argument :merchant_hash_value, type: :string, desc: 'Your Authorize.Net merchant hash value.', optional: true - desc <<-DESC -Description - Generates a simple implementation of Authorize.Net's SIM integration method. - -Example: - rails generate authorize_net:sim payments API_LOGIN_ID API_TRANSACTION_KEY MERCHANT_HASH_VALUE - - This will create: - create README-AuthorizeNet - create app/views/payments - create app/views/payments/payment.erb - create app/views/payments/thank_you.erb - create app/views/layouts/authorize_net.erb - create config/authorize_net.yml - create config/initializers/authorize_net.rb - create app/controllers/payments_controller.rb - route match '/payments/thank_you', :to => 'payments#thank_you', :as => 'payments_thank_you', :via => [:get] - route match '/payments/payment', :to => 'payments#payment', :as => 'paymentspayment', :via => [:get] - -DESC - - def manifest - copy_file "README-AuthorizeNet", "README-AuthorizeNet" - empty_directory "app/views/#{file_name}" - copy_file "payment.rails3.erb", "app/views/#{file_name}/payment.erb" - copy_file "thank_you.erb", "app/views/#{file_name}/thank_you.erb" - copy_file "layout.erb", "app/views/layouts/authorize_net.erb" - template "config.yml.rails3.erb", "config/authorize_net.yml" - copy_file "initializer.rb", "config/initializers/authorize_net.rb" - template "controller.rb.erb", "app/controllers/#{file_name}_controller.rb" - route "match '/#{plural_name}/thank_you', :to => '#{file_name}#thank_you', :as => '#{singular_name}_thank_you', :via => [:get]" - route "match '/#{plural_name}/payment', :to => '#{file_name}#payment', :as => '#{singular_name}payment', :via => [:get]" - end - end - end -end diff --git a/lib/generators/authorize_net/sim/templates/README-AuthorizeNet b/lib/generators/authorize_net/sim/templates/README-AuthorizeNet deleted file mode 100644 index 8b43b46..0000000 --- a/lib/generators/authorize_net/sim/templates/README-AuthorizeNet +++ /dev/null @@ -1,52 +0,0 @@ -= Authorize.Net Ruby SDK - -The Authorize.Net Ruby SDK is meant to offer an alternate object-oriented -model of development with the Authorize.net APIs (Version 3.1). The SDK is -based entirely off the name-value pair API, but performs the core payment -activities (such as error handling/parsing, network communication, and data -encoding) behind the scenes. Providing the end developer with this allows the -developer to start integrating immediately without having to write out a mass -of boiler plate code. - -== Prerequisites - -* Ruby 1.8.7 or higher -* RubyGem 1.3.7 or higher (to build the gem) -* RDoc 1.0 or higher (to build documentation) -* Rake 0.8.7 or higher (to use the rake tasks) - -== Installation - -Goto the Authorize.Net SDK download page and download the Ruby gem. Then - - > gem install authorize-net-1.0.0.gem - -== Usage - -=== Server Integration Method (SIM) - -A generator is provided to aid in setting up a Server Integration Method application. In the example below 'payments' is the name of the controller to generate. - - > sudo gem install rails -v '~> 2.1' - > rails my_sim_app - > cd my_sim_app - > script/generate authorize_net_sim payments YOUR_API_LOGIN_ID YOUR_TRANSACTION_KEY MERCH_HASH_KEY - > script/server - -After running the generator you will probably want to customize the payment page found in 'app/views/payments/payment.erb' and the thank you page found in 'app/views/payments/thank_you.erb'. - -You may also want to customize the actual payment form and receipt pages. That can be done by making the necessary changes to the AuthorizeNet::SIM::Transaction object ('@sim_transaction') found in the +payment+ action in 'app/controllers/payments_controller.rb'. The styling of those hosted pages are controlled by the AuthorizeNet::SIM::HostedReceiptPage and AuthorizeNet::SIM::HostedPaymentForm objects (which are passed to the AuthorizeNet::SIM::Transaction). - -There is also a default layout generated, 'app/views/layouts/authorize_net.erb'. If you already have your own layout, you can delete that file and the reference to it in the controller ('app/controllers/payments_controller.rb'). - -== Credit Card Test Numbers - -For your reference, you can use the following test credit card numbers. -The expiration date must be set to the present date or later. Use 123 for -the CCV code. - -American Express:: 370000000000002 -Discover:: 6011000000000012 -Visa:: 4007000000027 -JCB:: 3088000000000017 -Diners Club/ Carte Blanche:: 38000000000006 \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/templates/config.yml.erb b/lib/generators/authorize_net/sim/templates/config.yml.erb deleted file mode 100644 index f4dea4c..0000000 --- a/lib/generators/authorize_net/sim/templates/config.yml.erb +++ /dev/null @@ -1,8 +0,0 @@ -default: - api_login_id: <%= args[0] %> - api_transaction_key: <%= args[1] %> - merchant_hash_value: <%= args[2] %> - -development: -test: -production: diff --git a/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb b/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb deleted file mode 100644 index 715a762..0000000 --- a/lib/generators/authorize_net/sim/templates/config.yml.rails3.erb +++ /dev/null @@ -1,8 +0,0 @@ -default: - api_login_id: <%= self.api_login_id %> - api_transaction_key: <%= self.api_transaction_key %> - merchant_hash_value: <%= self.merchant_hash_value %> - -development: -test: -production: diff --git a/lib/generators/authorize_net/sim/templates/controller.rb.erb b/lib/generators/authorize_net/sim/templates/controller.rb.erb deleted file mode 100644 index a856e7c..0000000 --- a/lib/generators/authorize_net/sim/templates/controller.rb.erb +++ /dev/null @@ -1,21 +0,0 @@ -class <%= class_name %>Controller < ApplicationController - - layout 'authorize_net' - helper :authorize_net - protect_from_forgery :except => :relay_response - - # GET - # Displays a payment form. - def payment - @amount = 10.00 - @sim_transaction = AuthorizeNet::SIM::Transaction.new(AUTHORIZE_NET_CONFIG['api_login_id'], AUTHORIZE_NET_CONFIG['api_transaction_key'], @amount, :hosted_payment_form => true) - @sim_transaction.set_hosted_payment_receipt(AuthorizeNet::SIM::HostedReceiptPage.new(:link_method => AuthorizeNet::SIM::HostedReceiptPage::LinkMethod::GET, :link_text => 'Continue', :link_url => <%= singular_name %>_thank_you_url(:only_path => false))) - end - - # GET - # Displays a thank you page. - def thank_you - @auth_code = params[:x_auth_code] - end - -end \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/templates/initializer.rb b/lib/generators/authorize_net/sim/templates/initializer.rb deleted file mode 100644 index 0a0b25d..0000000 --- a/lib/generators/authorize_net/sim/templates/initializer.rb +++ /dev/null @@ -1,4 +0,0 @@ -yml = YAML.load_file("#{Rails.root}/config/authorize_net.yml") -AUTHORIZE_NET_CONFIG = yml['default'] -AUTHORIZE_NET_CONFIG.merge!(yml[Rails.env]) unless yml[Rails.env].nil? -AUTHORIZE_NET_CONFIG.freeze diff --git a/lib/generators/authorize_net/sim/templates/layout.erb b/lib/generators/authorize_net/sim/templates/layout.erb deleted file mode 100644 index 1782595..0000000 --- a/lib/generators/authorize_net/sim/templates/layout.erb +++ /dev/null @@ -1,18 +0,0 @@ - - - - SIM Sample App - - - - <%= yield %> - - \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/templates/payment.erb b/lib/generators/authorize_net/sim/templates/payment.erb deleted file mode 100644 index 6f341b3..0000000 --- a/lib/generators/authorize_net/sim/templates/payment.erb +++ /dev/null @@ -1,6 +0,0 @@ -<% form_for :sim_transaction, :url => AuthorizeNet::SIM::Transaction::Gateway::TEST do |f| %> - <%= sim_fields(@sim_transaction) %> - <%= label_tag 'x_amount', "Total: #{number_to_currency(@amount)}" %> -
- <%= f.submit 'Purchase'%> -<% end %> \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/templates/payment.rails3.erb b/lib/generators/authorize_net/sim/templates/payment.rails3.erb deleted file mode 100644 index 803930b..0000000 --- a/lib/generators/authorize_net/sim/templates/payment.rails3.erb +++ /dev/null @@ -1,6 +0,0 @@ -<%= form_for :sim_transaction, :url => AuthorizeNet::SIM::Transaction::Gateway::TEST do |f| %> - <%= sim_fields(@sim_transaction) %> - <%= label_tag 'x_amount', "Total: #{number_to_currency(@amount)}" %> -
- <%= f.submit 'Purchase'%> -<% end %> \ No newline at end of file diff --git a/lib/generators/authorize_net/sim/templates/thank_you.erb b/lib/generators/authorize_net/sim/templates/thank_you.erb deleted file mode 100644 index 0602186..0000000 --- a/lib/generators/authorize_net/sim/templates/thank_you.erb +++ /dev/null @@ -1 +0,0 @@ -Thanks for your purchase! Your authorization code is <%=h @auth_code %>. \ No newline at end of file diff --git a/lib/generators/generator_extensions.rb b/lib/generators/generator_extensions.rb deleted file mode 100644 index 77d34a2..0000000 --- a/lib/generators/generator_extensions.rb +++ /dev/null @@ -1,73 +0,0 @@ -# Extends the Rails::Generator::Commands classes to add support for route and gem configuration generation. - -module Rails - module Generator - module Commands - class Base - def route_code(route_options) - route_options[:path] = route_options[:name] unless route_options.key? :path - code = "map.#{route_options[:name]} '#{route_options[:path]}', :controller => '#{route_options[:controller]}', :action => '#{route_options[:action]}'" - code += ", :conditions => #{route_options[:conditions]}" if route_options.key? :conditions - end - - def gsub_file_check(relative_destination, regexp, *_args) - path = destination_path(relative_destination) - content = File.read(path) - !(content =~ regexp).nil? - end - - def gem_code(gem_options) - gem_options[:lib] = gem_options[:name] unless gem_options.key? :lib - code = "config.gem '#{gem_options[:name]}', :lib => '#{gem_options[:lib]}'" - end - end - - # Here's a readable version of the long string used above in route_code; - # but it should be kept on one line to avoid inserting extra whitespace - # into routes.rb when the generator is run: - # "map.#{route_options[:name]} '#{route_options[:name]}', - # :controller => '#{route_options[:controller]}', - # :action => '#{route_options[:action]}'" - - class Create - def route(route_options) - sentinel = 'ActionController::Routing::Routes.draw do |map|' - if gsub_file_check 'config/routes.rb', /(#{Regexp.escape(route_code(route_options))})/mi - logger.identical route_code(route_options) - else - logger.route route_code(route_options) - gsub_file 'config/routes.rb', /(#{Regexp.escape(sentinel)})/mi do |m| - "#{m}\n #{route_code(route_options)}" - end - end - end - - def gem(gem_options) - sentinel = 'Rails::Initializer.run do |config|' - if gsub_file_check 'config/environment.rb', /(#{Regexp.escape(gem_code(gem_options))})/mi - logger.identical gem_code(gem_options) - else - logger.gem gem_code(gem_options) - gsub_file 'config/environment.rb', /(#{Regexp.escape(sentinel)})/mi do |m| - "#{m}\n #{gem_code(gem_options)}" - end - end - end - end - - class Destroy - def route(route_options) - logger.remove_route route_code(route_options) - to_remove = "\n #{Regexp.escape(route_code(route_options))}" - gsub_file 'config/routes.rb', /(#{to_remove})/mi, '' - end - - def gem(gem_options) - logger.remove_gem gem_code(gem_options) - to_remove = "\n #{Regexp.escape(gem_code(gem_options))}" - gsub_file 'config/environment.rb', /(#{to_remove})/mi, '' - end - end - end - end -end diff --git a/spec/aim_spec.rb b/spec/aim_spec.rb deleted file mode 100644 index 99b716d..0000000 --- a/spec/aim_spec.rb +++ /dev/null @@ -1,315 +0,0 @@ -=begin -require "spec_helper" - -describe AuthorizeNet::AIM::Transaction do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - @md5_value = creds['md5_value'] - @solution_id = "AAA100302" - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - @md5_value = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - @type = AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_AND_CAPTURE - @test_mode = false - @gateway = :sandbox - @amount = rand(100..10_099) / BigDecimal.new(100) - @next_year = "#{(Time.now.year+1) % 100}" - @credit_card = AuthorizeNet::CreditCard.new('4111111111111111', "01#{@next_year}") - @response = '1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,,,10.00,CC,auth_capture,,,,,,,,,,,,,,,,,,,,,,,,,,7A3C09A367FED29C9902038440CD8A52,,,,,,,,,,,,,XXXX0027,Visa,,,,,,,,,,,,,,,,' - @echeck = AuthorizeNet::ECheck.new('322271627', '123456789', 'JPMorgan Chase Bank', 'John Doe') - end - - it "should support instantiation" do - AuthorizeNet::AIM::Transaction.new(@api_login, @api_key).should be_instance_of(AuthorizeNet::AIM::Transaction) - end - - it "should know if its in test mode" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: AuthorizeNet::AIM::Transaction::Gateway::TEST, test: true) - transaction.test?.should be_truthy - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: AuthorizeNet::AIM::Transaction::Gateway::TEST, test: false) - transaction.test?.should be_truthy - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: AuthorizeNet::AIM::Transaction::Gateway::LIVE, test: true) - transaction.test?.should be_truthy - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: AuthorizeNet::AIM::Transaction::Gateway::LIVE, test: false) - transaction.test?.should be_falsey - end - - it "should not have a response if the transaciton hasn't been run" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.has_response?.should be_falsey - end - - it "should support the addition of fields to the transaction body" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.should respond_to(:set_fields) - transaction.set_fields(test: 123).should == { test: 123 } - end - - it "should support the addition of mulitple line_item fields" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.set_fields(line_item: [123, 123]).should == { line_item: [123, 123] } - transaction.set_fields(line_item: "abc").should == { line_item: "abc" } - end - - it "should not support the addition of mulitple fields for non-line-item fields" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.set_fields(test: 123).should == { test: 123 } - transaction.set_fields(test: 123).should == { test: 123 } - end - - it "should support custom fields" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.should respond_to(:set_custom_fields) - transaction.set_custom_fields(test: 123).should == { test: 123 } - transaction.fields.should == {} - transaction.custom_fields.should == { test: 123 } - end - - it "should support the returning its response object" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.should respond_to(:response) - end - - it "should parse the response properly" do - Net::HTTP.stub(:start).and_return(@response) - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - response = transaction.purchase(@amount, @credit_card) - response.should be_kind_of(AuthorizeNet::AIM::Response) - response.transaction_id.length.should >= 3 - response.success?.should be_truthy - response.avs_response.should == AuthorizeNet::AIM::Response::AVSResponseCode::ADDRESS_AND_ZIP5_MATCH - response.card_type.should == AuthorizeNet::AIM::Response::CardType::VISA - response.card_type.should_not == AuthorizeNet::AIM::Response::CardType::MASTER_CARD - end - - it "should support different transaction types" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.should respond_to(:type) - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_AND_CAPTURE - transaction.type = AuthorizeNet::AIM::Transaction::Type::VOID - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::VOID - transaction.type = AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_ONLY - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::AUTHORIZE_ONLY - transaction.type = AuthorizeNet::AIM::Transaction::Type::CAPTURE_ONLY - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::CAPTURE_ONLY - transaction.type = AuthorizeNet::AIM::Transaction::Type::CREDIT - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::CREDIT - transaction.type = AuthorizeNet::AIM::Transaction::Type::PRIOR_AUTHORIZATION_AND_CAPTURE - transaction.type.should == AuthorizeNet::AIM::Transaction::Type::PRIOR_AUTHORIZATION_AND_CAPTURE - end - - it "should be able to run a transaction" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.run.should be_kind_of(AuthorizeNet::AIM::Response) - end - - it "should not be able to run a transaction a second time" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.run.should be_kind_of(AuthorizeNet::AIM::Response) - transaction.run.should be_nil - end - - it "should be able to make a purchase" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.fields[:amount].should == @amount - transaction.response.success?.should be_truthy - end - - it "should support custom fields in the response" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.set_custom_fields(funkey: '123') - transaction.set_custom_fields(winker: 'ABC') - transaction.set_custom_fields(bean: '!!!') - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - fields = transaction.response.custom_fields - fields.should have_key(:funkey) - fields[:funkey].should == '123' - fields.should have_key(:winker) - fields[:winker].should == 'ABC' - fields.should have_key(:bean) - fields[:bean].should == '!!!' - end - - it "should support an encapsulation character in the response" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode, encapsulation_character: '"') - transaction.set_custom_fields(funkey: '12,3') - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - fields = transaction.response.custom_fields - fields.should have_key(:funkey) - fields[:funkey].should == '12,3' - end - - it "should accept an ECheck for a purchase" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.purchase(@amount, @echeck).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - end - - it "should support adding line items" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.add_line_item("item1", "Foo", "Bar", "5", "5.00", "TRUE") - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - transaction.fields[:line_item].should == ["item1<|>Foo<|>Bar<|>5<|>5.00<|>TRUE"] - end - - it "should support setting a customer" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - customer = AuthorizeNet::Customer.new(ip: '127.0.0.1') - transaction.set_customer(customer) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - end - - it "should support setting an address" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - address = AuthorizeNet::Address.new(city: 'San Francisco', state: 'NY') - transaction.set_address(address) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - end - - it "should support setting a shipping address" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - address = AuthorizeNet::ShippingAddress.new(city: 'San Francisco', state: 'NY', tax: 10.00) - transaction.set_shipping_address(address) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - end - - it "should support setting solution id" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode, solution_id: @solution_id) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - fields = transaction.response.transaction - (defined?(fields.solution_id) && (fields.solution_id == 'AAA100302')).should be_truthy - end - - it "should support adding an email receipt" do - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - email = AuthorizeNet::EmailReceipt.new(header: 'TEST!') - transaction.set_email_receipt(email) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - end - - it "should be able to void a purchase" do - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: false) - purchase.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - purchase.response.fields[:amount].should == @amount - purchase.response.success?.should be_truthy - void = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: @gateway, test: false) - void.void(purchase.response.transaction_id) - void.response.success?.should be_truthy - end - - it "should be able to capture a prior authorization" do - auth = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: false) - auth.authorize(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - auth.response.fields[:amount].should == @amount - auth.response.success?.should be_truthy - capture = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: @gateway, test: false) - capture.prior_auth_capture(auth.response.transaction_id) - capture.response.success?.should be_truthy - end - - it "should be able to run a card present purchase with track 1 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_1: "%B4111111111111111^DOE/JOHN^#{@next_year}03101000000000020000831000000?") - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to run a card present purchase with LRC codes in the track 1 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_1: '%B4111111111111111^DOE/JOHN^'+@next_year+'03101000000000020000831000000?\xAA') - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 1 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_1: "B4111111111111111^DOE/JOHN^#{@next_year}03101000000000020000831000000") - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to run a card present purchase with track 2 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_2: ';4111111111111111='+@next_year+'101000020000831?') - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to run a card present purchase with LRC codes in the track 2 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_2: ";4111111111111111=#{@next_year}03101000020000831?\x33") - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to run a card present purchase with no LRC or Start/End Sentinels in track 2 data" do - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_2: "4111111111111111=#{@next_year}03101000020000831") - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - end - - it "should be able to validate the passed MD5 hash" do - skip - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, transaction_type: @type, gateway: @gateway, test: @test_mode) - transaction.purchase(@amount, @credit_card).should be_kind_of(AuthorizeNet::AIM::Response) - transaction.response.success?.should be_truthy - transaction.response.valid_md5?(@api_login, @md5_value).should be_truthy - end - - it "should be able to validate the passed MD5 hash for card present transactions" do - skip - @credit_card = AuthorizeNet::CreditCard.new(nil, nil, track_1: '%B4111111111111111^DOE/JOHN^'+@next_year+'03101000000000020000831000000?') - purchase = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :card_present_test, test: false) - response = purchase.purchase(@amount, @credit_card) - response.success?.should be_truthy - response.valid_md5?(@api_login, @md5_value).should be_truthy - end -end - -describe AuthorizeNet::AIM::Response do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - @cim_response = '1,1,1,This transaction has been approved.,000000,Y,2000000000,none,Test transaction for ValidateCustomerPaymentProfile.,0.01,CC,auth_only,custId123,John,Doe,,123 Main St.,Bellevue,WA,98004,USA,000-000-0000,,mark@example.com,,,,,,,,,0.00,0.00,0.00,,none,D18EB6B211FE0BBF556B271FDA6F92EE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,' - end - - it "should support a Nokogiri based raw_response" do - builder = Nokogiri::XML::Builder.new(encoding: 'utf-8') do |x| - x.directResponse(@cim_response) - end - @element = builder.doc.children[0] - @element.should be_kind_of(Nokogiri::XML::Element) - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, test: false) - response = AuthorizeNet::AIM::Response.new(@element, transaction) - response.success?.should be_truthy - response.response_reason_text.should == 'This transaction has been approved.' - end -end -=end diff --git a/spec/arb_spec.rb b/spec/arb_spec.rb deleted file mode 100644 index 34e2cfa..0000000 --- a/spec/arb_spec.rb +++ /dev/null @@ -1,268 +0,0 @@ -=begin -require "spec_helper" - -describe AuthorizeNet::ARB::Transaction do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - @gateway = :sandbox - @subscription = AuthorizeNet::ARB::Subscription.new( - name: "monthly foo", - length: 1, - unit: AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH, - start_date: Date.today, - total_occurrences: 1, - trial_occurrences: nil, - amount: 10.00, - trial_amount: nil, - invoice_number: rand, - description: "a test subscription", - subscription_id: nil, - customer: AuthorizeNet::Customer.new(email: rand(10_000_000).to_s + 'pb@mail.com', id: rand(10_000_000).to_s), - credit_card: AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')), - billing_address: AuthorizeNet::Address.new(first_name: 'John', last_name: 'Doe') - ) - end - - it "should support instantiation" do - AuthorizeNet::ARB::Transaction.new(@api_login, @api_key).should be_instance_of(AuthorizeNet::ARB::Transaction) - end - - it "should not have a response if the transaction hasn't been run" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: @gateway) - transaction.has_response?.should be_falsey - end - - it "should support the returning its response object" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: @gateway) - transaction.should respond_to(:response) - end - - it "should know if its running against the sandbox or not" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.test?.should be_truthy - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: 'sandbox') - transaction.test?.should be_truthy - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :live) - transaction.test?.should be_falsey - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: 'live') - transaction.test?.should be_falsey - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: 'moose') - transaction.test?.should be_truthy - end - - it "should have a response after running a transaction" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = transaction.create({}) - response.should be_instance_of(AuthorizeNet::ARB::Response) - end - - it "should support creating a subscription" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = transaction.create(@subscription) - response.success?.should be_truthy - end - - it "should support canceling a subscription" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = transaction.create(@subscription) - response.success?.should be_truthy - cancel = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = cancel.cancel(response.subscription_id) - response.success?.should be_truthy - end - - it "should support getting the status of a subscription" do - create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = create.create(@subscription) - response.success?.should be_truthy - status = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = status.get_status(response.subscription_id) - response.success?.should be_truthy - response.subscription_status.should == AuthorizeNet::ARB::Subscription::Status::ACTIVE - end - - it "should support updating a subscription" do - create = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - response = create.create(@subscription) - response.success?.should be_truthy - update = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - subscription = AuthorizeNet::ARB::Subscription.new(subscription_id: response.subscription_id, billing_address: AuthorizeNet::Address.new(first_name: 'Jane', last_name: 'Doe')) - response = update.update(subscription) - response.success?.should be_truthy - end - - it "should be able to retrieve list of subscriptions" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - sorting = AuthorizeNet::ARB::Sorting.new('name', true) - paging = AuthorizeNet::ARB::Paging.new(1, 1000) - response = transaction.get_subscription_list('subscriptionActive', sorting, paging) - response.success?.should be_truthy - - if response.subscription_details.nil? - warn "no subscriptons found - please create some." - else - response.subscription_details.length.should > 0 - end - end - - it "should return successful response for valid subscription list search types and sortBy fields" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(1, 1000) - - # iterate over valid search types - %i[cardExpiringThisMonthsubscriptionActivesubscriptionExpiringThisMonth - subscriptionInactive].each do |searchType| - # iterate over valid sortBy fields - %i[idnamestatuscreateTimeStampUTClastNamefirstNameaccountNumberamount - pastOccurrences].each do |sortBy| - sorting = AuthorizeNet::ARB::Sorting.new(sortBy, false) - response = transaction.get_subscription_list(searchType, sorting, paging) - response.success?.should be_truthy - end - end - end - - it "should return error when invalid search type specified" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(1, 1000) - sorting = AuthorizeNet::ARB::Sorting.new(:name, true) - - response = transaction.get_subscription_list(:bogusSearchType, sorting, paging) - response.success?.should be_falsey - end - - it "should return error when invalid sortBy field specified" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(1, 1000) - sorting = AuthorizeNet::ARB::Sorting.new(:bogusSortField, true) - - response = transaction.get_subscription_list(:subscriptionActive, sorting, paging) - response.success?.should be_falsey - end - - it "should return error when invalid order descending parameter is specified" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(1, 1000) - sorting = AuthorizeNet::ARB::Sorting.new(:name, 2) - - response = transaction.get_subscription_list(:subscriptionActive, sorting, paging) - response.success?.should be_falsey - end - - it "should return error when invalid paging offset is specified" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(0, 1000) - sorting = AuthorizeNet::ARB::Sorting.new(:name, false) - - response = transaction.get_subscription_list(:subscriptionActive, sorting, paging) - response.success?.should be_falsey - end - - it "should return error when invalid paging limit is specified" do - transaction = AuthorizeNet::ARB::Transaction.new(@api_login, @api_key, gateway: :sandbox) - paging = AuthorizeNet::ARB::Paging.new(1, -1) - sorting = AuthorizeNet::ARB::Sorting.new(:name, false) - - response = transaction.get_subscription_list(:subscriptionActive, sorting, paging) - response.success?.should be_falsey - end -end - -describe AuthorizeNet::ARB::Response do - before :all do - begin - creds = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml") - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - end - - it "should support instantiation" do - AuthorizeNet::ARB::Response.new('', nil).should be_instance_of(AuthorizeNet::ARB::Response) - end -end - -describe AuthorizeNet::ARB::Subscription do - before do - @attributes = %i[name length unit start_date total_occurrences trial_occurrences amount trial_amount invoice_number description subscription_id] - @attribute_values = { - name: "daily foo", - length: 1, - unit: AuthorizeNet::ARB::Subscription::IntervalUnits::DAY, - start_date: Date.today, - total_occurrences: 1, - trial_occurrences: nil, - amount: 10.00, - trial_amount: nil, - invoice_number: '123456', - description: "a test subscription", - subscription_id: nil, - credit_card: AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')), - billing_address: AuthorizeNet::Address.new(first_name: 'John', last_name: 'Doe') - } - end - - it "should support instantiation" do - AuthorizeNet::ARB::Subscription.new.should be_instance_of(AuthorizeNet::ARB::Subscription) - end - - it "should support access to its attributes" do - subscription = AuthorizeNet::ARB::Subscription.new(@attribute_values) - @attribute_values.each do |k, v| - subscription.send(k).should == v - end - end - - it "should support connivence values for unlimited subscription total occurrences" do - subscription = AuthorizeNet::ARB::Subscription.new(total_occurrences: :unlimited) - subscription.total_occurrences.should == AuthorizeNet::ARB::Subscription::UNLIMITED_OCCURRENCES - subscription = AuthorizeNet::ARB::Subscription.new - subscription.total_occurrences = :unlimited - subscription.total_occurrences.should == AuthorizeNet::ARB::Subscription::UNLIMITED_OCCURRENCES - end - - it "should support connivence values for day interval units" do - subscription = AuthorizeNet::ARB::Subscription.new(unit: :day) - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY - subscription = AuthorizeNet::ARB::Subscription.new(unit: :days) - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY - subscription = AuthorizeNet::ARB::Subscription.new - subscription.unit = :day - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY - subscription = AuthorizeNet::ARB::Subscription.new - subscription.unit = :days - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::DAY - end - - it "should support connivence values for month interval units" do - subscription = AuthorizeNet::ARB::Subscription.new(unit: :month) - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH - subscription = AuthorizeNet::ARB::Subscription.new(unit: :months) - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH - subscription = AuthorizeNet::ARB::Subscription.new - subscription.unit = :month - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH - subscription = AuthorizeNet::ARB::Subscription.new - subscription.unit = :months - subscription.unit.should == AuthorizeNet::ARB::Subscription::IntervalUnits::MONTH - end -end -=end \ No newline at end of file diff --git a/spec/authorize_net_spec.rb b/spec/authorize_net_spec.rb deleted file mode 100644 index 28b517c..0000000 --- a/spec/authorize_net_spec.rb +++ /dev/null @@ -1,219 +0,0 @@ -=begin -require "spec_helper" - -describe AuthorizeNet do - it "should have a module called AuthorizeNet" do - defined?(AuthorizeNet).should be_truthy - AuthorizeNet.class.should equal(Module) - end - - it "should have a module called AIM" do - defined?(AuthorizeNet::AIM).should be_truthy - AuthorizeNet::AIM.class.should equal(Module) - end -end - -describe AuthorizeNet::CreditCard do - before do - @card_number = '4111111111111111' - @expiry = '01' + (Time.now + (3600 * 24 * 365)).strftime('%y') - end - - it "should support instantiation" do - AuthorizeNet::CreditCard.new(@card_number, @expiry).should be_instance_of(AuthorizeNet::CreditCard) - end - - it "should support converting itself into a hash" do - card = AuthorizeNet::CreditCard.new(@card_number, @expiry) - card.should respond_to(:to_hash) - card.to_hash.should be_kind_of(Hash) - end - - it "should have the right payment method type" do - card = AuthorizeNet::CreditCard.new(@card_number, @expiry) - fields = card.to_hash - fields[:method].should == AuthorizeNet::PaymentMethodType::CREDIT_CARD - end - - it "should respond to attributes" do - card = AuthorizeNet::CreditCard.new(@card_number, @expiry) - card.card_number.should == @card_number - card.expiration.should == @expiry - card.card_code.should be_nil - end - # it 'should clean the track' do - # card = AuthorizeNet::CreditCard.new(@card_number, @expiry, track_1: '%1111111111111111=11111111111111111111?3', track_2: ';2222222222222222=22222222222222222222?3') - # card_hash = card.to_hash - # expect(card_hash[:track_1]).to eq('1111111111111111=11111111111111111111') - # expect(card_hash[:track_2]).to eq('2222222222222222=22222222222222222222') - # - # card = AuthorizeNet::CreditCard.new(@card_number, @expiry, track_1: '1111111111111111=11111111111111111111', track_2: '2222222222222222=22222222222222222222') - # card_hash = card.to_hash - # expect(card_hash[:track_1]).to eq('1111111111111111=11111111111111111111') - # expect(card_hash[:track_2]).to eq('2222222222222222=22222222222222222222') - # end -end - -describe AuthorizeNet::ECheck do - before do - @routing_number = '322271627' - @account_number = '123456789' - @bank_name = 'JPMorgan Chase Bank' - @account_holder_name = 'John Doe' - end - - it "should support instantiation" do - AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name).should be_instance_of(AuthorizeNet::ECheck) - end - - it "should support converting itself into a hash" do - echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name) - echeck.should respond_to(:to_hash) - echeck.to_hash.should be_kind_of(Hash) - end - - it "should support payment method code retrival" do - echeck = AuthorizeNet::ECheck.new(@routing_number, @account_number, @bank_name, @account_holder_name) - fields = echeck.to_hash - fields[:method].should == AuthorizeNet::PaymentMethodType::ECHECK - end -end - -describe AuthorizeNet::Address do - before do - end - - it "should support instantiation" do - AuthorizeNet::Address.new.should be_instance_of(AuthorizeNet::Address) - end - - it "should support converting itself into a hash" do - address = AuthorizeNet::Address.new - address.should respond_to(:to_hash) - address.to_hash.should be_kind_of(Hash) - end - - it "should ignore unknown fields" do - address = AuthorizeNet::Address.new(tax: '123') - hash = address.to_hash - hash.should be_kind_of(Hash) - hash.should == {} - end - - it "should accept known fields" do - address = AuthorizeNet::Address.new(first_name: '123') - hash = address.to_hash - hash.should be_kind_of(Hash) - hash.should == { first_name: '123' } - end -end - -describe AuthorizeNet::ShippingAddress do - before do - end - - it "should support instantiation" do - AuthorizeNet::ShippingAddress.new.should be_instance_of(AuthorizeNet::ShippingAddress) - end - - it "should support converting itself into a hash" do - address = AuthorizeNet::ShippingAddress.new - address.should respond_to(:to_hash) - address.to_hash.should be_kind_of(Hash) - end - - it "should ignore unknown fields" do - address = AuthorizeNet::ShippingAddress.new(pie: '123') - hash = address.to_hash - hash.should be_kind_of(Hash) - hash.should == {} - end - - it "should accept known fields" do - address = AuthorizeNet::ShippingAddress.new(first_name: '123') - hash = address.to_hash - hash.should be_kind_of(Hash) - hash.should == { ship_to_first_name: '123' } - end -end - -describe AuthorizeNet::Customer do - before do - end - - it "should support instantiation" do - AuthorizeNet::Customer.new.should be_instance_of(AuthorizeNet::Customer) - end - - it "should support converting itself into a hash" do - customer = AuthorizeNet::Customer.new - customer.should respond_to(:to_hash) - customer.to_hash.should be_kind_of(Hash) - end - - it "should ignore unknown fields" do - customer = AuthorizeNet::Customer.new(name: '123') - hash = customer.to_hash - hash.should be_kind_of(Hash) - hash.should == {} - end - - it "should accept known fields" do - customer = AuthorizeNet::Customer.new(id: '123') - hash = customer.to_hash - hash.should be_kind_of(Hash) - hash.should == { cust_id: '123' } - end - - it "should accept an address record" do - address = AuthorizeNet::Address.new(first_name: 'Tester', last_name: 'Testerson') - customer = AuthorizeNet::Customer.new(address: address) - hash = customer.to_hash - hash.should be_kind_of(Hash) - hash.should == { first_name: 'Tester', last_name: 'Testerson' } - end -end - -describe AuthorizeNet::EmailReceipt do - before do - end - - it "should support instantiation" do - AuthorizeNet::EmailReceipt.new.should be_instance_of(AuthorizeNet::EmailReceipt) - end - - it "should support converting itself into a hash" do - email = AuthorizeNet::EmailReceipt.new - email.should respond_to(:to_hash) - email.to_hash.should be_kind_of(Hash) - end - - it "should ignore unknown fields" do - email = AuthorizeNet::EmailReceipt.new(name: '123') - hash = email.to_hash - hash.should be_kind_of(Hash) - hash.should == {} - end - - it "should accept known fields" do - email = AuthorizeNet::EmailReceipt.new(header: '123') - hash = email.to_hash - hash.should be_kind_of(Hash) - hash.should == { header: '123' } - end -end - -describe AuthorizeNet::TypeConversions do - subject do - Object.new.extend(described_class) - end - - it 'should convert decimal strings' do - subject.value_to_decimal('1.2345').should == BigDecimal('1.2345') - end - - it 'should convert empty decimal strings' do - subject.value_to_decimal('').should == BigDecimal('0.0') - end -end -=end diff --git a/spec/cim_spec.rb b/spec/cim_spec.rb deleted file mode 100644 index 37d4243..0000000 --- a/spec/cim_spec.rb +++ /dev/null @@ -1,490 +0,0 @@ -=begin -require "spec_helper" - -describe AuthorizeNet::CIM::Transaction do - let(:api_key) { credentials['api_transaction_key'] } - let(:api_login) { credentials['api_login_id'] } - let(:chrs) { [('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).flatten } - let(:gateway) { :sandbox } - let(:credit_card) { AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')) } - let(:profile) { AuthorizeNet::CIM::CustomerProfile.new(email: 'test@example.com', id: (0..19).map { chrs[rand(chrs.length)] }.join) } - let(:address) { AuthorizeNet::Address.new(first_name: 'Jane', last_name: 'Doe', address: '123 Fake St', city: 'Raccoon Junction', state: 'WY', zip: '99999') } - let(:partial_auth_address) { AuthorizeNet::Address.new(first_name: 'Jane', last_name: 'Doe', address: '123 Fake St', city: 'Raccoon Junction', state: 'WY', zip: '46225') } - let(:payment_profile) { AuthorizeNet::CIM::PaymentProfile.new(payment_method: credit_card) } - let(:partial_auth_payment_profile) { AuthorizeNet::CIM::PaymentProfile.new(payment_method: credit_card, billing_address: partial_auth_address) } - - def create_profile(profile) - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_profile) - response = transaction.create_profile(profile) - expect(response.success?).to eq true - expect(response.profile_id).not_to eq nil - response.profile_id - end - - def delete_profile(profile) - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.delete_profile(profile) - expect(response.success?).to eq true - end - - it "should support instantiation" do - expect(AuthorizeNet::CIM::Transaction.new(api_login, api_key)).to be_instance_of(AuthorizeNet::CIM::Transaction) - end - - it "should not have a response if the transaction hasn't been run" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: gateway) - expect(transaction.has_response?).to eq false - end - - it "should support the returning its response object" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: gateway) - expect(transaction).to respond_to(:response) - end - - it "should know if its running against the sandbox or not" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction.test?).to eq true - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: 'sandbox') - expect(transaction.test?).to eq true - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :live) - expect(transaction.test?).to eq false - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: 'live') - expect(transaction.test?).to eq false - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: 'moose') - expect(transaction.test?).to eq true - end - - it "should be able to create customer profiles" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_profile) - response = transaction.create_profile(profile) - expect(response.success?).to eq true - expect(response.profile_id).not_to eq nil - expect(response.address_ids).to eq nil - expect(response.payment_profile_ids).to eq nil - expect(response.validation_responses).to eq nil - end - - it "should be able to create customer profiles with payment profiles included" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_profile) - profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(payment_method: credit_card) - response = transaction.create_profile(profile) - expect(response.success?).to eq true - expect(response.profile_id).not_to eq nil - expect(response.address_ids).to eq nil - expect(response.payment_profile_ids).not_to eq nil - expect(response.validation_responses).to eq nil - end - - it "should be able to create customer profiles with payment profiles included and validated" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_profile) - profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(payment_method: credit_card) - response = transaction.create_profile(profile, validation_mode: :testMode) - expect(response.success?).to eq true - expect(response.profile_id).not_to eq nil - expect(response.address_ids).to eq nil - expect(response.payment_profile_ids).not_to eq nil - valdiation_responses = response.validation_responses - expect(valdiation_responses).not_to eq nil - expect(valdiation_responses.length).to eq 1 - expect(valdiation_responses[0]).to be_instance_of(AuthorizeNet::AIM::Response) - expect(valdiation_responses[0].success?).to eq true - end - - it "should be able to delete customer profiles" do - # create a profile to delete - profile_id = create_profile(profile) - - # delete it - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:delete_profile) - response = transaction.delete_profile(profile_id) - expect(response.success?).to eq true - end - - it "should be able to retrieve customer profiles" do - # create a profile to fetch - profile.payment_profiles = AuthorizeNet::CIM::PaymentProfile.new(payment_method: credit_card) - profile_id = create_profile(profile) - - # fetch the profile - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:get_profile) - response = transaction.get_profile(profile_id) - expect(response.success?).to eq true - profile = response.profile - expect(profile).to be_instance_of(AuthorizeNet::CIM::CustomerProfile) - expect(profile.payment_profiles.length).to eq 1 - expect(profile.payment_profiles.first).to be_instance_of(AuthorizeNet::CIM::PaymentProfile) - - # delete it - delete_profile(profile) - end - - it "should be able to update customer profiles" do - # build a profile - profile_id = create_profile(profile) - - profile.customer_profile_id = profile_id - profile.fax = '5551112222' - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_profile) - response = transaction.update_profile(profile) - expect(response.success?).to eq true - - delete_profile(profile_id) - end - - it "should be able to receive hosted profile access token" do - # build a profile - profile_id = create_profile(profile) - - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:get_hosted_profile_token) - - response = transaction.get_hosted_profile_token(profile_id) - - expect(response.success?).to eq true - expect(response.token).not_to be_empty - end - it "should be able to add line items to the order" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - # build a order with line item - order = AuthorizeNet::Order.new.add_line_item(101, 'Abc', 'Xyz', 2, 25.2, 1) - expect(order[0].id).to eq 101 - expect(order[0].name).to eq 'Abc' - expect(order[0].description).to eq 'Xyz' - expect(order[0].quantity).to eq 2 - expect(order[0].price).to eq 25.2 - expect(order[0].taxable).to eq 1 - end - describe "performing actions on payment profiles" do - def create_payment_profile(payment_profile, profile, validation_mode = :none) - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_payment_profile) - response = transaction.create_payment_profile(payment_profile, profile, validation_mode: validation_mode) - expect(response.success?).to eq true - expect(response.payment_profile_id).not_to eq nil - expect(response.validation_responses).to eq nil - response.payment_profile_id - end - - before do - profile.customer_profile_id = create_profile(profile) - payment_profile.customer_payment_profile_id = create_payment_profile(payment_profile, profile) - end - - after do - delete_profile(profile) - end - - it "should be able to create payment profiles" do - # handled by our before/after filters - end - - it "should be able to delete payment profiles" do - # delete the payment profile - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:delete_payment_profile) - response = transaction.delete_payment_profile(payment_profile, profile) - expect(response.success?).to eq true - end - - it "should be able to retrieve payment profiles" do - # get the payment profile - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:get_payment_profile) - response = transaction.get_payment_profile(payment_profile, profile) - expect(response.success?).to eq true - expect(response.payment_profile).to be_kind_of(AuthorizeNet::CIM::PaymentProfile) - end - - it "should be able to update payment profiles" do - payment_profile.cust_type = :business - - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_payment_profile) - response = transaction.update_payment_profile(payment_profile, profile) - expect(response.success?).to eq true - end - - it "should be able to update payment profiles with a masked exp date" do - payment_profile.cust_type = :business - - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_payment_profile) - @credit_card_with_masked_exp_date = AuthorizeNet::CreditCard.new('4111111111111111', 'XXXX') - payment_profile.payment_method = @credit_card_with_masked_exp_date - - response = transaction.update_payment_profile(payment_profile, profile) - expect(response.success?).to eq true - end - - it "should be able to validate payment profiles" do - payment_profile.cust_type = :business - - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_payment_profile) - response = transaction.update_payment_profile(payment_profile, profile, validation_mode: :testMode) - expect(response.success?).to eq true - expect(response.validation_response).not_to eq nil - expect(response.validation_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(response.validation_response.success?).to eq true - end - - describe "should be able to create payment transactions" do - before do - @amount = rand(100..10_099) / BigDecimal.new(100) - end - - it "should support authorization and capture transactions" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_auth_capture) - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, AuthorizeNet::Order.new) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should support authorization only transactions" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_auth_only) - response = transaction.create_transaction_auth_only(@amount, profile, payment_profile, AuthorizeNet::Order.new) - expect(response.message_text).to eq 'Successful.' - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should support prior authorization capture transactions" do - # create an auth only transaction - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.create_transaction_auth_only(@amount + 10, profile, payment_profile, AuthorizeNet::Order.new) - expect(response.message_text).to eq 'Successful.' - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response.success?).to eq true - - # capture it - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_prior_auth_capture) - response = transaction.create_transaction_prior_auth_capture(direct_response.transaction_id, @amount) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should support voiding a transaction" do - # create a transaction - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, AuthorizeNet::Order.new) - expect(response.message_text).to eq 'Successful.' - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response.success?).to eq true - - # void it - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_void) - response = transaction.create_transaction_void(direct_response.transaction_id) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - # it "should support refunding a transaction" - # this test won't be created. It requires overnight settlement in order to work. - - it "should support capture only transactions" - - it "should be able to support multiple payment profiles" do - partial_auth_payment_profile.customer_payment_profile_id = create_payment_profile(partial_auth_payment_profile, profile) - expect(partial_auth_payment_profile.customer_payment_profile_id).not_to eq nil - end - - it "should support validating a payment profile" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:validate_payment_profile) - response = transaction.validate_payment_profile(payment_profile, profile) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should support custom delimiters" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, AuthorizeNet::Order.new, aim_options: { delim_char: '$' }) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response.success?).to eq true - end - - it "should support custom fields" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, AuthorizeNet::Order.new, custom_fields: { foo: '123', bar: '456' }) - expect(response.message_text).to eq 'Successful.' - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response.success?).to eq true - expect(direct_response.custom_fields[:foo]).to eq '123' - expect(direct_response.custom_fields[:bar]).to eq '456' - end - - it "should support passing order fields including invoice number" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_auth_capture) - order = AuthorizeNet::Order.new - order.invoice_num = '11111' - order.description = 'This order includes invoice num' - order.po_num = 'PO_12345' - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, order) - expect(response.message_text).to eq 'Successful.' - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should support custom fields with custom delimeters" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - response = transaction.create_transaction_auth_capture(@amount, profile, payment_profile, AuthorizeNet::Order.new, custom_fields: { foo: '123', bar: '456' }, aim_options: { delim_char: '$' }) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response.success?).to eq true - expect(direct_response.custom_fields[:foo]).to eq '123' - expect(direct_response.custom_fields[:bar]).to eq '456' - end - - describe "should be able to update split transaction statuses" do - before do - # create partial payment profile - partial_auth_payment_profile.customer_payment_profile_id = create_payment_profile(partial_auth_payment_profile, profile) - - # create partial payment transaciton - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_auth_capture) - response = transaction.create_transaction_auth_capture(@amount, profile, partial_auth_payment_profile, AuthorizeNet::Order.new, aim_options: { allow_partial_auth: true }) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq false - expect(direct_response.response_code).to eq AuthorizeNet::AIM::Response::ResponseCode::HELD - expect(direct_response.fields[:amount]).to eq 1.23 - expect(direct_response.fields[:split_tender_id]).not_to eq nil - new_amount = @amount - direct_response.fields[:amount] - @split_tender_id = direct_response.fields[:split_tender_id] - - # create transaction for the remaining value - - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_transaction_auth_capture) - response = transaction.create_transaction_auth_capture(new_amount, profile, partial_auth_payment_profile, AuthorizeNet::Order.new, aim_options: { split_tender_id: @split_tender_id }) - expect(response.success?).to eq true - direct_response = response.direct_response - expect(direct_response).to be_instance_of(AuthorizeNet::AIM::Response) - expect(direct_response.success?).to eq true - end - - it "should be able to complete a split transaction" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_split_tender) - response = transaction.update_split_tender(@split_tender_id, :completed) - expect(response.success?).to eq true - end - - it "should be able to void a split transaction" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_split_tender) - response = transaction.update_split_tender(@split_tender_id, :voided) - expect(response.success?).to eq true - end - end - end - end - - describe "performing actions on addresses" do - def create_address(address, profile) - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:create_address) - response = transaction.create_address(address, profile) - expect(response.success?).to eq true - expect(response.address_id).not_to eq nil - - response.address_id - end - - before do - profile.customer_profile_id = create_profile(profile) - address.customer_address_id = create_address(address, profile) - end - - after do - delete_profile(profile) - end - - it "should be able to create addresses" do - # our before and after filters handle it all - end - - it "should be able to delete addresses" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:delete_address) - response = transaction.delete_address(address, profile) - expect(response.success?).to eq true - end - - it "should be able to retrieve addresses" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:get_address) - response = transaction.get_address(address, profile) - expect(response.success?).to eq true - expect(response.address).to be_kind_of(AuthorizeNet::Address) - end - - it "should be able to update addresses" do - address.zip = '55555' - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:update_address) - response = transaction.update_address(address, profile) - expect(response.success?).to eq true - end - end - - it "should be able to get all profile ids" do - transaction = AuthorizeNet::CIM::Transaction.new(api_login, api_key, gateway: :sandbox) - expect(transaction).to respond_to(:get_profile_ids) - response = transaction.get_profile_ids - expect(response).to be_kind_of(AuthorizeNet::CIM::Response) - expect(response.success?).to eq true - expect(response.profile_ids).not_to eq nil - end - - it "should be able to get zero profile ids when a merchant has zero customer profiles" do - # Using specific credentials for a Merchant which has zero customer profiles - # NOTE: These credentials are specific to this test - transaction = AuthorizeNet::CIM::Transaction.new("982fNqW7sZ", "3k2549N82e53gKHa", gateway: :sandbox) - expect(transaction).to respond_to(:get_profile_ids) - response = transaction.get_profile_ids - expect(response).to be_kind_of(AuthorizeNet::CIM::Response) - expect(response.success?).to eq true - expect(response.profile_ids).to eq nil - end -end - -describe AuthorizeNet::CIM::Response do - let(:api_key) { credentials['api_transaction_key'] } - let(:api_login) { credentials['api_login_id'] } - - it "should support instantiation" do - expect(AuthorizeNet::CIM::Response.new('', nil)).to be_instance_of(AuthorizeNet::CIM::Response) - end -end -=end diff --git a/spec/reporting_spec.rb b/spec/reporting_spec.rb deleted file mode 100644 index ff363e7..0000000 --- a/spec/reporting_spec.rb +++ /dev/null @@ -1,649 +0,0 @@ -require "spec_helper" - -describe AuthorizeNet::Reporting do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - it "should support instantiation" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should be_kind_of(AuthorizeNet::Reporting::Transaction) - end - - it "should be able to fetch a list of settled batches" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_settled_batch_list) - response = transaction.get_settled_batch_list - response.success?.should be_truthy - response.should respond_to(:batch_list) - end - - it "should be able to fetch a list of settled batches with start and end dates" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_settled_batch_list) - response = transaction.get_settled_batch_list(Time.now - (1 * 3600 * 12), Time.now) - response.success?.should be_truthy - response.should respond_to(:batch_list) - end - - it "should be able to fetch a list of settled batches with statistics" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_settled_batch_list) - response = transaction.get_settled_batch_list(nil, nil, true) - response.success?.should be_truthy - response.should respond_to(:batch_list) - end - - it "should be able to fetch a transaction list" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_list) - response = transaction.get_transaction_list('111111') - response.success?.should be_truthy - response.should respond_to(:transactions) - end - - it "should be able to fetch a list of unsettled transactions" do - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_unsettled_transaction_list) - response = transaction.get_unsettled_transaction_list - puts response.inspect unless response.success? - response.success?.should be_truthy - response.should respond_to(:transactions) - end - - it "should be able to fetch transaction details" do - # create a transaction to fetch - transaction = AuthorizeNet::AIM::Transaction.new(@api_login, @api_key, gateway: :sandbox) - credit_card = AuthorizeNet::CreditCard.new('4111111111111111', '1120') - transaction.set_fields(duplicate_window: 0) - response = transaction.purchase(10.0, credit_card) - - # fetch the transaction - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_details) - response = transaction.get_transaction_details(response.transaction_id) - response.success?.should be_truthy - response.should respond_to(:transaction) - end - # # To get this test to run. You must setup an ARB subscription. After the subscription runs a transaction get - # # the transaction_id and put it in this test. - # it "should be able to fetch transaction details with subscription info" do - # transaction_id = 2212429253 - # - # transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, :gateway => :sandbox) - # transaction.should respond_to(:get_transaction_details) - # detail_response = transaction.get_transaction_details(transaction_id) - # detail_response.success?.should be_truthy - # detail_response.should respond_to(:transaction) - # detail_response.transaction.subscription_id.should == 2072134 - # detail_response.transaction.subscription_paynum.should == 1 - # end - describe "parsing batch statistics" do - before do - @response = ' - - Ok - - I00001 - Successful. - - - - - 834677 - 2010-12-07T23:57:05Z - 2010-12-07T15:57:05 - settledSuccessfully - creditCard - - - Visa - 799.92 - 17 - 0.00 - 0 - 4 - 0 - 0 - - - - - 834801 - 2010-12-08T00:17:57Z - 2010-12-07T16:17:57 - settledSuccessfully - creditCard - - - Visa - 594.77 - 16 - 0.00 - 0 - 4 - 0 - 0 - - - - - 835158 - 2010-12-08T00:29:31Z - 2010-12-07T16:29:31 - settledSuccessfully - creditCard - - - Visa - 786.22 - 17 - 0.00 - 0 - 4 - 0 - 0 - - - - - 835509 - 2010-12-08T09:40:51Z - 2010-12-08T01:40:51 - settledSuccessfully - creditCard - - - Visa - 180.00 - 18 - 0.00 - 0 - 0 - 0 - 0 - - - - - 835896 - 2010-12-08T17:21:43Z - 2010-12-08T09:21:43 - settledSuccessfully - creditCard - - - Visa - 3357.32 - 67 - 0.00 - 0 - 16 - 1 - 0 - - - - - 836099 - 2010-12-08T19:52:26Z - 2010-12-08T11:52:26 - settledSuccessfully - creditCard - - - Visa - 973.24 - 17 - 0.00 - 0 - 4 - 0 - 0 - - - MasterCard - 973.24 - 17 - 0.00 - 0 - 4 - 0 - 0 - - - - - ' - end - - it "should be able to build a batch statistics entity" do - # stub our connection response - net_response = Net::HTTPOK.new('1.1', 200, 'OK') - net_response.stub(:body).and_return(@response) - connection = Net::HTTP.new('http://www.example.com') - connection.stub(:start).and_return(net_response) - Net::HTTP.stub(:new).and_return(connection) - - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_settled_batch_list) - response = transaction.get_settled_batch_list(nil, nil, true) - response.success?.should be_truthy - response.should respond_to(:batch_list) - batches = response.batch_list - batches.length.should == 6 - batches.each do |batch| - batch.statistics.should be_kind_of(Array) - batch.statistics[0].should be_kind_of(AuthorizeNet::Reporting::BatchStatistics) - next unless batch.id == '836099' - batch.statistics.length.should == 2 - batch.statistics[1].account_type.should == 'MasterCard' - batch.payment_method.should == 'creditCard' - batch.statistics[1].charge_amount.should == 973.24 - batch.statistics[1].void_count.should == 4 - end - end - end - - describe "parsing transaction details" do - it "should be able to build a transaction details object from the transaction list response" do - @response = ' - - Ok - - I00001 - Successful. - - - - - 2156238989 - 2010-12-07T23:50:02Z - 2010-12-07T15:50:02 - settledSuccessfully - Visa - XXXX1111 - 38.37 - - - 2156238988 - 2010-12-07T23:50:01Z - 2010-12-07T15:50:01 - voided - Visa - XXXX1111 - 0.00 - - - 2156246780 - 2010-12-08T09:31:01Z - 2010-12-08T01:31:01 - settledSuccessfully - 0.0119129953556076 - John - Doe - Visa - XXXX1111 - 10.00 - true - - 2334316 - 3 - - - - ' - - # stub our connection response - net_response = Net::HTTPOK.new('1.1', 200, 'OK') - net_response.stub(:body).and_return(@response) - connection = Net::HTTP.new('http://www.example.com') - connection.stub(:start).and_return(net_response) - Net::HTTP.stub(:new).and_return(connection) - - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_list) - response = transaction.get_settled_batch_list('111111') - response.success?.should be_truthy - response.should respond_to(:transactions) - transactions = response.transactions - transactions.length.should == 3 - transactions[0].account_type.should == 'Visa' - transactions[0].settle_amount.should == 38.37 - transactions[0].submitted_at.should == DateTime.parse('2010-12-07T23:50:02Z') - transactions[0].status = 'voided' - transactions[2].subscription_id.should == '2334316' - customer = transactions[2].customer - customer.nil?.should be_falsey - customer.address.nil?.should be_falsey - customer.address.first_name.should == 'John' - customer.address.last_name.should == 'Doe' - order = transactions[2].order - order.nil?.should be_falsey - order.invoice_num.should == '0.0119129953556076' - transactions[2].returns.should be_truthy - transactions[0].returns.should be_falsey - end - - it "should be able to build a transaction details object from the transaction details response" do - @response = ' - - Ok - - I00001 - Successful. - - - - 2156246780 - 2010-12-08T09:31:01.01Z - 2010-12-08T01:31:01.01 - authCaptureTransaction - settledSuccessfully - 1 - 1 - Approval - 5N3WKF - Y - - 835509 - 2010-12-08T09:40:51.12Z - 2010-12-08T01:40:51.12 - settledSuccessfully - - - 0.0119129953556076 - a test subscription - - 10.00 - 10.00 - - 0.99 - Local municipality sales tax - - - 15.00 - export - - - 5.20 - Ultra-fast 3 day shipping - - - - ITEM00001 - name of item sold - Description of item sold - 1 - 6.95 - true - - - ITEM00002 - name of item sold - Description of item sold - 1 - 7.95 - true - - - false - - - XXXX1111 - XXXX - Visa - - - - individual - ABC00001 - mark@example.com - - - John - Doe - - false - 127.0.0.1 - - ' - - # stub our connection response - net_response = Net::HTTPOK.new('1.1', 200, 'OK') - net_response.stub(:body).and_return(@response) - connection = Net::HTTP.new('http://www.example.com') - connection.stub(:start).and_return(net_response) - Net::HTTP.stub(:new).and_return(connection) - - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_details) - response = transaction.get_transaction_details('2212429253') - response.success?.should be_truthy - response.should respond_to(:transaction) - transaction = response.transaction - - transaction.should be_kind_of(AuthorizeNet::Reporting::TransactionDetails) - transaction.response_code.should == "1" - transaction.response_reason_code.should == "1" - transaction.response_reason_description.should == "Approval" - transaction.auth_code.should == "5N3WKF" - transaction.avs_response.should == 'Y' - transaction.auth_amount.should == 10.00 - transaction.settle_amount.should == 10.00 - transaction.order.tax.should == 0.99 - transaction.order.tax_description.should == 'Local municipality sales tax' - transaction.order.duty.should == 15.00 - transaction.order.duty_description.should == 'export' - transaction.order.freight.should == 5.20 - transaction.order.freight_description.should == 'Ultra-fast 3 day shipping' - transaction.recurring_billing.should be_truthy - - transaction.order.should be_kind_of(AuthorizeNet::Order) - transaction.order.line_items.should be_kind_of(Array) - transaction.order.line_items.length.should == 2 - transaction.order.line_items[0].should be_kind_of(AuthorizeNet::LineItem) - transaction.order.tax_exempt.should be_falsey - - transaction.payment_method.should be_kind_of(AuthorizeNet::CreditCard) - transaction.payment_method.card_number.should == 'XXXX1111' - - transaction.batch.should be_kind_of(AuthorizeNet::Reporting::Batch) - transaction.batch.id.should == '835509' - transaction.batch.settled_at.should == DateTime.civil(2010, 12, 8, 9, 40, 51) - - transaction.bill_to.should be_kind_of(AuthorizeNet::Address) - transaction.bill_to.first_name.should == 'John' - transaction.bill_to.last_name.should == 'Doe' - - transaction.customer.should be_kind_of(AuthorizeNet::Customer) - transaction.customer.ip.should == '127.0.0.1' - transaction.customer.id.should == 'ABC00001' - transaction.customer.email.should == 'mark@example.com' - transaction.customer.payment_profiles.should be_kind_of(Array) - transaction.customer.payment_profiles.length.should == 1 - transaction.customer.payment_profiles[0].cust_type.should == 'individual' - end - - it "should be able to build a transaction details object with subscription info from the transaction details response" do - @response = ' - - Ok - - I00001 - Successful. - - - - 2212429253 - 2014-05-04T08:51:10.79Z - 2014-05-04T01:51:10.79 - authCaptureTransaction - settledSuccessfully - 1 - 1 - - 2072134 - 1 - - Approval - JJRP3T - Y - - 3395320 - 2014-05-05T02:04:50.827Z - 2014-05-04T19:04:50.827 - settledSuccessfully - - 40000.00 - 40000.00 - false - - - XXXX1111 - XXXX - Visa - - - - Third - Time - - false - Card Not Present - eCommerce - - ' - - # stub our connection response - net_response = Net::HTTPOK.new('1.1', 200, 'OK') - net_response.stub(:body).and_return(@response) - connection = Net::HTTP.new('http://www.example.com') - connection.stub(:start).and_return(net_response) - Net::HTTP.stub(:new).and_return(connection) - - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_details) - response = transaction.get_transaction_details('2212429253') - response.success?.should be_truthy - response.should respond_to(:transaction) - transaction = response.transaction - - transaction.should be_kind_of(AuthorizeNet::Reporting::TransactionDetails) - transaction.response_code.should == "1" - transaction.response_reason_code.should == "1" - transaction.response_reason_description.should == "Approval" - transaction.subscription_id.should == 2_072_134 - transaction.subscription_paynum.should == 1 - transaction.auth_code.should == "JJRP3T" - transaction.avs_response.should == 'Y' - transaction.auth_amount.should == 40_000.00 - transaction.settle_amount.should == 40_000.00 - transaction.recurring_billing.should be_truthy - end - - it "should be able to build an echeck transaction details object with returned items and solution from the transaction details response" do - @response = ' - - Ok - - I00001 - Successful. - - - - 2148887936 - 2014-05-27T19:25:27.23Z - 2014-05-27T12:25:27.23 - authCaptureTransaction - settledSuccessfully - 1 - 1 - Approval - P - - 10155860 - 2014-05-27T19:25:28.237Z - 2014-05-27T12:25:28.237 - settledSuccessfully - - - QaInv01vgphtbrhbdh - - 12.00 - 12.00 - false - - - XXXX0204 - XXXX2516 - Account Owner - WEB - - - false - - - 2148887937 - 2014-05-27T19:25:49Z - 2014-05-27T12:25:49 - R02 - Account Closed - - - 2148887938 - 2014-06-27T19:25:49Z - 2014-06-27T12:25:49 - R03 - Test - - - - A1000004 - Volusion Shopping Cart - - - ' - - # stub our connection response - net_response = Net::HTTPOK.new('1.1', 200, 'OK') - net_response.stub(:body).and_return(@response) - connection = Net::HTTP.new('http://www.example.com') - connection.stub(:start).and_return(net_response) - Net::HTTP.stub(:new).and_return(connection) - - transaction = AuthorizeNet::Reporting::Transaction.new(@api_login, @api_key, gateway: :sandbox) - transaction.should respond_to(:get_transaction_details) - response = transaction.get_transaction_details('2212429253') - response.success?.should be_truthy - response.should respond_to(:transaction) - transaction = response.transaction - - transaction.should be_kind_of(AuthorizeNet::Reporting::TransactionDetails) - transaction.response_code.should == "1" - transaction.response_reason_code.should == "1" - transaction.response_reason_description.should == "Approval" - transaction.solution_id = 'A1000004' - transaction.solution_name = 'Volusion Shopping Cart' - - transaction.returns.returned_items.length.should == 2 - transaction.returns.returned_items.should be_kind_of(Array) - transaction.returns.returned_items[0].should be_kind_of(AuthorizeNet::Reporting::ReturnedItem) - transaction.returns.returned_items[0].id = 2_148_887_938 - transaction.returns.returned_items[0].code = 'R02' - transaction.returns.returned_items[0].code = 'Account Closed' - end - end -end diff --git a/spec/sim_spec.rb b/spec/sim_spec.rb deleted file mode 100644 index 99d3185..0000000 --- a/spec/sim_spec.rb +++ /dev/null @@ -1,95 +0,0 @@ -=begin -require "spec_helper" - -describe AuthorizeNet::SIM::Transaction do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - @amount = 10.00 - @fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3' - @sequence = '123456789' - @timestamp = '987654321' - end - - it "should support instantiation" do - AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount).should be_instance_of(AuthorizeNet::SIM::Transaction) - end - - it "should generate a correct fingerprint" do - transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, sequence: @sequence, timestamp: @timestamp) - transaction.fingerprint.should == @fingerprint - end - - it "should provide the actual values used to build the fingerprint" do - transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount) - hash = transaction.fingerprint_fields - transaction2 = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount, sequence: hash[:fp_sequence], timestamp: hash[:fp_timestamp]) - hash[:fp_hash].should == transaction2.fingerprint - end - - it "should provide a hash of all the form fields, ready for conversion to HTML" do - transaction = AuthorizeNet::SIM::Transaction.new('TEST', 'TEST', @amount) - transaction.form_fields.should be_kind_of(Hash) - transaction.form_fields.should have_key(:x_fp_hash) - end - - it "should know if its in test mode" do - transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, test: true) - transaction.test?.should be_truthy - transaction = AuthorizeNet::SIM::Transaction.new(@api_login, @api_key, @amount, test: false) - transaction.test?.should be_falsey - end -end - -describe AuthorizeNet::SIM::Response do - before :all do - begin - creds = credentials - @api_key = creds['api_transaction_key'] - @api_login = creds['api_login_id'] - rescue Errno::ENOENT => e - @api_key = "TEST" - @api_login = "TEST" - warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml." - end - end - - before do - @amount = rand(100..10_099) / BigDecimal.new(100) - @fingerprint = 'a8ea7b27729daf76d4a67bdb7d0a2fa3' - @sequence = '123456789' - @timestamp = '987654321' - end - - it "should support instantiation" do - AuthorizeNet::SIM::Response.new('').should be_instance_of(AuthorizeNet::SIM::Response) - end - - it "should support parsing the response into fields" do - response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe') - response.fields.should have_key(:first_name) - response.fields.should have_key(:last_name) - end - - it "should be able to build a Direct Post Method URL with fields from the response" do - response = AuthorizeNet::SIM::Response.new('x_first_name=John&x_last_name=Doe') - response.direct_post_url('http://www.example.com/').should == 'http://www.example.com/?x_first_name=John&x_last_name=Doe' - end -end - -describe AuthorizeNet::SIM::HostedPaymentForm do - it "should support instantiation" do - AuthorizeNet::SIM::HostedPaymentForm.new.should be_instance_of(AuthorizeNet::SIM::HostedPaymentForm) - end -end -=end \ No newline at end of file