From 68d4f0eb7684b5a8992b9c68330284152021383b Mon Sep 17 00:00:00 2001 From: Diego Relyveld Date: Tue, 23 Jul 2024 15:49:26 +0200 Subject: [PATCH] Fix VoucherResourceTest --- .../Vouchers/RegisterVoucherMapper.php | 30 ------------------- .../OAuth/Vouchers/VouchersResource.php | 17 +++++++++++ 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/src/Mappers/Vouchers/RegisterVoucherMapper.php b/src/Mappers/Vouchers/RegisterVoucherMapper.php index f0ae862..4c87ac3 100644 --- a/src/Mappers/Vouchers/RegisterVoucherMapper.php +++ b/src/Mappers/Vouchers/RegisterVoucherMapper.php @@ -11,36 +11,6 @@ class RegisterVoucherMapper extends BaseMapper { public function map(stdClass $data): Voucher { - /** - * 'uuid' => $this->getUuid(), - * 'code' => $this->getCode(), - * 'status' => $this->getStatus(), - * 'name' => $this->getName(), - * 'description' => $this->getDescription(), - * 'expiration_date' => $this->getExpirationDate()?->format('c'), - * 'redeemed_at' => $this->getRedeemedAt()?->format('c'), - * 'is_redeemed' => $this->isRedeemed(), - * 'attributes' => $this->getCustomAttributeValues(), - * 'contact' => $this->getContact() ? [ - * 'uuid' => $this->getContact()->getUuid(), - * 'email' => $this->getContact()->getEmail(), - * ] : null, - * 'promotion' => array_merge([ - * 'uuid' => $promotion->getUuid(), - * 'name' => $promotion->getName(), - * 'description' => $promotion->getDescription(), - * 'image' => $promotion->getImage(Conversion::extraSmall()), - * 'voucher_limit' => $promotion->getVoucherLimit(), - * 'limit_per_contact' => $promotion->getLimitPerContact(), - * 'expiration_duration' => $promotion->getExpirationDuration(), - * ], $promotion->getCustomAttributeValues()), - */ - - - - - - if (isset($data->promotion)) { $promotionMapper = new PromotionMapper(); $promotion = $promotionMapper->map($data->promotion); diff --git a/src/Resources/OAuth/Vouchers/VouchersResource.php b/src/Resources/OAuth/Vouchers/VouchersResource.php index 37a9dbe..faad412 100644 --- a/src/Resources/OAuth/Vouchers/VouchersResource.php +++ b/src/Resources/OAuth/Vouchers/VouchersResource.php @@ -2,6 +2,7 @@ namespace Piggy\Api\Resources\OAuth\Vouchers; +use DateTime; use Piggy\Api\Exceptions\PiggyRequestException; use Piggy\Api\Mappers\Vouchers\VoucherLockMapper; use Piggy\Api\Mappers\Vouchers\VoucherMapper; @@ -16,6 +17,22 @@ class VouchersResource extends BaseVouchersResource */ protected $resourceUri = '/api/v3/oauth/clients/vouchers'; + /** + * @throws PiggyRequestException + */ + public function batch(string $promotionUuid, string $quantity, ?string $contactUuid = null, ?DateTime $activationDate = null, ?DateTime $expirationDate = null): string + { + $this->client->post($this->resourceUri, [ + 'promotion_uuid' => $promotionUuid, + 'quantity' => $quantity, + 'contact_uuid' => $contactUuid, + 'activation_date' => $activationDate, + 'expiration_date' => $expirationDate, + ]); + + return 'Voucher generation successfully started in background.'; + } + /** * @throws PiggyRequestException */