Skip to content

Commit

Permalink
Merge pull request #16 from Piggy-Loyalty/develop
Browse files Browse the repository at this point in the history
added promotionUuid; contactUuid; and status as parameters for vouche…
  • Loading branch information
EdingerMike authored Jan 16, 2024
2 parents 47e1074 + b90625c commit 57d802d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/Mappers/Vouchers/PromotionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public function map($data): Promotion
$data->description,
$data->voucher_limit ?? null,
$data->limit_per_contact ?? null,
$data->expiration_duration ?? null
$data->expiration_duration ?? null,
isset($data->attributes) ? get_object_vars($data->attributes) : []
);
}
}
3 changes: 2 additions & 1 deletion src/Mappers/Vouchers/VoucherMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function map($data): Voucher
isset($data->redeemed_at) ? $this->parseDate($data->redeemed_at) : null,
$data->is_redeemed ?? null,
isset($data->activation_date) ? $this->parseDate($data->activation_date) : null,
isset($data->expiration_date) ? $this->parseDate($data->expiration_date) : null
isset($data->expiration_date) ? $this->parseDate($data->expiration_date) : null,
isset($data->attributes) ? get_object_vars($data->attributes) : []
);
}
}
6 changes: 3 additions & 3 deletions src/Models/Vouchers/Promotion.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Promotion
protected $expiration_duration;

/**
* @var stdClass|null
* @var array
*/
protected $attributes;

Expand All @@ -63,7 +63,7 @@ public function __construct(
?int $voucher_limit = null,
?int $limit_per_contact = null,
?int $expiration_duration = null,
?stdClass $attributes = null
array $attributes = []
)
{
$this->uuid = $uuid;
Expand Down Expand Up @@ -123,7 +123,7 @@ public function getUuid(): string
return $this->uuid;
}

public function getAttributes(): ?stdClass
public function getAttributes(): array
{
return $this->attributes;
}
Expand Down
15 changes: 14 additions & 1 deletion src/Models/Vouchers/Voucher.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Voucher
*/
protected $contact;

/** @var array */
protected $attributes;

/**
* @var string
*/
Expand Down Expand Up @@ -99,7 +102,8 @@ public function __construct(
?DateTime $redeemedAt,
?bool $isRedeemed,
?DateTime $activationDate,
?DateTime $expirationDate
?DateTime $expirationDate,
array $attributes = []
)
{
$this->uuid = $uuid;
Expand All @@ -113,6 +117,7 @@ public function __construct(
$this->is_redeemed = $isRedeemed;
$this->activation_date = $activationDate;
$this->expiration_date = $expirationDate;
$this->attributes = $attributes;
}

/**
Expand Down Expand Up @@ -203,6 +208,14 @@ public function getContact(): ?Contact
return $this->contact;
}

/**
* @return array
*/
public function getAttributes(): array
{
return $this->attributes;
}

/**
* @param array $body
* @return Voucher
Expand Down
5 changes: 4 additions & 1 deletion src/Resources/OAuth/Vouchers/VouchersResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,14 @@ public function batch(string $promotionUuid, string $quantity, ?string $contactU
* @return array
* @throws PiggyRequestException
*/
public function list(int $page = 1, int $limit = 30): array
public function list(int $page = 1, int $limit = 30, ?string $promotionUuid = null, ?string $contactUuid = null, ?string $status = null): array
{
$response = $this->client->get($this->resourceUri, [
"page" => $page,
"limit" => $limit,
"promotion_uuid" => $promotionUuid,
"contact_uuid" => $contactUuid,
"status" => $status
]);

$mapper = new VouchersMapper();
Expand Down
2 changes: 1 addition & 1 deletion src/StaticMappers/Vouchers/PromotionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static function map($data): Promotion
$data->voucher_limit ?? null,
$data->limit_per_contact ?? null,
$data->expiration_duration ?? null,
$data->attributes ?? null
isset($data->attributes) ? get_object_vars($data->attributes) : []
);
}
}
3 changes: 2 additions & 1 deletion src/StaticMappers/Vouchers/VoucherMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static function map($data): Voucher
isset($data->redeemed_at) ? self::parseDate($data->redeemed_at) : null,
$data->is_redeemed ?? null,
isset($data->activation_date) ? self::parseDate($data->activation_date) : null,
isset($data->expiration_date) ? self::parseDate($data->expiration_date) : null
isset($data->expiration_date) ? self::parseDate($data->expiration_date) : null,
isset($data->attributes) ? get_object_vars($data->attributes) : []
);
}
}

0 comments on commit 57d802d

Please sign in to comment.