mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Solve a problem where voucher cannot be added to a user account if user does not exist at Voucherify
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class RandomName implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('is_active', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user