lib/ideal/gateway.rb in ideal-0.2.0 vs lib/ideal/gateway.rb in ideal-0.9.0

- old
+ new

@@ -38,16 +38,11 @@ # Holds the passphrase that should be used for the merchant private_key. attr_accessor :passphrase # Holds the test and production urls for your iDeal acquirer. - attr_accessor :live_url, :test_url - - # For ABN AMRO only assign the three separate directory, transaction and status urls. - attr_accessor :live_directory_url, :test_directory_url - attr_accessor :live_transaction_url, :test_transaction_url - attr_accessor :live_status_url, :test_status_url + attr_accessor :live_url, :test_url end # Environment defaults to test self.environment = :test @@ -117,15 +112,10 @@ else raise ArgumentError, "Unknown acquirer `#{acquirer}', please choose one of: #{self.acquirers.keys.join(', ')}" end end - # Returns true when the acquirer was set to :abnamro - def self.abn_amro? - acquirer.to_sym == :abnamro - end - # Returns the merchant `subID' being used for this Gateway instance. # Defaults to 0. attr_reader :sub_id # Initializes a new Gateway instance. @@ -133,24 +123,24 @@ # You can optionally specify <tt>:sub_id</tt>. Defaults to 0. def initialize(options = {}) @sub_id = options[:sub_id] || 0 end - # Returns the endpoint for a certain request. + # Returns the endpoint for the request. # # Automatically uses test or live URLs based on the configuration. - def request_url(request_type) - self.class.send("#{self.class.environment}#{request_url_prefix(request_type)}_url") + def request_url + self.class.send("#{self.class.environment}_url") end # Sends a directory request to the acquirer and returns an # DirectoryResponse. Use DirectoryResponse#list to receive the # actuall array of available issuers. # # gateway.issuers.list # => [{ :id => '1006', :name => 'ABN AMRO Bank' }, …] def issuers - post_data request_url(:directory), build_directory_request_body, DirectoryResponse + post_data request_url, build_directory_request_body, DirectoryResponse end # Starts a purchase by sending an acquirer transaction request for the # specified +money+ amount in EURO cents. # @@ -194,11 +184,11 @@ # redirect_to transaction_response.service_url # end # # See the Gateway class description for a more elaborate example. def setup_purchase(money, options) - post_data request_url(:transaction), build_transaction_request_body(money, options), TransactionResponse + post_data request_url, build_transaction_request_body(money, options), TransactionResponse end # Sends a acquirer status request for the specified +transaction_id+ and # returns an StatusResponse. # @@ -214,27 +204,26 @@ # flash[:notice] = "Congratulations, you are now the proud owner of a Dutch windmill!" # end # # See the Gateway class description for a more elaborate example. def capture(transaction_id) - post_data request_url(:status), build_status_request_body(:transaction_id => transaction_id), StatusResponse + post_data request_url, build_status_request_body(:transaction_id => transaction_id), StatusResponse end private - # Returns the prefix to locate the setting for a certain request type. Only applies - # in the case of ABN AMRO because they use more than one endpoint. - def request_url_prefix(request_type) - (request_type && self.class.abn_amro?) ? "_#{request_type.to_s}" : nil - end - def ssl_post(url, body) - response = REST.post(url, body, {}, { + log('URL', url) + log('Request', body) + response = REST.post(url, body, { + 'Content-Type' => 'application/xml; charset=utf-8' + }, { :tls_verify => true, :tls_key => self.class.private_key, :tls_certificate => self.class.private_certificate }) + log('Response', response.body) response.body end def post_data(gateway_url, data, response_klass) response_klass.new(ssl_post(gateway_url, data), :test => self.class.test?) @@ -258,11 +247,11 @@ def token Digest::SHA1.hexdigest(self.class.private_certificate.to_der).upcase end def strip_whitespace(str) - self.class.abn_amro? ? str.gsub(/(\f|\n|\r|\t|\v)/m, '') : str.gsub(/\s/m,'') + str.gsub(/\s/m,'') end # Creates a +tokenCode+ from the specified +message+. def token_code(message) signature = self.class.private_key.sign(OpenSSL::Digest::SHA1.new, strip_whitespace(message)) @@ -418,8 +407,12 @@ [:language, LANGUAGE], [:description, options[:description]], [:entrance_code, options[:entrance_code]] ]] ]) + end + + def log(thing, contents) + $stderr.write("\n#{thing}:\n\n#{contents}\n") if $DEBUG end end end \ No newline at end of file