Class: Adyen::Notification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Adyen::Notification
- 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.
Direct Known Subclasses
Defined Under Namespace
Constant Summary collapse
- DEFAULT_TABLE_NAME =
The default table name to use for the notifications table.
:adyen_notifications
Class Method Summary collapse
-
.log(params) ⇒ Adyen::Notification
Logs an incoming notification into the database.
Instance Method Summary collapse
-
#authorisation? ⇒ true, false
(also: #authorization?)
Returns true if this notification is an AUTHORISATION notification.
-
#collect_payment_for_recurring_contract!(options) ⇒ Object
Collect a payment using the recurring contract that was initiated with this notification.
-
#deactivate_recurring_contract!(options) ⇒ Object
Deactivates the recurring contract that was initiated with this notification.
-
#successful_authorisation? ⇒ true, false
(also: #successful_authorization?)
Returns true if this notification is an AUTHORISATION notification and the success status indicates that the authorization was successfull.
Class Method Details
.log(params) ⇒ Adyen::Notification
Logs an incoming notification into the database.
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:
Returns true if this notification is an AUTHORISATION notification
63 64 65 |
# File 'lib/adyen/notification.rb', line 63 def 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.
84 85 86 87 88 89 |
# File 'lib/adyen/notification.rb', line 84 def collect_payment_for_recurring_contract!() # Make sure we convert the value to cents [:value] = Adyen::Formatter::Price.in_cents([:value]) raise "This is not a recurring contract!" unless event_code == 'RECURRING_CONTRACT' Adyen::SOAP::RecurringService.submit(.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.
96 97 98 99 |
# File 'lib/adyen/notification.rb', line 96 def deactivate_recurring_contract!() raise "This is not a recurring contract!" unless event_code == 'RECURRING_CONTRACT' Adyen::SOAP::RecurringService.deactivate(.merge(:recurring_reference => self.psp_reference)) end |
#successful_authorisation? ⇒ true, false Also known as:
Returns true if this notification is an AUTHORISATION notification and the success status indicates that the authorization was successfull.
73 74 75 |
# File 'lib/adyen/notification.rb', line 73 def event_code == 'AUTHORISATION' && success? end |