Class: Adyen::Notification

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/adyen/notification.rb

Overview

The Adyen::Notification class handles notifications sent by Adyen to your servers.

Because notifications contain important payment status information, you should store these notifications in your database. For this reason, Adyen::Notification inherits from ActiveRecord::Base, and a migration is included to simply create a suitable table to store the notifications in.

Adyen can either send notifications to you via HTTP POST requests, or SOAP requests. Because SOAP is not really well supported in Rails and setting up a SOAP server is not trivial, only handling HTTP POST notifications is currently supported.

Examples:

@notification = Adyen::Notification::HttpPost.log(request)
if @notification.successful_authorisation?
  @invoice = Invoice.find(@notification.merchant_reference)
  @invoice.set_paid!
end

See Also:

Direct Known Subclasses

HttpPost

Defined Under Namespace

Classes: HttpPost, Migration

Constant Summary collapse

DEFAULT_TABLE_NAME =

The default table name to use for the notifications table.

:adyen_notifications

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log(params) ⇒ Adyen::Notification

Logs an incoming notification into the database.

Parameters:

  • params (Hash)

    The notification parameters that should be stored in the database.

Returns:

Raises:

  • This method will raise an exception if the notification cannot be stored.

See Also:



49
50
51
52
53
54
55
56
57
58
# File 'lib/adyen/notification.rb', line 49

def self.log(params)
  converted_params = {}
  # Convert each attribute from CamelCase notation to under_score notation
  # For example, merchantReference will be converted to merchant_reference
  params.each do |key, value|
    field_name                   = key.to_s.underscore
    converted_params[field_name] = value if self.column_names.include?(field_name)
  end
  self.create!(converted_params)
end

Instance Method Details

#authorisation?true, false Also known as: authorization?

Returns true if this notification is an AUTHORISATION notification

Returns:

  • (true, false)

    true iff event_code == ‘AUTHORISATION’

See Also:

  • Adyen.notification#successful_authorisation?


63
64
65
# File 'lib/adyen/notification.rb', line 63

def authorisation?
  event_code == 'AUTHORISATION'
end

#collect_payment_for_recurring_contract!(options) ⇒ Object

Collect a payment using the recurring contract that was initiated with this notification. The payment is collected using a SOAP call to the Adyen SOAP service for recurring payments.

Parameters:

  • options (Hash)

    The payment parameters.

See Also:

  • SOAP::RecurringService#submit


84
85
86
87
88
89
# File 'lib/adyen/notification.rb', line 84

def collect_payment_for_recurring_contract!(options)
  # Make sure we convert the value to cents
  options[:value] = Adyen::Formatter::Price.in_cents(options[:value])
  raise "This is not a recurring contract!" unless event_code == 'RECURRING_CONTRACT'
  Adyen::SOAP::RecurringService.submit(options.merge(:recurring_reference => self.psp_reference))
end

#deactivate_recurring_contract!(options) ⇒ Object

Deactivates the recurring contract that was initiated with this notification. The contract is deactivated by sending a SOAP call to the Adyen SOAP service for recurring contracts.

Parameters:

  • options (Hash)

    The recurring contract parameters.

See Also:

  • SOAP::RecurringService#deactivate


96
97
98
99
# File 'lib/adyen/notification.rb', line 96

def deactivate_recurring_contract!(options)
  raise "This is not a recurring contract!" unless event_code == 'RECURRING_CONTRACT'
  Adyen::SOAP::RecurringService.deactivate(options.merge(:recurring_reference => self.psp_reference))
end

#successful_authorisation?true, false Also known as: successful_authorization?

Returns true if this notification is an AUTHORISATION notification and the success status indicates that the authorization was successfull.

Returns:

  • (true, false)

    true iff the notification is an authorization and the authorization was successful according to the success field.



73
74
75
# File 'lib/adyen/notification.rb', line 73

def successful_authorisation?
  event_code == 'AUTHORISATION' && success?
end