Class: SecureTrading::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/secure_trading/request.rb

Defined Under Namespace

Classes: ConnectionFailed, ConnectionTimeout, PrematureXpayQuery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Request

Returns a new instance of Request.



11
12
13
# File 'lib/secure_trading/request.rb', line 11

def initialize(connection)
  @connection = connection
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



8
9
10
# File 'lib/secure_trading/request.rb', line 8

def connection
  @connection
end

#responseObject (readonly)

Returns the value of attribute response.



9
10
11
# File 'lib/secure_trading/request.rb', line 9

def response
  @response
end

Instance Method Details

#error_messageObject

 Returns the error message provided from Xpay



22
23
24
# File 'lib/secure_trading/request.rb', line 22

def error_message
  @error_message
end

#processObject

 Send the XML request, using the provided connection.



16
17
18
19
# File 'lib/secure_trading/request.rb', line 16

def process
  post_to_xpay!
  self.response.success?
end

#sanitized_xml_requestObject

Return a sanitized version of the xml request for storing in a data store. Sensitive card numbers and security codes will be replaced with asterisks and the certificate will be removed.



37
38
39
40
41
42
43
44
# File 'lib/secure_trading/request.rb', line 37

def sanitized_xml_request
  xml = xml_request.dup
  %w{ Number SecurityCode }.each do |field|
    xml.gsub!(/\<#{field}\>(.+)\<\/#{field}\>/) { "<#{field}>" + ('*' * $1.size) + "</#{field}>" }
  end
  xml.gsub!(/\<Certificate\>(.*)\<\/Certificate\>/m, '<Certificate>{FILTERED}</Certificate>')
  xml
end

#xml_requestObject

 Return the full XML request for this request. The full output from this method should be sent to the secure trading Xpay API.



28
29
30
31
32
33
# File 'lib/secure_trading/request.rb', line 28

def xml_request
  attributes = {}
  attributes['RequestBlock'] = {'Version' => SECURETRADING_API_VERSION}
  attributes['Request'] = {'Type' => self.request_type}
  @xml_request ||= Util.to_xml({'Request' => self.to_hash, 'Certificate' => self.connection.certificate}, :root => 'RequestBlock', :attributes => attributes)
end