Class: AdyenNotification

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

Overview

The AdyenNotification 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, AdyenNotification 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 = AdyenNotification.log(request)
if @notification.successful_authorisation?
  @invoice = Invoice.find(@notification.merchant_reference)
  @invoice.set_paid!
end

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:

  • (Adyen::Notification)

    The initiated and persisted notification instance.

Raises:

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

See Also:

  • Adyen::Notification::HttpPost.log


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/adyen/templates/notification_model.rb', line 38

def self.log(params)
  # Assign explicit each attribute from CamelCase notation to notification
  # For example, merchantReference will be converted to merchant_reference
  self.new.tap do |notification|
    params.each do |key, value|
      setter = "#{key.to_s.underscore}="
      notification.send(setter, value) if notification.respond_to?(setter)
    end

    notification.save!
  end
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?


54
55
56
# File 'lib/adyen/templates/notification_model.rb', line 54

def authorisation?
  event_code == 'AUTHORISATION'
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.



64
65
66
# File 'lib/adyen/templates/notification_model.rb', line 64

def successful_authorisation?
  authorisation? && success?
end