Class: ActiveMerchant::Billing::Integrations::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/active_merchant/billing/integrations/notification.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post, options = {}) ⇒ Notification

Returns a new instance of Notification.



11
12
13
14
15
# File 'lib/active_merchant/billing/integrations/notification.rb', line 11

def initialize(post, options = {})
  @options = options
  empty!
  parse(post)
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/active_merchant/billing/integrations/notification.rb', line 5

def params
  @params
end

#rawObject

Returns the value of attribute raw.



6
7
8
# File 'lib/active_merchant/billing/integrations/notification.rb', line 6

def raw
  @raw
end

Instance Method Details

#amountObject

This combines the gross and currency and returns a proper Money object. this requires the money library located at dist.leetsoft.com/api/money



32
33
34
35
# File 'lib/active_merchant/billing/integrations/notification.rb', line 32

def amount
  return Money.new(gross_cents, currency) rescue ArgumentError
  return Money.new(gross_cents) # maybe you have an own money object which doesn't take a currency?
end

#empty!Object

reset the notification.



38
39
40
41
# File 'lib/active_merchant/billing/integrations/notification.rb', line 38

def empty!
  @params  = Hash.new
  @raw     = ""      
end

#grossObject

the money amount we received in X.2 decimal.

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/active_merchant/billing/integrations/notification.rb', line 22

def gross
  raise NotImplementedError, "Must implement this method in the subclass"
end

#gross_centsObject



26
27
28
# File 'lib/active_merchant/billing/integrations/notification.rb', line 26

def gross_cents
  (gross.to_f * 100.0).round
end

#statusObject

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/active_merchant/billing/integrations/notification.rb', line 17

def status
  raise NotImplementedError, "Must implement this method in the subclass"
end

#test?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/active_merchant/billing/integrations/notification.rb', line 49

def test?
  false
end

#valid_sender?(ip) ⇒ Boolean

Check if the request comes from an official IP

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/active_merchant/billing/integrations/notification.rb', line 44

def valid_sender?(ip)
  return true if ActiveMerchant::Billing::Base.integration_mode == :test || production_ips.blank?
  production_ips.include?(ip)
end