Skip to content

Fix and refactor webhook validation #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

unspok3n
Copy link

@unspok3n unspok3n commented Apr 8, 2025

Thanks for this awesome lib! Currently, the webhook validation seems to be a little bit broken because of the wrong types, missing fields in the Webhook struct and a typo in the (c *Cryptomus) VerifySign function (passing unmodified reqBody to the sign func)

This PR:

  • Makes nullable fields in the webhook struct pointers
  • Adds missing undocumented webhook fields (payer_amount, payer_amount_exchange_rate, transfer_id)
  • Moves verification logic from (c *Cryptomus) VerifySign to (w *Webhook) verify function
  • Makes signRequest a regular function (it didn't use any values from the receiver), so it can be called from (w *Webhook) verify
  • Escapes forward slash after marshalling modified webhook (txid contains a slash that has to be escaped https://doc.cryptomus.com/business/payments/webhook)
  • Adds webhook verification example to the README

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant