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

Add deletion and raw http endpoint urls for Webhooks #304

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

Conversation

sfinktah
Copy link

WHY are these changes introduced?

I couldn't add a webhook, because it insists on making all HttpDelivery webhooks a path of Context::$HOST_NAME (which was myshop.myshopify.com), and I wanted a webhook on my server.

    public function getCallbackAddress(string $path): string
    {
        return 'https://' . Context::$HOST_NAME . '/' . ltrim($path, '/');
    }

I also couldn't delete a webhook.

WHAT is this pull request doing?

Added a new enum to Webhooks::Registry::register

            case self::DELIVERY_METHOD_RAW:
                $method = new HttpDeliveryRaw();
                break;

which doesn't try and get smart with the provided url

    public function getCallbackAddress(string $path): string
    {
        return $path;
    }

To allow deletion of webhooks with the maximum code re-use, I modified Webhooks::Registry::register to equate an empty $path with a request to delete the webhook.

        if (empty($path) && $webhookId) {
            $body = self::sendDeleteRequest(
                $client,
                $topic,
                $callbackAddress,
                $method,
                $webhookId
            );
            $registered = $method->isSuccess($body, $webhookId);
            return new RegisterResponse($registered, $body);
        }

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • [-] I have added/updated tests for this change
  • There are no existing tests for DELIVERY_METHOD_HTTP, so no reason to add any for DELIVERY_METHOD_RAW
  • Possibly there should be a test written for the deletion functionality, and I will do so if this PR receives tentative approval.
  • I have updated the documentation for public APIs from the library (if applicable)
    There's documentation?

@tectiv3
Copy link

tectiv3 commented Mar 10, 2024

because it insists on making all HttpDelivery webhooks a path of Context::$HOST_NAME

I also have this problem. Why does it do that?!
Maybe an easier (with a smaller footprint) fix would be to try to detect http in the path?

@sfinktah
Copy link
Author

because it insists on making all HttpDelivery webhooks a path of Context::$HOST_NAME

I also have this problem. Why does it do that?! Maybe an easier (with a smaller footprint) fix would be to try to detect http in the path?

Because it's retarded.

Making a clever fix like you suggest is how I would normally solve the problem myself, however with production code it is best not to change the behavior of existing functions.

@sfinktah
Copy link
Author

I have signed the CLA!

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.

None yet

2 participants