-
Notifications
You must be signed in to change notification settings - Fork 34
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
feature: added possibility to have a proxied webhook url #38
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,19 +43,23 @@ class WebhookService implements WebhookServiceInterface | |
|
||
private SystemConfigService $systemConfigService; | ||
|
||
private ?string $proxyWebhookUrl; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public function __construct( | ||
WebhookResource $webhookResource, | ||
WebhookRegistry $webhookRegistry, | ||
SystemConfigService $systemConfigService, | ||
RouterInterface $router | ||
RouterInterface $router, | ||
?string $proxyWebhookUrl | ||
) { | ||
$this->webhookResource = $webhookResource; | ||
$this->webhookRegistry = $webhookRegistry; | ||
$this->router = $router; | ||
$this->systemConfigService = $systemConfigService; | ||
$this->proxyWebhookUrl = $proxyWebhookUrl; | ||
} | ||
|
||
public function getStatus(?string $salesChannelId): string | ||
|
@@ -73,12 +77,18 @@ public function getStatus(?string $salesChannelId): string | |
|
||
$webhookExecuteToken = $this->systemConfigService->getString(Settings::WEBHOOK_EXECUTE_TOKEN, $salesChannelId); | ||
|
||
$this->router->getContext()->setScheme('https'); | ||
$webhookUrl = $this->router->generate( | ||
'api.action.paypal.webhook.execute', | ||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
); | ||
if ($this->proxyWebhookUrl !== null) { | ||
$webhookUrl = $this->proxyWebhookUrl . '?' . http_build_query( | ||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken] | ||
); | ||
} else { | ||
$this->router->getContext()->setScheme('https'); | ||
$webhookUrl = $this->router->generate( | ||
'api.action.paypal.webhook.execute', | ||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
); | ||
} | ||
|
||
return $registeredWebhookUrl === $webhookUrl ? self::STATUS_WEBHOOK_VALID : self::STATUS_WEBHOOK_INVALID; | ||
} | ||
|
@@ -96,12 +106,18 @@ public function registerWebhook(?string $salesChannelId): string | |
$webhookExecuteToken = Random::getAlphanumericString(self::PAYPAL_WEBHOOK_TOKEN_LENGTH); | ||
} | ||
|
||
$this->router->getContext()->setScheme('https'); | ||
$webhookUrl = $this->router->generate( | ||
'api.action.paypal.webhook.execute', | ||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
); | ||
if ($this->proxyWebhookUrl !== null) { | ||
$webhookUrl = $this->proxyWebhookUrl . '?' . http_build_query( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if the proxy already contains GET parameters? Maybe do a |
||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken] | ||
); | ||
} else { | ||
$this->router->getContext()->setScheme('https'); | ||
$webhookUrl = $this->router->generate( | ||
'api.action.paypal.webhook.execute', | ||
[self::PAYPAL_WEBHOOK_TOKEN_NAME => $webhookExecuteToken], | ||
UrlGeneratorInterface::ABSOLUTE_URL | ||
); | ||
} | ||
Comment on lines
+109
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please outsource this into an extra private method? So we don't have the duplicate code? |
||
|
||
$webhookId = $this->systemConfigService->getString(Settings::WEBHOOK_ID, $salesChannelId); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you do one more layer? so
Background: we will in a future iteration, add more config parameters to the yaml files, therefore we would like to have some sort of namespacing