Class: Paypal::Webhooks::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/paypal/webhooks/event.rb

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

VALID_PAYPAL_CERT_CN =
"messageverificationcerts.paypal.com".freeze
VALID_PAYPAL_CERT_HOST =
"api.paypal.com".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params:, request:) ⇒ Event

Returns a new instance of Event.



19
20
21
22
23
# File 'lib/paypal/webhooks/event.rb', line 19

def initialize(params:, request:)
  @request = request
  @body = request.body&.read
  @params = params
end

Class Method Details

.cert_cacheObject



10
11
12
# File 'lib/paypal/webhooks/event.rb', line 10

def cert_cache
  @cert_cache ||= {}
end

.clear_cert_cacheObject



14
15
16
# File 'lib/paypal/webhooks/event.rb', line 14

def clear_cert_cache
  @cert_cache = nil
end

Instance Method Details

#dataObject



37
38
39
# File 'lib/paypal/webhooks/event.rb', line 37

def data
  @data ||= Util.deep_symbolize_keys(@params)[:resource] || {}
end

#typeObject



33
34
35
# File 'lib/paypal/webhooks/event.rb', line 33

def type
  @params[:event_type]
end

#verifyObject



29
30
31
# File 'lib/paypal/webhooks/event.rb', line 29

def verify
  verify_cert_url && verify_cert && verify_signature
end

#verify!Object



25
26
27
# File 'lib/paypal/webhooks/event.rb', line 25

def verify!
  raise EventVerificationFailed unless verify
end