Class: QiwiObserver::Webhook

Inherits:
Object
  • Object
show all
Defined in:
lib/qiwi_observer/webhook/webhook.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Webhook

Returns a new instance of Webhook.

Raises:

  • (ArgumentError)


3
4
5
6
7
# File 'lib/qiwi_observer/webhook/webhook.rb', line 3

def initialize(key)
  raise ArgumentError, "Secret key must be set" unless key

  @key = key
end

Instance Method Details

#call(params) ⇒ Object



9
10
11
12
13
14
# File 'lib/qiwi_observer/webhook/webhook.rb', line 9

def call(params)
  return WebhookResponse.new(success: true, body: params) if params.dig(:test) == true
  return WebhookResponse.new(success: true, body: params) if sign_correct?(params)

  WebhookResponse.new(success: false, body: params.dig(:payment, :txnId))
end