class OffsitePayments::Notification

Attributes

params[RW]
raw[RW]

Public Class Methods

new(post, options = {}) click to toggle source
  • Args :

    • doc -> raw post string

    • options -> custom options which individual implementations can

      utilize
      
# File lib/offsite_payments/notification.rb, line 14
def initialize(post, options = {})
  @options = options
  empty!
  parse(post)
end

Public Instance Methods

amount() click to toggle source

This combines the gross and currency and returns a proper Money object. this requires the money library located at rubymoney.github.io/money/

# File lib/offsite_payments/notification.rb, line 35
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!() click to toggle source

reset the notification.

# File lib/offsite_payments/notification.rb, line 41
def empty!
  @params  = Hash.new
  @raw     = ""
end
gross() click to toggle source

the money amount we received in X.2 decimal.

# File lib/offsite_payments/notification.rb, line 25
def gross
  raise NotImplementedError, "Must implement this method in the subclass"
end
gross_cents() click to toggle source
# File lib/offsite_payments/notification.rb, line 29
def gross_cents
  (gross.to_f * 100.0).round
end
iso_currency() click to toggle source
# File lib/offsite_payments/notification.rb, line 56
def iso_currency
  ActiveUtils::CurrencyCode.standardize(currency)
end
status() click to toggle source
# File lib/offsite_payments/notification.rb, line 20
def status
  raise NotImplementedError, "Must implement this method in the subclass"
end
test?() click to toggle source
# File lib/offsite_payments/notification.rb, line 52
def test?
  false
end
valid_sender?(ip) click to toggle source

Check if the request comes from an official IP

# File lib/offsite_payments/notification.rb, line 47
def valid_sender?(ip)
  return true if OffsitePayments.mode == :test || production_ips.blank?
  production_ips.include?(ip)
end

Private Instance Methods

parse(post) click to toggle source

Take the posted data and move the relevant data into a hash

# File lib/offsite_payments/notification.rb, line 63
def parse(post)
  @raw = post.to_s
  for line in @raw.split('&')
    key, value = *line.scan( %r{^([A-Za-z0-9_.-]+)\=(.*)$} ).flatten
    params[key] = CGI.unescape(value.to_s) if key.present?
  end
end