mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Merge pull request #13777 from rioug/13481-webhook-payment
Payment status change webhook
This commit is contained in:
@@ -101,6 +101,24 @@ module Spree
|
||||
end
|
||||
|
||||
after_transition to: :completed, do: :set_captured_at
|
||||
after_transition do |payment, transition|
|
||||
# Catch any exceptions to prevent any rollback potentially
|
||||
# preventing payment from going through
|
||||
ActiveSupport::Notifications.instrument(
|
||||
"ofn.payment_transition", payment: payment, event: transition.to
|
||||
)
|
||||
rescue StandardError => e
|
||||
Rails.logger.fatal "ActiveSupport::Notification.instrument failed params: " \
|
||||
"<event_type:ofn.payment_transition> " \
|
||||
"<payment_id:#{payment.id}> " \
|
||||
"<event:#{transition.to}>"
|
||||
Alert.raise(
|
||||
e,
|
||||
metadata: {
|
||||
event_tye: "ofn.payment_transition", payment_id: payment.id, event: transition.to
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def money
|
||||
|
||||
@@ -2,5 +2,11 @@
|
||||
|
||||
# Records a webhook url to send notifications to
|
||||
class WebhookEndpoint < ApplicationRecord
|
||||
WEBHOOK_TYPES = %w(order_cycle_opened payment_status_changed).freeze
|
||||
|
||||
validates :url, presence: true
|
||||
validates :webhook_type, presence: true, inclusion: { in: WEBHOOK_TYPES }
|
||||
|
||||
scope :order_cycle_opened, -> { where(webhook_type: "order_cycle_opened") }
|
||||
scope :payment_status, -> { where(webhook_type: "payment_status_changed") }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user