Processing webhooks
The following example of Ruby code illustrates how a method on the customer-hosted endpoint should process webhook event notifications and pings. In addition to requiring access to the webhook messages, this method requires the value of the webhook’ssecret field (this field is configured using the Marqeta platform’s /webhooks endpoint).
The method performs these actions:
First, it computes the message signature using the raw request body and the secret. It then compares the computed signature against the actual signature contained in the message. If the two signatures are equal, the signature is verified and the method proceeds to check whether the message is a ping or an event notification and processes the message accordingly.
If the signatures are not equal, the message is not verified and is processed accordingly.
Ruby
signature_algorithm field in the Marqeta platform’s /webhooks endpoint.
If you wish to change the signature algorithm used for verification from HMAC-SHA1 to HMAC-SHA256 for enhanced security, we recommend you allow a temporary fallback. Marqeta will retry failed webhook event notifications for up to two weeks. Therefore, for up to two weeks after changing your signature algorithm, you may still receive messages with signature generated using the original algorithm.
The following Ruby code illustrates how you may modify the above example to allow for either algorithm temporarily.
Ruby