Sha256: 9f1f8c8be3267388bd9ab9dd9ec0804ff317d0587b3a1e822aa0188e27777e2e

Contents?: true

Size: 1.93 KB

Versions: 7

Compression:

Stored size: 1.93 KB

Contents

require 'datatrans/xml/transaction/request'
require 'datatrans/xml/transaction/response'

class Datatrans::XML::Transaction
  class AuthorizeRequest < Request
    
    def process
      self.class.post(Datatrans.xml_authorize_url, 
        :headers => { 'Content-Type' => 'text/xml' },
        :body => build_authorize_request.to_s).parsed_response
    end
    
    
    private
    
    def build_authorize_request
      build_xml_request(:authorization) do |xml|
        xml.amount params[:amount]
        xml.currency params[:currency]
        xml.aliasCC params[:aliasCC]
        xml.expm params[:expm]
        xml.expy params[:expy]
        xml.sign sign(Datatrans.merchant_id, params[:amount], params[:currency], params[:refno])
      end
    end
    
  end
  
  class AuthorizeResponse < Response
    
    def successful?
      response_code == '01' && response_message == 'Authorized'
    end
    
    def response_code
      params_root_node['response']['responseCode'] rescue nil
    end
    
    def response_message
      params_root_node['response']['responseMessage'] rescue nil
    end
    
    def transaction_id
      params_root_node['response']['uppTransactionId'] rescue nil 
    end
    
    def reference_number
      params_root_node['refno'] rescue nil 
    end
    
    def authorization_code
      params_root_node['response']['authorizationCode'] rescue nil
    end

    def masked_cc
      params_root_node['response']['maskedCC'] rescue nil
    end
    
    def creditcard_alias
      params_root_node['request']['aliasCC'] rescue nil
    end
    
    def error_code
      params_root_node['error']['errorCode'] rescue nil 
    end
    
    def error_message
      params_root_node['error']['errorMessage'] rescue nil
    end
    
    def error_detail
      params_root_node['error']['errorDetail'] rescue nil
    end
    
    
    private
    
    def params_root_node
      params['authorizationService']['body']['transaction']
    end
    
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
datatrans-2.3.1 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.3.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.2.2 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.2.1 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.2.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.1.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-2.0.0 lib/datatrans/xml/transaction/authorize.rb