lib/active_merchant/billing/integrations/notification.rb in activemerchant-1.3.2 vs lib/active_merchant/billing/integrations/notification.rb in activemerchant-1.4.0
- old
+ new
@@ -2,10 +2,13 @@
module Billing #:nodoc:
module Integrations #:nodoc:
class Notification
attr_accessor :params
attr_accessor :raw
+
+ # set this to an array in the subclass, to specify which IPs are allowed to send requests
+ class_inheritable_accessor :production_ips
def initialize(post, options = {})
@options = options
empty!
parse(post)
@@ -34,10 +37,16 @@
# reset the notification.
def empty!
@params = Hash.new
@raw = ""
end
-
+
+ # Check if the request comes from an official IP
+ def valid_sender?(ip)
+ return true if ActiveMerchant::Billing::Base.integration_mode == :test || production_ips.blank?
+ production_ips.include?(ip)
+ end
+
private
# Take the posted data and move the relevant data into a hash
def parse(post)
@raw = post.to_s