Sha256: ed8e5b91d62039bc1f5dcb97653a4c80815312416b1085fd230f1f0333624649

Contents?: true

Size: 1.85 KB

Versions: 1

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
      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

1 entries across 1 versions & 1 rubygems

Version Path
datatrans-2.4.0 lib/datatrans/xml/transaction/authorize.rb