Class: OffsitePayments::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/offsite_payments/notification.rb

Direct Known Subclasses

Integrations::A1agregator::Notification, Integrations::AuthorizeNetSim::Notification, Integrations::BitPay::Notification, Integrations::Bogus::Notification, Integrations::Chronopay::Notification, Integrations::Citrus::Notification, Integrations::Coinbase::Notification, Integrations::DirecPay::Notification, Integrations::Directebanking::Notification, Integrations::Doku::Notification, Integrations::Dotpay::Notification, Integrations::Dwolla::Notification, Integrations::EPaymentPlans::Notification, Integrations::EasyPay::Notification, Integrations::Epay::Notification, Integrations::Gestpay::Notification, Integrations::HiTrust::Notification, Integrations::Ipay88::Notification, Integrations::Klarna::Notification, Integrations::Liqpay::Notification, Integrations::Maksuturva::Notification, Integrations::MollieIdeal::Notification, Integrations::MollieMistercash::Notification, Integrations::Molpay::Notification, Integrations::Moneybookers::Notification, Integrations::Nochex::Notification, Integrations::PagSeguro::Notification, Integrations::Paxum::Notification, Integrations::PayFast::Notification, Integrations::Paydollar::Notification, Integrations::PayflowLink::Notification, Integrations::Paypal::Notification, Integrations::Paysbuy::Notification, Integrations::PayuIn::Notification, Integrations::Platron::Notification, Integrations::Pxpay::Notification, Integrations::Quickpay::Notification, Integrations::Rbkmoney::Notification, Integrations::RealexOffsite::Notification, Integrations::Robokassa::Notification, Integrations::SagePayForm::Notification, Integrations::TwoCheckout::Notification, Integrations::Universal::Notification, Integrations::Valitor::Notification, Integrations::Verkkomaksut::Notification, Integrations::WebPay::Notification, Integrations::Webmoney::Notification, Integrations::WirecardCheckoutPage::Notification, Integrations::WorldPay::Notification

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

  • Args :

    • doc -> raw post string

    • options -> custom options which individual implementations can

      utilize
      

14
15
16
17
18
# File 'lib/offsite_payments/notification.rb', line 14

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

Instance Attribute Details

#paramsObject

Returns the value of attribute params


3
4
5
# File 'lib/offsite_payments/notification.rb', line 3

def params
  @params
end

#rawObject

Returns the value of attribute raw


4
5
6
# File 'lib/offsite_payments/notification.rb', line 4

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 rubymoney.github.io/money/


35
36
37
38
# 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!Object

reset the notification.


41
42
43
44
# File 'lib/offsite_payments/notification.rb', line 41

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

#grossObject

the money amount we received in X.2 decimal.

Raises:

  • (NotImplementedError)

25
26
27
# File 'lib/offsite_payments/notification.rb', line 25

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

#gross_centsObject


29
30
31
# File 'lib/offsite_payments/notification.rb', line 29

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

#iso_currencyObject


56
57
58
# File 'lib/offsite_payments/notification.rb', line 56

def iso_currency
  ActiveUtils::CurrencyCode.standardize(currency)
end

#statusObject

Raises:

  • (NotImplementedError)

20
21
22
# File 'lib/offsite_payments/notification.rb', line 20

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

#test?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/offsite_payments/notification.rb', line 52

def test?
  false
end

#valid_sender?(ip) ⇒ Boolean

Check if the request comes from an official IP

Returns:

  • (Boolean)

47
48
49
50
# 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