Skip to content
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

Can I use this library for WebHooks too? #63

Closed
bhaidar opened this issue Mar 27, 2024 · 2 comments · Fixed by #64
Closed

Can I use this library for WebHooks too? #63

bhaidar opened this issue Mar 27, 2024 · 2 comments · Fixed by #64
Labels
documentation Improvements or additions to documentation question Further information is requested

Comments

@bhaidar
Copy link

bhaidar commented Mar 27, 2024

Hi @amcintosh

First of all, does this package support WebHooks? Is there a sample code that first verifies and then listens to WebHook events from FreshBooks?

Thanks
Bill

@amcintosh
Copy link
Owner

amcintosh commented Mar 28, 2024

Hi!

So the library does support the registration and verification of callbacks.
See https://amcintosh.github.io/freshbooks-php-sdk/html/classes/amcintosh-FreshBooks-FreshBooksClient.html#method_callbacks
and https://amcintosh.github.io/freshbooks-php-sdk/html/classes/amcintosh-FreshBooks-Resource-EventsResource.html#method_verify

There's no example code at the moment, nor examples on checking the verification header, though the FreshBooks API docs does have a python example of that:

# Using Flask:
import base64
import hmac
import hashlib
import json

from flask import Flask, request

def signature_match(verifier, request):
    signature = request.headers.get('X-FreshBooks-Hmac-SHA256')
    data = json.dumps(request.form)

    dig = hmac.new(
        verifier.encode('utf-8'),
        msg=data.encode('utf-8'),
        digestmod=hashlib.sha256
    ).digest()
    calculated_sig = base64.b64encode(dig).decode()

    return signature == calculated_sig

I can look into writing a PHP example but I hope the above helps in the meantime.

@amcintosh amcintosh added documentation Improvements or additions to documentation question Further information is requested labels Mar 30, 2024
amcintosh added a commit that referenced this issue Mar 30, 2024
Add webhook information to SDK documentation
Add a webhooks flow example. This requires some setup and a local
server, so information on how to do that is included.

Closes #63
@amcintosh
Copy link
Owner

@bhaidar I've added a webhooks example and some more documentation on their use in this PR.

Hope that helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants