Skip to content

Commit 7d1d67d

Browse files
committed
Normalise event names to lowercase.
1 parent 59b25df commit 7d1d67d

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

config/revenuecat-webhooks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*
1616
* You can find a list of RevenueCat webhook events here:
1717
* https://www.revenuecat.com/docs/integrations/webhooks/event-types-and-fields
18+
*
19+
* Important: use lowercase for your event names.
1820
*/
1921
'jobs' => [
2022
// 'initial_purchase' => \App\Jobs\RevenueCatWebhooks\InitialPurchase::class,

src/ProcessRevenueCatWebhookJob.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ public function handle()
1515
throw WebhookFailed::missingType($this->webhookCall);
1616
}
1717

18-
event("revenuecat-webhooks::{$event['type']}", $this->webhookCall);
18+
// Normalize the event type to lowercase, RevenueCat sends them as uppercase
19+
$eventType = strtolower($event['type']);
1920

20-
$jobClass = $this->determineJobClass($event['type']);
21+
event("revenuecat-webhooks::{$eventType}", $this->webhookCall);
22+
23+
$jobClass = $this->determineJobClass($eventType);
2124

2225
if ($jobClass === '') {
2326
return;

tests/IntegrationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp(): void
1818
Route::revenueCatWebhooks('revenuecat-webhooks');
1919
Route::revenueCatWebhooks('revenuecat-webhooks/{configKey}');
2020

21-
config(['revenuecat-webhooks.jobs' => ['INITIAL_PURCHASE' => DummyJob::class]]);
21+
config(['revenuecat-webhooks.jobs' => ['initial_purchase' => DummyJob::class]]);
2222
cache()->clear();
2323
}
2424

@@ -46,7 +46,7 @@ public function it_can_handle_a_valid_request()
4646
$this->assertEquals($payload, $webhookCall->payload);
4747
$this->assertNull($webhookCall->exception);
4848

49-
Event::assertDispatched('revenuecat-webhooks::INITIAL_PURCHASE',
49+
Event::assertDispatched('revenuecat-webhooks::initial_purchase',
5050
function ($event, $eventPayload) use ($webhookCall) {
5151
$this->assertInstanceOf(WebhookCall::class, $eventPayload);
5252
$this->assertEquals($webhookCall->id, $eventPayload->id);
@@ -106,7 +106,7 @@ public function it_can_handle_a_valid_request_with_authorization_header()
106106
$this->assertEquals($payload, $webhookCall->payload);
107107
$this->assertNull($webhookCall->exception);
108108

109-
Event::assertDispatched('revenuecat-webhooks::INITIAL_PURCHASE',
109+
Event::assertDispatched('revenuecat-webhooks::initial_purchase',
110110
function ($event, $eventPayload) use ($webhookCall) {
111111
$this->assertInstanceOf(WebhookCall::class, $eventPayload);
112112
$this->assertEquals($webhookCall->id, $eventPayload->id);

tests/RevenueCatWebhookCallTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ public function setUp(): void
2020

2121
Event::fake();
2222

23-
config(['revenuecat-webhooks.jobs' => ['INITIAL_PURCHASE' => DummyJob::class]]);
23+
config(['revenuecat-webhooks.jobs' => ['initial_purchase' => DummyJob::class]]);
2424

2525
$this->webhookCall = WebhookCall::create([
2626
'name' => 'revenuecat',
2727
'payload' => [
2828
'api_version' => '1.0',
2929
'event' => [
30-
'type' => 'INITIAL_PURCHASE',
30+
'type' => 'INITIAL_PURCHASE', // Event type in uppercase as sent by RevenueCat
3131
'name' => 'value',
3232
],
3333
],
@@ -74,7 +74,7 @@ public function it_will_dispatch_events_even_when_no_corresponding_job_is_config
7474

7575
$webhookCall = $this->webhookCall;
7676

77-
Event::assertDispatched("revenuecat-webhooks::{$webhookCall->payload['event']['type']}",
77+
Event::assertDispatched("revenuecat-webhooks::initial_purchase",
7878
function ($event, $eventPayload) use ($webhookCall) {
7979
$this->assertInstanceOf(WebhookCall::class, $eventPayload);
8080
$this->assertEquals($webhookCall->id, $eventPayload->id);

0 commit comments

Comments
 (0)