Class: AdyenNotification
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AdyenNotification
- Defined in:
- app/models/adyen_notification.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.
Constant Summary collapse
- AUTO_CAPTURE_ONLY_METHODS =
[ "ideal", "c_cash", "directEbanking", "trustly", "giropay", "bcmc" ].freeze
- AUTHORISATION =
"AUTHORISATION".freeze
- CANCELLATION =
"CANCELLATION".freeze
- REFUND =
"REFUND".freeze
- CANCEL_OR_REFUND =
"CANCEL_OR_REFUND".freeze
- CAPTURE =
"CAPTURE".freeze
- CAPTURE_FAILED =
"CAPTURE_FAILED".freeze
- REFUND_FAILED =
"REFUND_FAILED".freeze
- REFUNDED_REVERSED =
"REFUNDED_REVERSED".freeze
Class Method Summary collapse
-
.build(params) ⇒ Adyen::Notification
Logs an incoming notification into the database.
Instance Method Summary collapse
- #actions ⇒ Object
-
#authorisation? ⇒ true, false
(also: #authorization?)
Returns true if this notification is an AUTHORISATION notification.
- #auto_captured? ⇒ Boolean
- #bank_transfer? ⇒ Boolean
- #cancel_or_refund? ⇒ Boolean
- #capture? ⇒ Boolean
- #duplicate? ⇒ Boolean
- #modification_event? ⇒ Boolean
- #money ⇒ Object
- #normal_event? ⇒ Boolean
- #payment ⇒ Object
- #payment_method_auto_capture_only? ⇒ Boolean
- #processed! ⇒ Object
- #refund? ⇒ Boolean
Class Method Details
.build(params) ⇒ Adyen::Notification
Logs an incoming notification into the database.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/adyen_notification.rb', line 70 def self.build(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}=" # don't assign if value is empty string. if notification.respond_to?(setter) && value.present? notification.send(setter, value) end end end end |
Instance Method Details
#actions ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'app/models/adyen_notification.rb', line 123 def actions if operations operations. split(","). map(&:downcase) else [] end end |
#authorisation? ⇒ true, false Also known as:
Returns true if this notification is an AUTHORISATION notification
103 104 105 |
# File 'app/models/adyen_notification.rb', line 103 def event_code == AUTHORISATION end |
#auto_captured? ⇒ Boolean
163 164 165 |
# File 'app/models/adyen_notification.rb', line 163 def auto_captured? payment_method_auto_capture_only? || bank_transfer? end |
#bank_transfer? ⇒ Boolean
151 152 153 |
# File 'app/models/adyen_notification.rb', line 151 def bank_transfer? self.payment_method.match(/^bankTransfer/) end |
#cancel_or_refund? ⇒ Boolean
111 112 113 |
# File 'app/models/adyen_notification.rb', line 111 def cancel_or_refund? event_code == CANCEL_OR_REFUND end |
#capture? ⇒ Boolean
107 108 109 |
# File 'app/models/adyen_notification.rb', line 107 def capture? event_code == CAPTURE end |
#duplicate? ⇒ Boolean
155 156 157 158 159 160 161 |
# File 'app/models/adyen_notification.rb', line 155 def duplicate? self.class.exists?( psp_reference: self.psp_reference, event_code: self.event_code, success: self.success ) end |
#modification_event? ⇒ Boolean
136 137 138 139 140 141 142 143 144 145 |
# File 'app/models/adyen_notification.rb', line 136 def modification_event? [ CANCELLATION, REFUND, CANCEL_OR_REFUND, CAPTURE, CAPTURE_FAILED, REFUND_FAILED, REFUNDED_REVERSED ].member? self.event_code end |
#money ⇒ Object
171 172 173 |
# File 'app/models/adyen_notification.rb', line 171 def money ::Money.new(value, currency) end |
#normal_event? ⇒ Boolean
147 148 149 |
# File 'app/models/adyen_notification.rb', line 147 def normal_event? AUTHORISATION == self.event_code end |
#payment ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/adyen_notification.rb', line 85 def payment reference = original_reference || psp_reference payment_with_reference = Spree::Payment.find_by response_code: reference return payment_with_reference if payment_with_reference # If no reference take the last payment in the associated order where the # response_code was nil. if order order .payments .where(source_type: "Spree::Adyen::HppSource", response_code: nil) .last end end |
#payment_method_auto_capture_only? ⇒ Boolean
167 168 169 |
# File 'app/models/adyen_notification.rb', line 167 def payment_method_auto_capture_only? AUTO_CAPTURE_ONLY_METHODS.member?(self.payment_method) end |
#processed! ⇒ Object
119 120 121 |
# File 'app/models/adyen_notification.rb', line 119 def processed! update! processed: true end |
#refund? ⇒ Boolean
115 116 117 |
# File 'app/models/adyen_notification.rb', line 115 def refund? event_code == REFUND end |