Class: CompletePaymentSystems::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/complete_payment_systems/response_processing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
# File 'lib/complete_payment_systems/response_processing.rb', line 6

def initialize(xml)
  @xml = xml #|| File.read("#{CPS.root}/response.xml")
  @response_hash = parse_response(@xml)
  @code = @response_hash["resultCode"]
  @message = @response_hash["resultMessage"]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/complete_payment_systems/response_processing.rb', line 4

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



4
5
6
# File 'lib/complete_payment_systems/response_processing.rb', line 4

def message
  @message
end

#response_hashObject (readonly)

Returns the value of attribute response_hash.



4
5
6
# File 'lib/complete_payment_systems/response_processing.rb', line 4

def response_hash
  @response_hash
end

#xmlObject (readonly)

Returns the value of attribute xml.



4
5
6
# File 'lib/complete_payment_systems/response_processing.rb', line 4

def xml
  @xml
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/complete_payment_systems/response_processing.rb', line 13

def ok?
  return signature_ok? && message.match(CPS.config.success_regex).present? && code == "000"
end

#signature_ok?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
# File 'lib/complete_payment_systems/response_processing.rb', line 17

def signature_ok?
  digi_signature = response_hash["digiSignature"]
  hash_string = build_hashable_string
  decoded_resp = Base64.decode64(digi_signature)
  public_key = OpenSSL::X509::Certificate.new(
    File.read "#{CPS.root}/lib/complete_payment_systems/certs/cps.cer").
    public_key
  return public_key.verify(OpenSSL::Digest::SHA1.new, decoded_resp, hash_string)
end