Class: IpnMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/generators/templates/ipn_message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_message(hash) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/generators/templates/ipn_message.rb', line 5

def self.create_from_message(hash)
	ipn_message = IpnMessage.new

	ipn_message.body = hash.to_yaml
	ipn_message.success = hash["ACK"] == "Success"
	ipn_message.correlation_id = hash["correlation_id"]
	ipn_message.transaction_id = hash["transaction_id"]

	ipn_message.save
	return ipn_message
end

Instance Method Details

#unique_idsObject

returns hash of unique_id:string => status:bool



18
19
20
21
22
23
24
25
26
# File 'lib/generators/templates/ipn_message.rb', line 18

def unique_ids
	hash = YAML.load(self.body)

	return hash.inject({}){|acc, (k,v)|
		k.to_s =~ /unique_id_(\d+)/
		acc[v] = hash["status_#{$1}"] == "Completed" if $1
		acc
	}
end