lib/offsite_payments/integrations/authorize_net_sim.rb
# Add a line item to Authorize.Net.
# Call line add_line_item {:name => 'orange', :unit_price => 30, :tax_value => 'Y', :quantity => 3, }
# Note you can't pass in a negative unit price, and you can add an
# optional :line_title => 'special name' if you don't want it to say
# 'Item 1' or what not, the default coded here.
# Cannot have a negative price, nor a name with "'s or $
# You can use the :line_title for the product name and then :name for description, if desired
Add a line item to Authorize.Net.
Add a line item to Authorize . Net .
def add_line_item(options)
          raise 'needs name' unless options[:name]
          if @line_item_count == 30
            description_of_last = @raw_html_fields[-1][1]
            description_of_last =~ />([^>]*)<\|>[YN]$/
            @raw_html_fields[-1][1] = description_of_last.gsub($1, $1[0..200] + ' + more unshown items after this one.')
          end
          name = options[:name]
          quantity = options[:quantity] || 1
          line_title = options[:line_title] || ('Item ' + (@line_item_count + 1).to_s) 
          unit_price = options[:unit_price] || 0
          unit_price = unit_price.to_f.round(2)
          tax_value = options[:tax_value] || 'N'
           Authorize.net ignores the second field (sanitized_short_name)
          raise 'illegal char for line item <|>' if name.include? '<|>'
          raise 'illegal char for line item "' if name.include? '"'
          raise 'cannot pass in dollar sign' if unit_price.to_s.include? '$'
          raise 'must have positive or 0 unit price' if unit_price.to_f < 0
           Using CGI::escape causes the output to be formated incorrectly in
           the HTML presented to the end-user's browser (e.g., spaces turn
           into +'s).
          sanitized_short_name = name[0..30]
          name = name[0..255]
          add_raw_html_field "x_line_item", "{line_title}<|>{sanitized_short_name}<|>{name}<|>{quantity}<|>{unit_price}<|>{tax_value}"
          @line_item_count += 1
        end
def add_line_item ( options ) raise 'needs name' unless options [ :name ] if @line_item_count == 30 description_of_last = @raw_html_fields [ - 1 ] [ 1 ] description_of_last =~ / >([^>]*)< \| >[YN]$ / @raw_html_fields [ - 1 ] [ 1 ] = description_of_last . gsub ( $1 , $1 [ 0 .. 200 ] + ' + more unshown items after this one.' ) end name = options [ :name ] quantity = options [ :quantity ] || 1 line_title = options [ :line_title ] || ( 'Item ' + ( @line_item_count + 1 ) . to_s ) unit_price = options [ :unit_price ] || 0 unit_price = unit_price . to_f . round ( 2 ) tax_value = options [ :tax_value ] || 'N' raise 'illegal char for line item <|>' if name . include? '<|>' raise 'illegal char for line item "' if name . include? '"' raise 'cannot pass in dollar sign' if unit_price . to_s . include? '$' raise 'must have positive or 0 unit price' if unit_price . to_f < 0 sanitized_short_name = name [ 0 .. 30 ] name = name [ 0 .. 255 ] add_raw_html_field "x_line_item" , "#{line_title}<|>#{sanitized_short_name}<|>#{name}<|>#{quantity}<|>#{unit_price}<|>#{tax_value}" @line_item_count += 1 end
Add a line item to Authorize.Net.
Add a line item to Authorize . Net .
# Add a note that we are not showing at least one -- AN doesn't # display more than 30 or so. # Pull off the second to last section, which is the description. # Create a new description, which can't be too big, so truncate here. # left most field # Sanitization, in case they include a reserved word here, following # their guidelines; unfortunately, they require 'raw' fields here, # not CGI escaped, using their own delimiters. # # Authorize.net ignores the second field (sanitized_short_name) # Using CGI::escape causes the output to be formated incorrectly in # the HTML presented to the end-user's browser (e.g., spaces turn # into +'s).
options
<not_specific>