Class: DefraRubyGovpay::WebhookBaseService

Inherits:
Object
  • Object
show all
Defined in:
lib/defra_ruby_govpay/services/webhook_base_service.rb

Direct Known Subclasses

WebhookPaymentService, WebhookRefundService

Defined Under Namespace

Classes: InvalidStatusTransition

Constant Summary collapse

VALID_STATUS_TRANSITIONS =

override this in subclasses

{}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#previous_statusObject

Returns the value of attribute previous_status.



10
11
12
# File 'lib/defra_ruby_govpay/services/webhook_base_service.rb', line 10

def previous_status
  @previous_status
end

#webhook_bodyObject

Returns the value of attribute webhook_body.



10
11
12
# File 'lib/defra_ruby_govpay/services/webhook_base_service.rb', line 10

def webhook_body
  @webhook_body
end

Class Method Details

.run(webhook_body, previous_status: nil) ⇒ Object



15
16
17
# File 'lib/defra_ruby_govpay/services/webhook_base_service.rb', line 15

def self.run(webhook_body, previous_status: nil)
  new.run(webhook_body, previous_status: previous_status)
end

Instance Method Details

#run(webhook_body, previous_status: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/defra_ruby_govpay/services/webhook_base_service.rb', line 19

def run(webhook_body, previous_status: nil)
  @webhook_body = webhook_body.deep_symbolize_keys
  @previous_status = previous_status

  validate_webhook_body

  # If we have a previous status and it's different from the current one, validate the transition
  if previous_status && previous_status != webhook_payment_or_refund_status
    validate_status_transition
  else
    DefraRubyGovpay.logger.warn(
      "Status \"#{@previous_status}\" unchanged in #{payment_or_refund_str} webhook update " \
      "#{log_webhook_context} "
    )
  end

  extract_data_from_webhook
end