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

[v3] Add channel to loyalty transactions #26

Merged
merged 4 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/Mappers/Loyalty/Receptions/CreditReceptionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ public function map(stdClass $data): CreditReception
$attributes = [];

foreach ($data as $propertyName => $value) {
if (in_array($propertyName, ['type', 'credits', 'uuid', 'contact', 'shop', 'contact_identifier', 'created_at', 'unit_value', 'unit'])) {
continue;
}
$attributes[$propertyName] = $value;
}

$attributes = [];

foreach ($data as $propertyName => $value) {
if (in_array($propertyName, ['type', 'credits', 'uuid', 'contact', 'shop', 'contact_identifier', 'created_at', 'unit_value', 'unit'])) {
if (in_array($propertyName, ['type', 'credits', 'uuid', 'contact', 'shop', 'contact_identifier', 'created_at', 'unit_value', 'unit', 'channel'])) {
continue;
}
$attributes[$propertyName] = $value;
Expand All @@ -58,6 +49,7 @@ public function map(stdClass $data): CreditReception
$data->uuid,
$contact ?? null,
$shop ?? null,
$data->channel,
$contactIdentifier ?? null,
$this->parseDate($data->created_at),
$data->unit_value ?? null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function map(stdClass $data): DigitalRewardReception
$data->uuid,
$contact,
$shop,
$data->channel,
$contactIdentifier,
$this->parseDate($data->created_at),
$data->title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function map(stdClass $data): PhysicalRewardReception
$data->uuid,
$contact,
$shop,
$data->channel,
$contactIdentifier,
$this->parseDate($data->created_at),
$data->title,
Expand Down
13 changes: 12 additions & 1 deletion src/Models/Loyalty/Receptions/CreditReception.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class CreditReception extends BaseReception
*/
private $shop;

/**
* @var string
*/
private $channel;

/**
* @var ContactIdentifier|null
*/
Expand Down Expand Up @@ -68,13 +73,14 @@ class CreditReception extends BaseReception
/**
* @param mixed[] $attributes
*/
public function __construct(string $type, int $credits, string $uuid, ?Contact $contact, ?Shop $shop, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, ?float $unitValue = null, ?Unit $unit = null, array $attributes = [])
public function __construct(string $type, int $credits, string $uuid, ?Contact $contact, ?Shop $shop, string $channel, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, ?float $unitValue = null, ?Unit $unit = null, array $attributes = [])
{
$this->type = $type;
$this->credits = $credits;
$this->uuid = $uuid;
$this->contact = $contact;
$this->shop = $shop;
$this->channel = $channel;
$this->contactIdentifier = $contactIdentifier;
$this->createdAt = $createdAt;
$this->unitValue = $unitValue;
Expand Down Expand Up @@ -107,6 +113,11 @@ public function getShop(): ?Shop
return $this->shop;
}

public function getChannel(): string
{
return $this->channel;
}

public function getContactIdentifier(): ?ContactIdentifier
{
return $this->contactIdentifier;
Expand Down
13 changes: 12 additions & 1 deletion src/Models/Loyalty/Receptions/DigitalRewardReception.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class DigitalRewardReception extends BaseReception
*/
protected $shop;

/**
* @var string
*/
protected $channel;

/**
* @var ContactIdentifier|null
*/
Expand All @@ -61,13 +66,14 @@ class DigitalRewardReception extends BaseReception
*/
protected $digitalRewardCode;

public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, ?DigitalReward $digitalReward, ?DigitalRewardCode $digitalRewardCode)
public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, string $channel, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, ?DigitalReward $digitalReward, ?DigitalRewardCode $digitalRewardCode)
{
$this->type = $type;
$this->credits = $credits;
$this->uuid = $uuid;
$this->contact = $contact;
$this->shop = $shop;
$this->channel = $channel;
$this->contactIdentifier = $contactIdentifier;
$this->createdAt = $createdAt;
$this->title = $title;
Expand Down Expand Up @@ -100,6 +106,11 @@ public function getShop(): Shop
return $this->shop;
}

public function getChannel(): string
{
return $this->channel;
}

public function getContactIdentifier(): ?ContactIdentifier
{
return $this->contactIdentifier;
Expand Down
13 changes: 12 additions & 1 deletion src/Models/Loyalty/Receptions/PhysicalRewardReception.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class PhysicalRewardReception extends BaseReception
*/
protected $shop;

/**
* @var string
*/
protected $channel;

/**
* @var ContactIdentifier|null
*/
Expand Down Expand Up @@ -65,13 +70,14 @@ class PhysicalRewardReception extends BaseReception
*/
protected $hasBeenCollected;

public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, Reward $reward, ?DateTime $expiresAt, bool $hasBeenCollected)
public function __construct(string $type, int $credits, string $uuid, Contact $contact, Shop $shop, string $channel, ?ContactIdentifier $contactIdentifier, DateTime $createdAt, string $title, Reward $reward, ?DateTime $expiresAt, bool $hasBeenCollected)
{
$this->type = $type;
$this->credits = $credits;
$this->uuid = $uuid;
$this->contact = $contact;
$this->shop = $shop;
$this->channel = $channel;
$this->contactIdentifier = $contactIdentifier;
$this->createdAt = $createdAt;
$this->title = $title;
Expand Down Expand Up @@ -105,6 +111,11 @@ public function getShop(): Shop
return $this->shop;
}

public function getChannel(): string
{
return $this->channel;
}

public function getContactIdentifier(): ?ContactIdentifier
{
return $this->contactIdentifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function map(stdClass $data): CreditReception
$data->uuid,
$contact ?? null,
$shop ?? null,
$data->channel,
$contactIdentifier ?? null,
self::parseDate($data->created_at),
$data->unit_value ?? null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function map(stdClass $data): DigitalRewardReception
$data->uuid,
$contact,
$shop,
$data->channel,
$contactIdentifier,
self::parseDate($data->created_at),
$data->title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static function map(stdClass $data): PhysicalRewardReception
$data->uuid,
$contact,
$shop,
$data->channel,
$contactIdentifier,
self::parseDate($data->created_at),
$data->title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function it_returns_a_credit_reception()
'name' => 'shopName',
'uuid' => '123-312',
],
'channel' => 'BUSINESS_DASHBOARD',
'created_at' => '2022-06-30T13:42:04+00:00',
'unit_value' => 1011,
'unit' => [
Expand All @@ -44,6 +45,7 @@ public function it_returns_a_credit_reception()
$this->assertEquals('123-123', $creditReception->getContact()->getUuid());
$this->assertEquals('123-312', $creditReception->getShop()->getUuid());
$this->assertEquals('shopName', $creditReception->getShop()->getName());
$this->assertEquals('BUSINESS_DASHBOARD', $creditReception->getChannel());
$this->assertEquals('2022-06-30T13:42:04+00:00', $creditReception->getCreatedAt()->format('c'));
$this->assertEquals(1011, $creditReception->getUnitValue());
$this->assertEquals('bonkers', $creditReception->getUnit()->getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function it_returns_a_physical_reward_reception()
'name' => 'shopName',
'uuid' => '123-312',
],
'channel' => 'BUSINESS_DASHBOARD',
'created_at' => '2022-06-30T13:42:04+00:00',
'title' => 'reward title',
'reward' => [
Expand Down Expand Up @@ -72,6 +73,7 @@ public function it_returns_a_digital_reward_reception_without_a_reward_linked()
'name' => 'shopName',
'uuid' => '123-312',
],
'channel' => 'BUSINESS_DASHBOARD',
'created_at' => '2022-06-30T13:42:04+00:00',
'title' => 'digital reward title',
]);
Expand Down Expand Up @@ -109,6 +111,7 @@ public function it_returns_a_digital_reward_reception()
'name' => 'shopName',
'uuid' => '123-312',
],
'channel' => 'BUSINESS_DASHBOARD',
'created_at' => '2022-06-30T13:42:04+00:00',
'title' => 'digital reward title',
'digital_reward' => [
Expand All @@ -128,6 +131,7 @@ public function it_returns_a_digital_reward_reception()
$this->assertEquals('123-123', $rewardReception->getContact()->getUuid());
$this->assertEquals('123-312', $rewardReception->getShop()->getUuid());
$this->assertEquals('shopName', $rewardReception->getShop()->getName());
$this->assertEquals('BUSINESS_DASHBOARD', $rewardReception->getChannel());
$this->assertEquals('2022-06-30T13:42:04+00:00', $rewardReception->getCreatedAt()->format('c'));
$this->assertEquals('digital reward title', $rewardReception->getTitle());
$this->assertEquals('DIGITAL', $rewardReception->getDigitalReward()->getRewardType());
Expand Down
2 changes: 2 additions & 0 deletions tests/OAuth/Loyalty/Tokens/LoyaltyTokenResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function it_can_claim_a_credit_based_loyalty_token_url_and_returns_a_cred
'name' => 'Visjes',
'uuid' => '1',
],
'channel' => 'BUSINESS_DASHBOARD',
'contact_identifier' => null,
'created_at' => '2023-01-10T15:59:58+00:00',
'uuid' => '0c655a10-7980-4fdb-ac11-2caca19f2329',
Expand Down Expand Up @@ -104,6 +105,7 @@ public function it_can_claim_a_unit_based_loyalty_token_url_and_returns_a_credit
'name' => 'Visjes',
'uuid' => '1',
],
'channel' => 'BUSINESS_DASHBOARD',
'created_at' => '2023-01-12T14:59:03+00:00',
'uuid' => '0c655a10-7980-4fdb-ac11-2caca19f2329',
'unit_value' => 200.0,
Expand Down
Loading