4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/action_smser/delivery_reports_controller.rb', line 4
def gateway_commit
updated_count = 0
if !ActionSmser.delivery_options[:gateway_commit].blank? &&
!ActionSmser.delivery_options[:gateway_commit][params['gateway']].blank?
ActionSmser::Logger.info("Gateway_commit found parser for gateway: #{params['gateway']}")
dr_var_array = ActionSmser.delivery_options[:gateway_commit][params['gateway']].send(:process_delivery_report, request)
dr_array = []
if !dr_var_array.blank?
dr_var_array.each do |dr_update|
msg_id = dr_update["msg_id"]
dr = ActionSmser::DeliveryReport.where(:msg_id => msg_id).first
if dr
dr_update.each_pair do |key, value|
dr.send("#{key}=", value) if dr.attribute_names.include?(key.to_s)
end
if dr.save
updated_count += 1
dr_array << dr
ActionSmser::Logger.info("Gateway_commit updated item with id: #{msg_id}, params: #{dr_update.inspect}")
else
ActionSmser::Logger.info("Gateway_commit problem updating item with id: #{msg_id}, params: #{dr_update.inspect}")
end
else
ActionSmser::Logger.info("Gateway_commit not found item with id: #{msg_id}, params: #{dr_update.inspect}")
end
end
end
begin
ActionSmser.delivery_options[:gateway_commit_observers].each do |observer|
observer.after_gateway_commit(dr_array)
end
rescue Exception => e
ActionSmser::Logger.error("Problem with gateway_commit_observers: #{e}")
end
end
if updated_count > 0
render :text => "Updated info for #{updated_count} items"
else
render :text => "Not saved"
end
end
|