Class: CompletePaymentSystems::Response
- Inherits:
-
Object
- Object
- CompletePaymentSystems::Response
- Defined in:
- lib/complete_payment_systems/response_processing.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#response_hash ⇒ Object
readonly
Returns the value of attribute response_hash.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
-
#initialize(xml) ⇒ Response
constructor
A new instance of Response.
- #ok? ⇒ Boolean
- #signature_ok? ⇒ Boolean
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
#code ⇒ Object (readonly)
Returns the value of attribute code.
4 5 6 |
# File 'lib/complete_payment_systems/response_processing.rb', line 4 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
4 5 6 |
# File 'lib/complete_payment_systems/response_processing.rb', line 4 def @message end |
#response_hash ⇒ Object (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 |
#xml ⇒ Object (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
13 14 15 |
# File 'lib/complete_payment_systems/response_processing.rb', line 13 def ok? return signature_ok? && .match(CPS.config.success_regex).present? && code == "000" end |
#signature_ok? ⇒ 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 |