Skip to content

Commit

Permalink
Merge pull request #267 from imdhemy/get-provider-from-notification
Browse files Browse the repository at this point in the history
[1.x] Get provider from server notification
  • Loading branch information
imdhemy authored Jan 27, 2023
2 parents 2986abc + a91d405 commit d008441
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/Contracts/ServerNotificationContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
*/
interface ServerNotificationContract
{
public const PROVIDER_GOOGLE_PLAY = 'google_play';
public const PROVIDER_APP_STORE = 'app_store';

/**
* Gets the notification type.
*/
Expand All @@ -35,4 +38,9 @@ public function getBundle(): string;
* Gets the notification payload.
*/
public function getPayload(): array;

/**
* Gets the notification provider.
*/
public function getProvider(): string;
}
10 changes: 6 additions & 4 deletions src/ServerNotifications/AppStoreServerNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@

class AppStoreServerNotification implements ServerNotificationContract
{
/**
* @var ServerNotification
*/
private $notification;
private ServerNotification $notification;

/**
* AppStoreServerNotification constructor.
Expand Down Expand Up @@ -79,4 +76,9 @@ public function getAutoRenewProductId(): ?string
{
return $this->notification->getAutoRenewProductId();
}

public function getProvider(): string
{
return self::PROVIDER_APP_STORE;
}
}
5 changes: 5 additions & 0 deletions src/ServerNotifications/AppStoreV2ServerNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ public function getSubtype(): string
{
return (string)$this->payload->getSubType();
}

public function getProvider(): string
{
return self::PROVIDER_APP_STORE;
}
}
5 changes: 5 additions & 0 deletions src/ServerNotifications/GoogleServerNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,9 @@ public function getPayload(): array
{
return $this->notification->toArray();
}

public function getProvider(): string
{
return self::PROVIDER_GOOGLE_PLAY;
}
}
8 changes: 8 additions & 0 deletions tests/ServerNotifications/AppStoreServerNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,12 @@ public function test_get_auto_renew_product_id()
{
$this->assertNotNull($this->appStoreServerNotification->getAutoRenewProductId());
}

/**
* @test
*/
public function get_provider(): void
{
$this->assertEquals('app_store', $this->appStoreServerNotification->getProvider());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ public function get_subtype(): void
{
$this->assertEquals(V2DecodedPayload::SUBTYPE_INITIAL_BUY, $this->sut->getSubtype());
}

/**
* @test
*/
public function get_provider(): void
{
$this->assertEquals('app_store', $this->sut->getProvider());
}
}
8 changes: 8 additions & 0 deletions tests/ServerNotifications/GoogleServerNotificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ public function get_payload(): void
{
$this->assertEquals($this->developerNotification->toArray(), $this->googleServerNotification->getPayload());
}

/**
* @test
*/
public function get_provider(): void
{
$this->assertEquals('google_play', $this->googleServerNotification->getProvider());
}
}

0 comments on commit d008441

Please sign in to comment.