Skip to content

Commit d180c05

Browse files
Merge pull request #270 from Shopify/topic-name-graphql-transformation
Add support for Event topic names
2 parents 124976b + 69a8e1d commit d180c05

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
1414
- [#262](https://github.com/Shopify/shopify-api-php/pull/262) ⚠️ [Breaking] Added support for PHP 8.2, and removed support for PHP 7.4
1515
- [#264](https://github.com/Shopify/shopify-api-php/pull/264) [Patch] Remove support for currently-non-existent versions of PHP (8.3+)
1616
- [#272](https://github.com/Shopify/shopify-api-php/pull/272) ⚠️ [Breaking] Removed REST resources for 2022-01, update resources for remaining versions
17+
- [#270](https://github.com/Shopify/shopify-api-php/pull/270) [Patch] Add support for Event topic names
1718

1819
## v4.3.0 - 2023-04-12
1920

src/Webhooks/Registry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,6 @@ private static function validateProcessHmac(string $rawBody, string $hmac): void
295295
*/
296296
private static function convertTopic(string $topic): string
297297
{
298-
return strtoupper(str_replace('/', '_', $topic));
298+
return strtoupper(str_replace(['/', '.'], '_', $topic));
299299
}
300300
}

tests/Webhooks/RegistryTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,29 @@ public function testProcessWebhook()
408408
$this->assertNull($response->getErrorMessage());
409409
}
410410

411+
public function testHandlesVarianceInWebhookTopicNames()
412+
{
413+
$handler = $this->getMockHandler();
414+
$handler->expects($this->once())
415+
->method('handle')
416+
->with(
417+
"DOMAIN_SUB_DOMAIN_SOMETHING_HAPPENED",
418+
'test-shop.myshopify.io',
419+
$this->processBody,
420+
);
421+
422+
Registry::addHandler("DOMAIN_SUB_DOMAIN_SOMETHING_HAPPENED", $handler);
423+
424+
$processHeaders = [
425+
HttpHeaders::X_SHOPIFY_HMAC => '/Redz4YXHLnSmmSN8grr5/Jl/Ua3d7yX3iWbjb8R8wo=',
426+
HttpHeaders::X_SHOPIFY_TOPIC => 'domain.sub_domain.something_happened',
427+
HttpHeaders::X_SHOPIFY_DOMAIN => 'test-shop.myshopify.io',
428+
];
429+
$response = Registry::process($processHeaders, json_encode($this->processBody));
430+
$this->assertTrue($response->isSuccess());
431+
$this->assertNull($response->getErrorMessage());
432+
}
433+
411434
public function testProcessWebhookWithHandlerErrors()
412435
{
413436
$handler = $this->getMockHandler();

0 commit comments

Comments
 (0)