Module: CoinbaseCommerce::Webhook

Defined in:
lib/coinbase_commerce/webhooks.rb

Defined Under Namespace

Modules: WebhookSignature

Class Method Summary collapse

Class Method Details

.construct_event(payload, sig_header, secret) ⇒ Object

Analyze and construct appropriate event object based on webhook notification



6
7
8
9
10
11
12
13
14
15
# File 'lib/coinbase_commerce/webhooks.rb', line 6

def self.construct_event(payload, sig_header, secret)
  data = JSON.parse(payload, symbolize_names: true)
  if data.key?(:event)
    WebhookSignature.verify_header(payload, sig_header, secret)
    CoinbaseCommerce::APIResources::Event.create_from(data[:event])
  else
    raise CoinbaseCommerce::Errors::WebhookInvalidPayload.new("no event in payload",
                                                              sig_header, http_body: payload)
  end
end