Sha256: ce863f53f8df389285bef5cd36072af46927660d4f3ecf863be9c6ef3fccc6b7

Contents?: true

Size: 1.85 KB

Versions: 7

Compression:

Stored size: 1.85 KB

Contents

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

class Datatrans::XML::Transaction
  class AuthorizeRequest < Request
    def process
      post(self.datatrans.url(: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(self.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-5.1.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-5.0.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-4.0.1 lib/datatrans/xml/transaction/authorize.rb
datatrans-4.0.0 lib/datatrans/xml/transaction/authorize.rb
datatrans-3.0.2 lib/datatrans/xml/transaction/authorize.rb
datatrans-3.0.1 lib/datatrans/xml/transaction/authorize.rb
datatrans-3.0.0 lib/datatrans/xml/transaction/authorize.rb