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
112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/adyen_notification.rb', line 112 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
92 93 94 |
# File 'app/models/adyen_notification.rb', line 92 def event_code == AUTHORISATION end |
#auto_captured? ⇒ Boolean
152 153 154 |
# File 'app/models/adyen_notification.rb', line 152 def auto_captured? payment_method_auto_capture_only? || bank_transfer? end |
#bank_transfer? ⇒ Boolean
140 141 142 |
# File 'app/models/adyen_notification.rb', line 140 def bank_transfer? self.payment_method.match(/^bankTransfer/) end |
#cancel_or_refund? ⇒ Boolean
100 101 102 |
# File 'app/models/adyen_notification.rb', line 100 def cancel_or_refund? event_code == CANCEL_OR_REFUND end |
#capture? ⇒ Boolean
96 97 98 |
# File 'app/models/adyen_notification.rb', line 96 def capture? event_code == CAPTURE end |
#duplicate? ⇒ Boolean
144 145 146 147 148 149 150 |
# File 'app/models/adyen_notification.rb', line 144 def duplicate? self.class.exists?( psp_reference: self.psp_reference, event_code: self.event_code, success: self.success ) end |
#modification_event? ⇒ Boolean
125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/adyen_notification.rb', line 125 def modification_event? [ CANCELLATION, REFUND, CANCEL_OR_REFUND, CAPTURE, CAPTURE_FAILED, REFUND_FAILED, REFUNDED_REVERSED ].member? self.event_code end |
#money ⇒ Object
160 161 162 |
# File 'app/models/adyen_notification.rb', line 160 def money ::Money.new(value, currency) end |
#normal_event? ⇒ Boolean
136 137 138 |
# File 'app/models/adyen_notification.rb', line 136 def normal_event? AUTHORISATION == self.event_code end |
#payment ⇒ Object
85 86 87 |
# File 'app/models/adyen_notification.rb', line 85 def payment Spree::Payment.find_by response_code: original_reference || psp_reference end |
#payment_method_auto_capture_only? ⇒ Boolean
156 157 158 |
# File 'app/models/adyen_notification.rb', line 156 def payment_method_auto_capture_only? AUTO_CAPTURE_ONLY_METHODS.member?(self.payment_method) end |
#processed! ⇒ Object
108 109 110 |
# File 'app/models/adyen_notification.rb', line 108 def processed! update! processed: true end |
#refund? ⇒ Boolean
104 105 106 |
# File 'app/models/adyen_notification.rb', line 104 def refund? event_code == REFUND end |