Merge branch 'dillon/63.7-company-with-multiple-employees' into development

This commit is contained in:
Dillon Ngo
2024-08-23 12:24:39 +08:00
3 changed files with 19 additions and 5 deletions
@@ -11,6 +11,7 @@ use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyVoucherInACampaign;
use App\Classes\Modules\Vouchers\Services\Voucherify\ListsVoucherifyVouchers;
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyCampaign;
use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyProcessor;
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
use App\Classes\Modules\Vouchers\Services\UpdatesVoucherCampaign;
@@ -75,6 +76,9 @@ class CreateVoucherLogic extends AbstractControllerLogic
/** @var UpdatesVoucherCampaign */
private $updatesVoucherCampaign;
/** @var NewCustomerToVoucherifyProcessor */
private $newCustomerToVoucherifyProcessor;
/**
* CreateVoucherLogic constructor.
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
@@ -87,8 +91,9 @@ class CreateVoucherLogic extends AbstractControllerLogic
* @param CreatesKeyValuePair $createsKeyValuePair
* @param UpdatesKeyValuePair $updatesKeyValuePair
* @param UpdatesVoucherCampaign $updatesVoucherCampaign
* @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor
*/
public function __construct(CreatesUserReward $createsUserReward, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, CreateVoucherProcessor $createVoucherProcessor, CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign, CanCreateVoucher $canCreateVoucher, ListsVoucherifyVouchers $listsVoucherifyVouchers, FetchesVoucherifyCampaign $fetchesVoucherifyCampaign, CreatesKeyValuePair $createsKeyValuePair, UpdatesKeyValuePair $updatesKeyValuePair, UpdatesVoucherCampaign $updatesVoucherCampaign)
public function __construct(CreatesUserReward $createsUserReward, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, CreateVoucherProcessor $createVoucherProcessor, CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign, CanCreateVoucher $canCreateVoucher, ListsVoucherifyVouchers $listsVoucherifyVouchers, FetchesVoucherifyCampaign $fetchesVoucherifyCampaign, CreatesKeyValuePair $createsKeyValuePair, UpdatesKeyValuePair $updatesKeyValuePair, UpdatesVoucherCampaign $updatesVoucherCampaign, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor)
{
$this->createsUserReward = $createsUserReward;
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
@@ -100,6 +105,7 @@ class CreateVoucherLogic extends AbstractControllerLogic
$this->createsKeyValuePair = $createsKeyValuePair;
$this->updatesKeyValuePair = $updatesKeyValuePair;
$this->updatesVoucherCampaign = $updatesVoucherCampaign;
$this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor;
}
/**
@@ -129,6 +135,12 @@ class CreateVoucherLogic extends AbstractControllerLogic
$user = $userParam ? $userParam : $user;
}
//Voucherify - To check if user exist at Voucherify, create if not exist
$voucherify_entity = $user->voucherifyEntities()->first();
if(!$voucherify_entity){
$this->newCustomerToVoucherifyProcessor->execute($user->company()->first()->id, $user, false);
}
//Voucherify - creates new voucher at voucherify
if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 ) {
$result = $this->newVoucherifyVoucherIssuanceHandler($voucherCodeInput);
@@ -65,9 +65,9 @@ class CreateVoucherifyCustomerObject implements DataTransferObject
*/
public function getAcquisitionChannel(): string
{
if(!$this->isNew){
return "";
}
// if(!$this->isNew){
// return "";
// }
return $this->acquisitionChannel;
}
@@ -44,7 +44,9 @@ class NewCustomerToVoucherifyProcessor
$createVoucherifyCustomerObject = new CreateVoucherifyCustomerObject($companyId, $user, $isNew);
$result = $this->createsVoucherifyCustomer->execute($createVoucherifyCustomerObject);
if($result && isset($result->id)){
$voucherify_entity = $user->voucherifyEntities()->get();
if($result && isset($result->id) && count($voucherify_entity) === 0){
$voucherEntityObject = new VoucherEntityObject($result->id, VoucherifyEntityType::CUSTOMER);
$this->createsVoucherEntityMapping->execute($createVoucherifyCustomerObject->getUser(), $voucherEntityObject);
}