class Kojn::Ipn
Constants
- ENCRYPTION
- INTEGRITY
Attributes
content[RW]
invoice[RW]
mode[RW]
token[RW]
Public Class Methods
new(params)
click to toggle source
# File lib/kojn/ipn.rb, line 8 def initialize params self.content = params self.ensure_secure(params) if params['token'] self.mode = Kojn::Ipn::INTEGRITY self.invoice = params['invoice'] self.token = params['token'] raise AuthenticityException.new("ERROR -*- IPN Could not be verified. Please notify Kojn authors. This message has been fabricated. -*- ERROR") unless self.authentic? elsif params['iv'] self.mode = Kojn::Ipn::ENCRYPTION self.decrypt end # Create a real object. self.invoice = Kojn::Invoice.new(self.invoice) end
Public Instance Methods
authentic?()
click to toggle source
# File lib/kojn/ipn.rb, line 28 def authentic? raise AuthenticityException.new("Checking if message is authentic while mode is set to Encryption") unless self.mode == Kojn::Ipn::INTEGRITY sha = Digest::SHA2.hexdigest "#{Kojn.api_key}#{self.invoice['internal_id']}#{self.invoice['received_amount']}" Rails.logger.info "sha: #{sha} tokne: #{self.token}" sha == self.token end
decrypt()
click to toggle source
# File lib/kojn/ipn.rb, line 37 def decrypt self.invoice = Kojn::crypto.decrypt_params(self.content) end
ensure_secure(params)
click to toggle source
# File lib/kojn/ipn.rb, line 41 def ensure_secure(params) if (params['token'] && Kojn.ipn_sec == :integrity) || (params['iv'] && Kojn.ipn_sec == :encryption) true else raise Kojn::AuthenticityException.new("ERROR -*- IPN security expected: #{Kojn.ipn_sec}. Opposite was found. -*- ERROR") end end