Module: Airwallex::Webhook
- Defined in:
- lib/airwallex/webhook.rb
Defined Under Namespace
Classes: Event
Constant Summary collapse
- DEFAULT_TOLERANCE =
5 minutes
300
Class Method Summary collapse
- .construct_event(payload, signature, timestamp, secret:, tolerance: DEFAULT_TOLERANCE) ⇒ Object
- .verify_signature(payload, signature, timestamp, secret, tolerance) ⇒ Object
Class Method Details
.construct_event(payload, signature, timestamp, secret:, tolerance: DEFAULT_TOLERANCE) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/airwallex/webhook.rb', line 11 def construct_event(payload, signature, , secret:, tolerance: DEFAULT_TOLERANCE) verify_signature(payload, signature, , secret, tolerance) data = JSON.parse(payload) Event.new(data) rescue JSON::ParserError => e raise SignatureVerificationError, "Invalid payload: #{e.}" end |
.verify_signature(payload, signature, timestamp, secret, tolerance) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/airwallex/webhook.rb', line 20 def verify_signature(payload, signature, , secret, tolerance) (, tolerance) expected_signature = compute_signature(, payload, secret) unless secure_compare(expected_signature, signature) raise SignatureVerificationError, "Signature verification failed" end true end |