lib/gocardless_pro/webhook.rb
# Validates that a webhook was genuinely sent by GoCardless using
# `.signature_valid?`, and then parses it into an array of
# `GoCardlessPro::Resources::Event` objects representing each event
# included in the webhook
#
# @option options [String] :request_body the request body
# @option options [String] :signature_header the signature included in the request,
#   found in the `Webhook-Signature` header
# @option options [String] :webhook_endpoint_secret the webhook endpoint secret for
#   your webhook endpoint, as configured in your GoCardless Dashboard
# @return [Array<GoCardlessPro::Resources::Event>] the events included
#   in the webhook
# @raise [InvalidSignatureError] if the signature header specified does not match
#   the signature computed using the request body and webhook endpoint secret
# @raise [ArgumentError] if a required keyword argument is not provided or is not
#   of the required type
Validates that a webhook was genuinely sent by GoCardless using
`.signature_valid?`, and then parses it into an array of
`GoCardlessPro::Resources::Event` objects representing each event
included in the webhook
Validates that a webhook was genuinely sent by GoCardless using ` . signature_valid? ` and then parses it into an array of ` GoCardlessPro :: Resources :: Event ` objects representing each event included in the webhook
def parse(options = {})
        validate_options!(options)
        unless signature_valid?(request_body: options[:request_body],
                                signature_header: options[:signature_header],
                                webhook_endpoint_secret: options[:webhook_endpoint_secret])
          raise InvalidSignatureError, "This webhook doesn't appear to be a genuine " \
                                        'webhook from GoCardless, because the signature ' \
                                        "header doesn't match the signature computed" \
                                        ' with your webhook endpoint secret.'
        end
        events = JSON.parse(options[:request_body])['events']
        events.map { |event| Resources::Event.new(event) }
      end
def parse ( options = { } ) validate_options! ( options ) unless signature_valid? ( request_body : options [ :request_body ] , signature_header : options [ :signature_header ] , webhook_endpoint_secret : options [ :webhook_endpoint_secret ] ) raise InvalidSignatureError , "This webhook doesn't appear to be a genuine " 'webhook from GoCardless, because the signature ' "header doesn't match the signature computed" ' with your webhook endpoint secret.' end events = JSON . parse ( options [ :request_body ] ) [ 'events' ] events . map { | event | Resources :: Event . new ( event ) } end
Validates that a webhook was genuinely sent by GoCardless using
`.signature_valid?`, and then parses it into an array of
`GoCardlessPro::Resources::Event` objects representing each event
included in the webhook
Validates that a webhook was genuinely sent by GoCardless using ` . signature_valid? ` and then parses it into an array of ` GoCardlessPro :: Resources :: Event ` objects representing each event included in the webhook
the events included in the webhook
the events included in the webhook
Array<GoCardlessPro::Resources::Event>
[InvalidSignatureError] if the signature header specified does not match the signature computed using the request body and webhook endpoint secret
[ InvalidSignatureError ] if the signature header specified does not match the signature computed using the request body and webhook endpoint secret
[ArgumentError] if a required keyword argument is not provided or is not of the required type
[ ArgumentError ] if a required keyword argument is not provided or is not of the required type
options
:webhook_endpoint_secret the webhook endpoint secret for your webhook endpoint, as configured in your GoCardless Dashboard
: webhook_endpoint_secret the webhook endpoint secret for your webhook endpoint as configured in your GoCardless Dashboard