mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Voucherify phase 2
This commit is contained in:
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [{
|
||||
"name": "Listen for XDebug on Docker",
|
||||
"type": "php",
|
||||
"request": "launch",
|
||||
"port": 9002,
|
||||
"pathMappings": {
|
||||
"/var/www/html": "${workspaceFolder}",
|
||||
},
|
||||
"log": true
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class Code implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('code', '=', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HasActiveReward implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
if(in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)){
|
||||
// $userId = $value !== 1 ? $value : Auth::user()->id;
|
||||
$userId = $value;
|
||||
return $builder->where('user_id', $userId)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.booking.company.employees', function ($query) use ($userId) {
|
||||
$query->where('user_id', $userId);
|
||||
});
|
||||
}
|
||||
else{
|
||||
return $builder->where('user_id', Auth::user()->id)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('reward', function ($subquery) {
|
||||
$subquery->where('is_active', true);
|
||||
})
|
||||
->orWhereDoesntHave('reward');
|
||||
})
|
||||
->whereDoesntHave('voucher.redemptions.transaction.owner');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HasUsedVoucher implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('user_id', Auth::user()->id)
|
||||
->where(function ($query) {
|
||||
$query->whereHas('voucher', function ($subquery) {
|
||||
$subquery->whereHas('redemptions', function ($subsubquery) {
|
||||
$subsubquery->whereHas('transaction', function ($subsubsubquery) {
|
||||
$subsubsubquery->whereHas('owner');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class HasUsedVoucherForAdmin implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$userId = $value !== 1 ? $value : Auth::user()->id;
|
||||
|
||||
return $builder->where('user_id', $userId)
|
||||
->where(function ($query) use ($userId){
|
||||
$query->whereHas('voucher', function ($subquery) use ($userId){
|
||||
$subquery->whereHas('redemptions', function ($subsubquery) use ($userId){
|
||||
$subsubquery->whereHas('transaction', function ($subsubsubquery) use ($userId){
|
||||
$subsubsubquery->whereHas('booking', function ($s4query) use ($userId){
|
||||
$s4query->whereHas('company', function ($s5query) use ($userId) {
|
||||
$s5query->whereHas('employees', function ($s6query) use ($userId){
|
||||
$s6query->where('user_id', $userId);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class UserId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('user_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class isActive implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('is_active', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class isActive2 implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('is_active', $value);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ class Helper
|
||||
* @param $log
|
||||
* @return array
|
||||
*/
|
||||
static function debugLoggerForPerfexCRM($log){
|
||||
static function debugLogger($log){
|
||||
if($log && isset($log['message'])){
|
||||
$message = $log['message'];
|
||||
$substring = 'No data were found';
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Interfaces;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
interface Voucherifiable
|
||||
{
|
||||
public function voucherifyEntities(): morphMany;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
} else {
|
||||
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
|
||||
$log['message'] = 'UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed';
|
||||
Helper::debugLoggerForPerfexCRM($log);
|
||||
Helper::debugLogger($log);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -11,7 +11,9 @@ use App\Classes\Modules\Companies\Processors\AssignEmployeeProcessor;
|
||||
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
|
||||
use App\Classes\Modules\Companies\Processors\CreateCompanyProcessor;
|
||||
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMLeadProcessor;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\CreateVoucherProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateLeadPerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -63,12 +65,18 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
/** @var GenerateEmailVerificationAttemptProcessor */
|
||||
private $generateEmailVerificationAttemptProcessor;
|
||||
|
||||
/** @var CreatePerfexCRMLeadProcessor */
|
||||
private $createPerfexCRMLeadProcessor;
|
||||
|
||||
/** @var CreatesSeasonalSegment */
|
||||
private $createsSeasonalSegment;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
/** @var NewCustomerToVoucherifyProcessor */
|
||||
private $newCustomerToVoucherifyProcessor;
|
||||
|
||||
/** @var CreateVoucherProcessor */
|
||||
private $createVoucherProcessor;
|
||||
|
||||
/**
|
||||
* CreateCustomerLogic constructor.
|
||||
* @param CreateUserProcessor $createUserProcessor
|
||||
@@ -78,11 +86,13 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
* @param AssignSegmentProcessor $assignSegmentProcessor
|
||||
* @param AuthenticationProcessor $authenticationProcessor
|
||||
* @param GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor
|
||||
* @param CreatePerfexCRMLeadProcessor $createPerfexCRMLeadProcessor
|
||||
* @param CreatesSeasonalSegment $createsSeasonalSegment
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
* @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor
|
||||
* @param CreateVoucherProcessor $createVoucherProcessor
|
||||
*/
|
||||
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateContactProcessor $createContactProcessor, AssignEmployeeProcessor $assignEmployeeProcessor, AssignSegmentProcessor $assignSegmentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor,
|
||||
CreatePerfexCRMLeadProcessor $createPerfexCRMLeadProcessor, CreatesSeasonalSegment $createsSeasonalSegment)
|
||||
CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor, CreateVoucherProcessor $createVoucherProcessor)
|
||||
{
|
||||
$this->createUserProcessor = $createUserProcessor;
|
||||
$this->createCompanyProcessor = $createCompanyProcessor;
|
||||
@@ -91,8 +101,10 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
$this->assignSegmentProcessor = $assignSegmentProcessor;
|
||||
$this->authenticationProcessor = $authenticationProcessor;
|
||||
$this->generateEmailVerificationAttemptProcessor = $generateEmailVerificationAttemptProcessor;
|
||||
$this->createPerfexCRMLeadProcessor = $createPerfexCRMLeadProcessor;
|
||||
$this->createsSeasonalSegment = $createsSeasonalSegment;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
$this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor;
|
||||
$this->createVoucherProcessor = $createVoucherProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,6 +118,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->createUserProcessor->execute($request, RoleTypes::USER, App::environment(['local']) ? ApprovalStatus::APPROVED : ApprovalStatus::PENDING_VERIFICATION);
|
||||
|
||||
@@ -132,7 +145,6 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
}
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
//$this->createPerfexCRMLeadProcessor->execute($request);
|
||||
$createLeadPerfexCRMObject = new CreateLeadPerfexCRMObject(
|
||||
$request->input('name'),
|
||||
$request->input('email'),
|
||||
@@ -145,7 +157,11 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
|
||||
$this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request));
|
||||
$this->newCustomerToVoucherifyProcessor->execute($company->id, $user, true);
|
||||
|
||||
$this->createVoucherProcessor->execute($user, 'WELCOME2EXCHANGE');
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request, false));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ use App\Classes\Modules\Accounts\Services\AuthenticationRedirect;
|
||||
use App\Classes\Modules\Accounts\Services\FetchesUser;
|
||||
use App\Classes\Modules\Accounts\Services\GeneratesAuthenticationToken;
|
||||
use App\Classes\Modules\Accounts\Standards\Rules\CanAuthenticateUser;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyProcessor;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AuthenticationProcessor
|
||||
@@ -28,6 +31,13 @@ class AuthenticationProcessor
|
||||
/** @var AuthenticationRedirect */
|
||||
private $authenticationRedirect;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
/** @var NewCustomerToVoucherifyProcessor */
|
||||
private $newCustomerToVoucherifyProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* AuthenticationProcessor constructor.
|
||||
* @param CanAuthenticateUser $canAuthenticateUser
|
||||
@@ -35,14 +45,18 @@ class AuthenticationProcessor
|
||||
* @param GeneratesAuthenticationToken $generatesAuthenticationToken
|
||||
* @param FetchesUser $fetchesUser
|
||||
* @param AuthenticationRedirect $authenticationRedirect
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
* @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor
|
||||
*/
|
||||
public function __construct(CanAuthenticateUser $canAuthenticateUser, AuthenticatesUser $authenticatesUser, GeneratesAuthenticationToken $generatesAuthenticationToken, FetchesUser $fetchesUser, AuthenticationRedirect $authenticationRedirect)
|
||||
public function __construct(CanAuthenticateUser $canAuthenticateUser, AuthenticatesUser $authenticatesUser, GeneratesAuthenticationToken $generatesAuthenticationToken, FetchesUser $fetchesUser, AuthenticationRedirect $authenticationRedirect, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor)
|
||||
{
|
||||
$this->canAuthenticateUser = $canAuthenticateUser;
|
||||
$this->authenticatesUser = $authenticatesUser;
|
||||
$this->generatesAuthenticationToken = $generatesAuthenticationToken;
|
||||
$this->fetchesUser = $fetchesUser;
|
||||
$this->authenticationRedirect = $authenticationRedirect;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
$this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +67,7 @@ class AuthenticationProcessor
|
||||
* @throws \App\Classes\Exceptions\AccessUnauthorisedException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request): array {
|
||||
public function execute(Request $request, bool $isSignIn = true): array {
|
||||
|
||||
$object = new AuthenticationCredentialsObject($request->input('email'), $request->input('password'));
|
||||
|
||||
@@ -63,8 +77,13 @@ class AuthenticationProcessor
|
||||
|
||||
$user = $this->fetchesUser->execute(['email' => $object->getEmail()]);
|
||||
|
||||
if($isSignIn){
|
||||
$this->newCustomerToVoucherifyProcessor->execute(0, $user, false);
|
||||
}
|
||||
|
||||
//cief todo: case study 1
|
||||
$this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_1]);
|
||||
|
||||
return ['access_token' => $this->generatesAuthenticationToken->execute($user), 'redirect_url' => $this->authenticationRedirect->url($user)];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,12 @@ use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
|
||||
class CreateAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -39,19 +41,25 @@ class CreateAddressLogic extends AbstractControllerLogic
|
||||
/** @var CreatesAddress */
|
||||
private $createsAddress;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* CreateAddressLogic constructor.
|
||||
* @param CanCreateAddress $canCreateAddress
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CreatesAddress $createsAddress
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
*/
|
||||
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress)
|
||||
public function __construct(CanCreateAddress $canCreateAddress, FetchesDistrict $fetchesDistrict, FetchesCompany $fetchesCompany, CreatesAddress $createsAddress, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
|
||||
{
|
||||
$this->canCreateAddress = $canCreateAddress;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsAddress = $createsAddress;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -70,10 +78,15 @@ class CreateAddressLogic extends AbstractControllerLogic
|
||||
|
||||
$this->canCreateAddress->passes($object);
|
||||
|
||||
$query = $this->createsAddress->execute($this->fetchesCompany->execute(['id' => $request->input('company_id')]), $object);
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
$query = $this->createsAddress->execute($company, $object);
|
||||
|
||||
//cief todo: case study 6
|
||||
// $user = $company->employees()->first();
|
||||
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_6]);
|
||||
|
||||
return $this->resourceResponse(new AddressResource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ use App\Classes\Modules\Banks\Standards\Rules\CanCreateBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesBank;
|
||||
use App\Classes\Modules\Banks\Services\CreatesBankLog;
|
||||
use App\Classes\Modules\Banks\DataTransferObjects\BankObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Http\Resources\BankResource;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -36,21 +39,34 @@ class CreateBankLogic extends AbstractControllerLogic
|
||||
/** @var CreatesBankLog */
|
||||
private $createsBankLog;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* CreateBankLogic constructor.
|
||||
* @param CanCreateBank $canCreateBank
|
||||
* @param CreatesBank $createsBank
|
||||
* @param CreatesBankLog $createsBankLog
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
CanCreateBank $canCreateBank,
|
||||
CreatesBank $createsBank,
|
||||
CreatesBankLog $createsBankLog
|
||||
CreatesBankLog $createsBankLog,
|
||||
FetchesCompany $fetchesCompany,
|
||||
CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
)
|
||||
{
|
||||
$this->canCreateBank = $canCreateBank;
|
||||
$this->createsBank = $createsBank;
|
||||
$this->createsBankLog = $createsBankLog;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,7 +89,12 @@ class CreateBankLogic extends AbstractControllerLogic
|
||||
|
||||
// $bankLog = $this->createsBankLog->execute($bank);
|
||||
|
||||
//cief todo: case study 4
|
||||
// $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
// $user = $company->employees()->first();
|
||||
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_4]);
|
||||
|
||||
return $this->resourceResponse(new BankResource($bank));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ use App\Classes\Modules\Bookings\Services\GeneratesBookingMarking;
|
||||
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\BookingToPerfexCRMProcessor;
|
||||
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
use App\Http\Resources\BookingResource;
|
||||
|
||||
use App\Models\Booking;
|
||||
@@ -50,6 +51,10 @@ class CreateBookingLogic extends AbstractControllerLogic
|
||||
/** @var BookingToPerfexCRMProcessor */
|
||||
private $bookingToPerfexCRMProcessor;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* CreateBookingLogic constructor.
|
||||
* @param CanCreateBooking $canCreateBooking
|
||||
@@ -57,14 +62,16 @@ class CreateBookingLogic extends AbstractControllerLogic
|
||||
* @param GeneratesBookingMarking $generatesBookingMarking
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor
|
||||
* @param CheckMilestoneForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
*/
|
||||
public function __construct(CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany, BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor)
|
||||
public function __construct(CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany, BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
|
||||
{
|
||||
$this->canCreateBooking = $canCreateBooking;
|
||||
$this->createsBooking = $createsBooking;
|
||||
$this->generatesBookingMarking = $generatesBookingMarking;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->bookingToPerfexCRMProcessor = $bookingToPerfexCRMProcessor;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +97,10 @@ class CreateBookingLogic extends AbstractControllerLogic
|
||||
$this->bookingToPerfexCRMProcessor->execute($booking);
|
||||
}
|
||||
|
||||
//cief todo: case study 5
|
||||
// $user = $company->employees()->first();
|
||||
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_5]);
|
||||
|
||||
return $this->resourceResponse(new BookingResource($booking));
|
||||
|
||||
}
|
||||
|
||||
@@ -8,24 +8,20 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
|
||||
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucherRedemption;
|
||||
use App\Classes\Modules\Vouchers\Services\RedeemsVoucher;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
|
||||
use App\Classes\Modules\Transactions\Processors\CreateCashBackTransactionProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
|
||||
|
||||
use App\Models\Booking;
|
||||
use App\Models\Transaction;
|
||||
@@ -78,17 +74,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
/** @var RecalculatesWalletBalance */
|
||||
private $recalculatesWalletBalance;
|
||||
|
||||
/** @var FetchesVoucher */
|
||||
private $fetchesVoucher;
|
||||
/** @var BookingToVoucherifyProcessor */
|
||||
private $bookingToVoucherifyProcessor;
|
||||
|
||||
/** @var CreatesVoucher */
|
||||
private $createsVoucher;
|
||||
|
||||
/** @var CreatesVoucherRedemption */
|
||||
private $createsVoucherRedemption;
|
||||
|
||||
/** @var RedeemsVoucher */
|
||||
private $redeemsVoucher;
|
||||
/**
|
||||
* CreateBookingPaymentLogic constructor.
|
||||
* @param FetchesBookingQuotation $fetchBookingQuotation
|
||||
@@ -101,12 +89,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param CreateCashBackTransactionProcessor $createCashBackTransactionProcessor
|
||||
* @param RecalculatesWalletBalance $recalculatesWalletBalance
|
||||
* @param FetchesVoucher $fetchesVoucher
|
||||
* @param CreatesVoucher $createsVoucher
|
||||
* @param CreatesVoucherRedemption $createsVoucherRedemption
|
||||
* @param RedeemVoucher $redeemVoucher
|
||||
* @param BookingToVoucherifyProcessor $bookingToVoucherifyProcessor
|
||||
*/
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance, FetchesVoucher $fetchesVoucher, CreatesVoucher $createsVoucher, CreatesVoucherRedemption $createsVoucherRedemption, RedeemsVoucher $redeemsVoucher)
|
||||
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance, BookingToVoucherifyProcessor $bookingToVoucherifyProcessor)
|
||||
{
|
||||
$this->fetchBookingQuotation = $fetchBookingQuotation;
|
||||
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
|
||||
@@ -118,10 +103,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->createCashBackTransactionProcessor = $createCashBackTransactionProcessor;
|
||||
$this->recalculatesWalletBalance = $recalculatesWalletBalance;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
$this->createsVoucher = $createsVoucher;
|
||||
$this->createsVoucherRedemption = $createsVoucherRedemption;
|
||||
$this->redeemsVoucher = $redeemsVoucher;
|
||||
$this->bookingToVoucherifyProcessor = $bookingToVoucherifyProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,11 +113,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$voucherCode = $request->input('voucher_code'); //cief to, json_encode and json_decode ???
|
||||
// if($voucherReqInput){
|
||||
// $voucherObject = json_decode($voucherReqInput);
|
||||
// $validatedVoucherObject = new ValidatedVoucherObject($voucherObject->metadata->name, $voucherObject->code, $voucherObject->discount->type, $voucherObject->discount->amount_off);
|
||||
// }
|
||||
$voucherCode = $request->input('voucher_code');
|
||||
|
||||
$booking = Booking::find($request->route('id'));
|
||||
|
||||
@@ -189,34 +167,12 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
|
||||
$transaction = $this->createsTransaction->execute($booking, $object);
|
||||
// $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction);
|
||||
|
||||
$this->bookingToVoucherifyProcessor->execute($booking->company->employees()->first(), $transaction, $booking->company->id, $configurations->getSubTotal(), $configurations->getVoucherDiscountAmount(), $voucherCode);
|
||||
|
||||
if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::WALLET){
|
||||
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED);
|
||||
}
|
||||
|
||||
//Voucherify
|
||||
if($voucherCode){
|
||||
$employee = $booking->company->employees()->first();
|
||||
|
||||
$result = $this->redeemsVoucher->execute($voucherCode, $configurations->getSubTotal(), $employee);
|
||||
$voucher = $result->voucher;
|
||||
$redemptionId = $result->id;
|
||||
//Update Database
|
||||
$voucherValue = 0.00;
|
||||
if(isset($voucher->discount->amount_off)){
|
||||
$voucherValue =$voucher->discount->amount_off;
|
||||
}
|
||||
if($voucherValue == 0.00){
|
||||
if(isset($voucher->discount->percent_off)){
|
||||
$voucherValue =$voucher->discount->percent_off;
|
||||
}
|
||||
}
|
||||
|
||||
$voucherObject= new VoucherObject($voucher->code, isset($voucher->metadata->name) ? $voucher->metadata->name : "", $voucher->discount->type, $voucherValue);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
|
||||
$this->createsVoucherRedemption->execute($transaction, $voucher, $redemptionId, $configurations->getVoucherDiscountAmount());
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new TransactionResource($transaction));
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@ use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyServiceSettings;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidatedVoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\Modules\Vouchers\Services\ValidatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Models\Company;
|
||||
use App\Models\Currency;
|
||||
|
||||
@@ -22,19 +23,19 @@ class FetchesBookingQuotation
|
||||
/** @var FetchesCurrency */
|
||||
private $fetchesCurrency;
|
||||
|
||||
/** @var ValidatesVoucher */
|
||||
private $validatesVoucher;
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/**
|
||||
* FetchesBookingQuotation constructor.
|
||||
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
*/
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucher $validatesVoucher)
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
||||
{
|
||||
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
$this->validatesVoucher = $validatesVoucher;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,15 +60,15 @@ class FetchesBookingQuotation
|
||||
//Voucherify
|
||||
if($voucherCode){
|
||||
$employee = $company->employees()->first();
|
||||
|
||||
$result = $this->validatesVoucher->execute($voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
||||
$voucher = [
|
||||
"code" => $result->code,
|
||||
"discount" => $result->discount,
|
||||
"discount" => property_exists($result, 'discount') ? $result->discount : null,
|
||||
"metadata" => $result->metadata,
|
||||
"order" => $result->order,
|
||||
];
|
||||
$validatedVoucherObject = new ValidatedVoucherObject(isset($voucher['metadata']->name) ? $voucher['metadata']->name: "", $voucher['code'], $voucher['discount']->type, $voucher['order']->total_discount_amount, $voucher['order']->total_amount);
|
||||
$validatedVoucherObject = new ValidatedVoucherObject(isset($voucher['metadata']->name) ? $voucher['metadata']->name: "", $voucher['code'], $voucher['discount']->type ?? 'AMOUNT', $voucher['order']->total_discount_amount, $voucher['order']->total_amount);
|
||||
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
use App\Models\SeasonalSegment;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -36,17 +38,22 @@ class AssignCompanyToSegmentLogic extends AbstractControllerLogic
|
||||
/** @var CreatesSeasonalSegment */
|
||||
private $createsSeasonalSegment;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
/**
|
||||
* AssignCompanyToSegmentLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param AssignSegmentProcessor $assignCompanyToSegmentProcessor
|
||||
* @param CreatesSeasonalSegment $createsSeasonalSegment
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor, CreatesSeasonalSegment $createsSeasonalSegment)
|
||||
public function __construct(FetchesCompany $fetchesCompany, AssignSegmentProcessor $assignCompanyToSegmentProcessor, CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->assignCompanyToSegmentProcessor = $assignCompanyToSegmentProcessor;
|
||||
$this->createsSeasonalSegment = $createsSeasonalSegment;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,12 +82,16 @@ class AssignCompanyToSegmentLogic extends AbstractControllerLogic
|
||||
// }
|
||||
|
||||
$start_date = $request->input('starting_on') ? $request->input('starting_on') : Carbon::now();
|
||||
|
||||
|
||||
$seasonalSegmentObject = new SeasonalSegmentObject($company->id, $request->input('segment_id'), $start_date, $request->input('ending_on') ?? null);
|
||||
|
||||
$this->createsSeasonalSegment->execute($seasonalSegmentObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//cief todo: case study 3
|
||||
$user = $company->employees()->first();
|
||||
$this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_3]);
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($company));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-1
@@ -10,9 +10,11 @@ use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\NewLeadTaskToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\Milestones;
|
||||
use App\Models\Company;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -46,6 +48,9 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
/** @var NewLeadTaskToPerfexCRMProcessor */
|
||||
private $newLeadTaskToPerfexCRMProcessor;
|
||||
|
||||
/** @var CheckMilestonesForRewardProcessor */
|
||||
private $checkMilestonesForRewardProcessor;
|
||||
|
||||
/**
|
||||
* CreateIdentificationDocumentLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
@@ -53,14 +58,16 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
* @param CreatesFiles $createsFile
|
||||
* @param UpdatesCompanyStatus $updatesCompanyStatus
|
||||
* @param NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor
|
||||
* @param CheckMilestoneForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor)
|
||||
public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFile = $createsFile;
|
||||
$this->updatesCompanyStatus = $updatesCompanyStatus;
|
||||
$this->newLeadTaskToPerfexCRMProcessor = $newLeadTaskToPerfexCRMProcessor;
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +94,10 @@ class CreateIdentificationDocumentLogic extends AbstractControllerLogic
|
||||
$this->newLeadTaskToPerfexCRMProcessor->execute($company);
|
||||
}
|
||||
|
||||
//cief todo: case study 2
|
||||
$user = $company->employees()->first();
|
||||
$this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_2]);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\FetchesReward;
|
||||
use App\Classes\Modules\Milestones\Processors\CreateMilestoneProcessor;
|
||||
use App\Classes\Modules\Milestones\Processors\AssignRewardProcessor;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
use App\Http\Resources\MilestoneResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Reward;
|
||||
|
||||
class CreateMilestoneLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Create Milestone',
|
||||
'message' => 'You have successfully created a milestone'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesReward */
|
||||
private $fetchesReward;
|
||||
|
||||
/** @var CreateMilestoneProcessor */
|
||||
private $createMilestoneProcessor;
|
||||
|
||||
/** @var AssignRewardProcessor */
|
||||
private $assignRewardProcessor;
|
||||
|
||||
/**
|
||||
* CreateMilestoneLogic constructor.
|
||||
*/
|
||||
public function __construct(CreateMilestoneProcessor $createMilestoneProcessor, FetchesReward $fetchesReward, AssignRewardProcessor $assignRewardProcessor)
|
||||
{
|
||||
$this->createMilestoneProcessor = $createMilestoneProcessor;
|
||||
$this->fetchesReward = $fetchesReward;
|
||||
$this->assignRewardProcessor = $assignRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$milestone = $this->createMilestoneProcessor->execute($request);
|
||||
|
||||
//Extra checking to make sure that each reward exists
|
||||
$rewardIds = $request->input('reward_ids');
|
||||
foreach ($rewardIds as $rewardId) {
|
||||
/** @var Reward $reward */
|
||||
$this->fetchesReward->execute(['id' => $rewardId]);
|
||||
}
|
||||
|
||||
$object = new AchievementObject($milestone, $rewardIds);
|
||||
$this->assignRewardProcessor->execute($object);
|
||||
|
||||
return $this->resourceResponse(new MilestoneResource($milestone));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\MilestoneResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Milestones\Services\FetchesMilestone;
|
||||
|
||||
use App\Classes\Modules\Milestones\Standards\Rules\CanDeleteMilestone;
|
||||
use App\Classes\Modules\Milestones\Services\DeletesMilestone;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteMilestoneLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Milestone',
|
||||
'message' => 'You have successfully deleted the Milestone'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanDeleteMilestone */
|
||||
private $canDeleteMilestone;
|
||||
|
||||
/** @var DeletesMilestone */
|
||||
private $deletesMilestone;
|
||||
|
||||
/** @var FetchesMilestone */
|
||||
private $fetchesMiestone;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteMilestoneLogic constructor.
|
||||
* @param CanDeleteMilestone $canDeleteMilestone
|
||||
* @param DeletesMilestone $deletesMilestone
|
||||
* @param FetchesMilestone $fetchesMiestone
|
||||
*/
|
||||
public function __construct(
|
||||
CanDeleteMilestone $canDeleteMilestone,
|
||||
DeletesMilestone $deletesMilestone,
|
||||
FetchesMilestone $fetchesMiestone
|
||||
)
|
||||
{
|
||||
$this->canDeleteMilestone = $canDeleteMilestone;
|
||||
$this->deletesMilestone = $deletesMilestone;
|
||||
$this->fetchesMiestone = $fetchesMiestone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$query = $this->fetchesMiestone->execute(['id' => $request->route('id')]);
|
||||
$this->canDeleteMilestone->passes();
|
||||
$this->deletesMilestone->execute($query);
|
||||
|
||||
return $this->resourceResponse(new MilestoneResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Milestones\Services\ListsMilestoneProgress;
|
||||
use App\Http\Resources\MilestoneProgressResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListMilestoneProgressLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Milestone Progress',
|
||||
'message' => 'You have successfully retrieved a list of Milestone Progress'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsMilestoneProgress */
|
||||
private $listsMilestoneProgress;
|
||||
|
||||
/**
|
||||
* ListMilestoneProgressLogic constructor.
|
||||
* @param ListsMilestoneProgress $listsMilestoneProgress
|
||||
*/
|
||||
public function __construct(ListsMilestoneProgress $listsMilestoneProgress)
|
||||
{
|
||||
$this->listsMilestoneProgress = $listsMilestoneProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsMilestoneProgress->execute($this->listsMilestoneProgress->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(MilestoneProgressResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Milestones\Services\ListsMilestones;
|
||||
use App\Http\Resources\MilestoneResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListMilestonesLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Milestones',
|
||||
'message' => 'You have successfully retrieved a list of Milestones'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsMilestones */
|
||||
private $listsMilestones;
|
||||
|
||||
/**
|
||||
* ListMilestonesLogic constructor.
|
||||
* @param ListsMilestones $listsMilestones
|
||||
*/
|
||||
public function __construct(ListsMilestones $listsMilestones)
|
||||
{
|
||||
$this->listsMilestones = $listsMilestones;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsMilestones->execute($this->listsMilestones->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(MilestoneResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\FetchesReward;
|
||||
use App\Classes\Modules\Milestones\Processors\UpdateMilestoneProcessor;
|
||||
use App\Classes\Modules\Milestones\Processors\AssignRewardProcessor;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
use App\Http\Resources\MilestoneResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Reward;
|
||||
|
||||
class UpdateMilestoneLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Milestone',
|
||||
'message' => 'You have successfully updated a milestone'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesReward */
|
||||
private $fetchesReward;
|
||||
|
||||
/** @var UpdateMilestoneProcessor */
|
||||
private $updateMilestoneProcessor;
|
||||
|
||||
/** @var AssignRewardProcessor */
|
||||
private $assignRewardProcessor;
|
||||
|
||||
/**
|
||||
* UpdateMilestoneLogic constructor.
|
||||
* @param UpdateMilestoneProcessor $updateMilestoneProcessor
|
||||
* @param FetchesReward $fetchesReward
|
||||
* @param AssignRewardProcessor $assignRewardProcessor
|
||||
*/
|
||||
public function __construct(UpdateMilestoneProcessor $updateMilestoneProcessor, FetchesReward $fetchesReward, AssignRewardProcessor $assignRewardProcessor)
|
||||
{
|
||||
$this->updateMilestoneProcessor = $updateMilestoneProcessor;
|
||||
$this->fetchesReward = $fetchesReward;
|
||||
$this->assignRewardProcessor = $assignRewardProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$milestone = $this->updateMilestoneProcessor->execute($request);
|
||||
|
||||
//Extra checking to make sure that each reward exists
|
||||
$rewardIds = $request->input('reward_ids');
|
||||
foreach ($rewardIds as $rewardId) {
|
||||
/** @var Reward $reward */
|
||||
$this->fetchesReward->execute(['id' => $rewardId]);
|
||||
}
|
||||
|
||||
$object = new AchievementObject($milestone, $rewardIds);
|
||||
$this->assignRewardProcessor->execute($object);
|
||||
|
||||
return $this->resourceResponse(new MilestoneResource($milestone));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class AchievementObject implements DataTransferObject
|
||||
{
|
||||
/** @var Milestone */
|
||||
private $milestone;
|
||||
|
||||
/** @var array */
|
||||
private $rewardIds;
|
||||
|
||||
/**
|
||||
* AchievementObject constructor.
|
||||
* @param Milestone $milestone
|
||||
* @param array $reward
|
||||
*/
|
||||
public function __construct(Milestone $milestone, array $rewardIds)
|
||||
{
|
||||
$this->milestone = $milestone;
|
||||
$this->rewardIds = $rewardIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Milestone
|
||||
*/
|
||||
public function getMilestone(): Milestone
|
||||
{
|
||||
return $this->milestone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getRewardIds(): array
|
||||
{
|
||||
return $this->rewardIds;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class MilestoneObject implements DataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var string */
|
||||
private $description;
|
||||
|
||||
/**
|
||||
* MilestoneObject constructor.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $description
|
||||
*/
|
||||
public function __construct(int $id, string $name, string $description)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Processors;
|
||||
|
||||
use App\Classes\Modules\Milestones\Services\AssignsReward;
|
||||
use App\Classes\Modules\Milestones\Standards\Rules\CanAssignReward;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AssignRewardProcessor
|
||||
{
|
||||
|
||||
/** @var CanAssignReward */
|
||||
private $canAssignReward;
|
||||
|
||||
/** @var AssignsReward */
|
||||
private $assignsReward;
|
||||
|
||||
/**
|
||||
* AssignRewardProcessor constructor.
|
||||
* @param CanAssignReward $canAssignReward
|
||||
* @param AssignsReward $assignsReward
|
||||
*/
|
||||
public function __construct(CanAssignReward $canAssignReward, AssignsReward $assignsReward)
|
||||
{
|
||||
$this->canAssignReward = $canAssignReward;
|
||||
$this->assignsReward = $assignsReward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AchievementObject $object
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(AchievementObject $object): Model {
|
||||
|
||||
$this->canAssignReward->passes($object);
|
||||
|
||||
return $this->assignsReward->execute($object);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Processors;
|
||||
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
|
||||
use App\Classes\Modules\Milestones\Services\FetchesMilestone;
|
||||
use App\Classes\Modules\Milestones\Services\CreatesMilestoneProgress;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\ValueObjects\Constants\RewardType;
|
||||
use App\Models\Milestone;
|
||||
use App\Models\MilestoneProgress;
|
||||
use App\Models\Reward;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CheckMilestonesForRewardProcessor
|
||||
{
|
||||
/** @var CreatesVoucherifyVoucher */
|
||||
private $createsVoucherifyVoucher;
|
||||
|
||||
/** @var CreatesVoucher */
|
||||
private $createsVoucher;
|
||||
|
||||
/** @var CreatesMilestoneProgress */
|
||||
private $createsMilestoneProgress;
|
||||
|
||||
/** @var FetchesMilestone */
|
||||
private $fetchesMilestone;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/** @var FetchesVoucherifyVoucher */
|
||||
private $fetchesVoucherifyVoucher;
|
||||
|
||||
/** @var FetchesVoucher */
|
||||
private $fetchesVoucher;
|
||||
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/**
|
||||
* CheckMilestonesForRewardProcessor constructor.
|
||||
* @param CreatesVoucherifyVoucher $createsVoucherifyVoucher
|
||||
* @param CreatesVoucher $createsVoucher
|
||||
* @param FetchesMilestone $fetchesMilestone
|
||||
* @param CreatesMilestoneProgress $createsMilestoneProgress
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
* @param FetchesVoucherifyVoucher $fetchesVoucherifyVoucher
|
||||
* @param FetchesVoucher $fetchesVoucher
|
||||
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||
*/
|
||||
public function __construct(CreatesVoucherifyVoucher $createsVoucherifyVoucher, CreatesVoucher $createsVoucher, FetchesMilestone $fetchesMilestone, CreatesMilestoneProgress $createsMilestoneProgress, CreatesUserReward $createsUserReward, FetchesVoucherifyVoucher $fetchesVoucherifyVoucher, FetchesVoucher $fetchesVoucher, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
||||
{
|
||||
$this->createsVoucherifyVoucher = $createsVoucherifyVoucher;
|
||||
$this->createsVoucher = $createsVoucher;
|
||||
$this->fetchesMilestone = $fetchesMilestone;
|
||||
$this->createsMilestoneProgress = $createsMilestoneProgress;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param array $milestone_constants
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(User $user, array $milestone_constants)
|
||||
{
|
||||
try{
|
||||
foreach($milestone_constants as $constant)
|
||||
{
|
||||
//update milestone progress
|
||||
/** @var Milestone $milestone */
|
||||
$milestone = $this->fetchesMilestone->execute(['name' => $constant]);
|
||||
$result = null;
|
||||
if($user->milestoneProgress->count() > 0){
|
||||
$result = $user->milestoneProgress->where('milestone_id', $milestone->id)->first();
|
||||
}
|
||||
|
||||
if(!$result){
|
||||
$result = $this->createsMilestoneProgress->execute($milestone, $user->id);
|
||||
}
|
||||
|
||||
if($result){
|
||||
//fetch completed miletones
|
||||
$completedMilestones = MilestoneProgress::where('user_id', $user->id)->pluck('milestone_id');
|
||||
$rewards = $milestone->rewards;
|
||||
|
||||
//check for rewards that have a corresponding milestone count
|
||||
if(count($rewards) > 0){
|
||||
$this->checkMilestoneForReward($user, $completedMilestones, $rewards);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param object $completedMilestones
|
||||
* @param object $rewards
|
||||
* @return void
|
||||
*/
|
||||
private function checkMilestoneForReward(User $user, object $completedMilestones, object $rewards)
|
||||
{
|
||||
$milestoneIds = $rewards[0]->milestones->pluck('id');
|
||||
if ($milestoneIds->intersect($completedMilestones)->count() >= count($rewards[0]->milestones)) {
|
||||
/** @var Reward $reward */
|
||||
foreach ($rewards as $reward) {
|
||||
$result = null;
|
||||
if (!$user->rewards->contains('reward_id', $reward->id)) {
|
||||
$voucherId = 0;
|
||||
$voucherName = '';
|
||||
$voucherType = "";
|
||||
if($reward->type == RewardType::REWARD_AMOUNT){
|
||||
//Voucherify - Create Voucher
|
||||
$result = $this->createsVoucherifyVoucher->execute($user, intval($reward->value));
|
||||
}
|
||||
else{
|
||||
//Voucherify - Validates Voucher
|
||||
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $reward->value, 0.00, $user);
|
||||
$voucherifyVoucherValidated = $this->validatesVoucherifyVoucher->execute($ValidateVoucherifyVoucherObject);
|
||||
|
||||
if(!isset($voucherifyVoucherValidated->reason)){
|
||||
//Voucherify - Get Voucher
|
||||
$result = $this->fetchesVoucherifyVoucher->execute($user, $reward->value);
|
||||
}
|
||||
}
|
||||
|
||||
if($result && !isset($result->reason)){
|
||||
$voucherName = isset($result->campaign) ? $result->campaign : $reward->name;
|
||||
$voucherType = $result->discount->type;
|
||||
$voucherValue = isset($result->discount->amount_off) ? $result->discount->amount_off : $result->discount->percent_off;
|
||||
$voucherStartDate = $result->start_date;
|
||||
$voucherEndDate = $result->expiration_date;
|
||||
|
||||
//create voucher
|
||||
$voucherObject = new VoucherObject($result->code, isset($voucherName) ? $voucherName : "", $voucherType, $voucherValue, $voucherStartDate, $voucherEndDate);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
|
||||
$voucherId = $voucher->id;
|
||||
|
||||
//create reward to user (user_reward)
|
||||
$voucherCount = $user->rewards->where('voucher_id', $voucher->id)->count();
|
||||
if($voucherCount == 0){
|
||||
$this->createsUserReward->execute($reward, $user, $voucherId);
|
||||
}
|
||||
}
|
||||
else{
|
||||
Log::info('CheckMilestonesForRewardProcessor: no voucher fetched or created for reward '. json_encode($reward));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Processors;
|
||||
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Classes\Modules\Milestones\Services\CreatesMilestone;
|
||||
use App\Classes\Modules\Milestones\Standards\Rules\CanCreateMilestone;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CreateMilestoneProcessor
|
||||
{
|
||||
/** @var CreatesMilestone */
|
||||
private $createsMilestone;
|
||||
|
||||
/** @var CanCreateMilestone */
|
||||
private $canCreateMilestone;
|
||||
|
||||
/**
|
||||
* CreateMilestoneProcessor constructor.
|
||||
* @param CreatesMilestone $createsMilestone
|
||||
* @param CanCreateMilestone $canCreateMilestone
|
||||
*/
|
||||
public function __construct(CanCreateMilestone $canCreateMilestone, CreatesMilestone $createsMilestone)
|
||||
{
|
||||
$this->canCreateMilestone = $canCreateMilestone;
|
||||
$this->createsMilestone = $createsMilestone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request): Model
|
||||
{
|
||||
$userMilestoneObject = new MilestoneObject(
|
||||
$request->input('id'),
|
||||
$request->input('name'),
|
||||
$request->input('description')
|
||||
);
|
||||
|
||||
$this->canCreateMilestone->passes($userMilestoneObject);
|
||||
|
||||
return $this->createsMilestone->execute($userMilestoneObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Processors;
|
||||
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Classes\Modules\Milestones\Services\FetchesMilestone;
|
||||
use App\Classes\Modules\Milestones\Services\UpdatesMilestone;
|
||||
use App\Classes\Modules\Milestones\Standards\Rules\CanUpdateMilestone;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UpdateMilestoneProcessor
|
||||
{
|
||||
/** @var UpdatesMilestone */
|
||||
private $updatesMilestone;
|
||||
|
||||
/** @var FetchesMilestone */
|
||||
private $fetchesMilestone;
|
||||
|
||||
/** @var CanUpdateMilestone */
|
||||
private $canUpdateMilestone;
|
||||
|
||||
/**
|
||||
* UpdateMilestoneProcessor constructor.
|
||||
* @param UpdatesMilestone $updatesMilestone
|
||||
* @param FetchesMilestone $fetchesMilestone
|
||||
* @param CanUpdateMilestone $canUpdateMilestone
|
||||
*/
|
||||
public function __construct(CanUpdateMilestone $canUpdateMilestone, UpdatesMilestone $updatesMilestone, FetchesMilestone $fetchesMilestone)
|
||||
{
|
||||
$this->canUpdateMilestone = $canUpdateMilestone;
|
||||
$this->updatesMilestone = $updatesMilestone;
|
||||
$this->fetchesMilestone = $fetchesMilestone;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(Request $request): Model
|
||||
{
|
||||
$milestoneObject = new MilestoneObject(
|
||||
$request->input('id'),
|
||||
$request->input('name'),
|
||||
$request->input('description')
|
||||
);
|
||||
|
||||
$this->canUpdateMilestone->passes($milestoneObject);
|
||||
|
||||
$milestone = $this->fetchesMilestone->execute(['id' => $request->route('id')]);
|
||||
|
||||
return $this->updatesMilestone->execute($milestone, $milestoneObject);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class AssignsReward extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param AchievementObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(AchievementObject $object)
|
||||
{
|
||||
try {
|
||||
// $object->getMilestone()->rewards()->attach($object->getReward()->id);
|
||||
$object->getMilestone()->rewards()->sync($object->getRewardIds());
|
||||
|
||||
return $object->getMilestone();
|
||||
|
||||
} catch (QueryException $exception){
|
||||
throw new MalformedRequestException($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Models\MilestoneProgress;
|
||||
|
||||
class CheckIfMilestoneProgressExists
|
||||
{
|
||||
|
||||
/** @var MilestoneProgress */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* CheckIfMilestoneProgressExists constructor.
|
||||
* @param MilestoneProgress $repository
|
||||
*/
|
||||
public function __construct(MilestoneProgress $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function execute(int $user_id, int $milestone_id): bool {
|
||||
return $this->repository->where('user_id', $user_id)->where('milestone_id', $milestone_id)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class CreatesMilestone extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(MilestoneObject $object) {
|
||||
$model = new Milestone();
|
||||
$model->name = $object->getName();
|
||||
$model->description = $object->getDescription();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Models\Milestone;
|
||||
use App\Models\MilestoneProgress;
|
||||
|
||||
class CreatesMilestoneProgress extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/** @var CheckIfMilestoneProgressExists */
|
||||
private $isMilestoneProgressExists;
|
||||
|
||||
/**
|
||||
* CreatesMilestoneProgress constructor.
|
||||
* @param CheckIfMilestoneProgressExists $isMilestoneProgressExists
|
||||
*/
|
||||
public function __construct(CheckIfMilestoneProgressExists $isMilestoneProgressExists)
|
||||
{
|
||||
$this->isMilestoneProgressExists = $isMilestoneProgressExists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Milestone $milestone
|
||||
* @param string $userId
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function execute(Milestone $milestone, string $userId) {
|
||||
if(!$this->isMilestoneProgressExists->execute($userId, $milestone->id))
|
||||
{
|
||||
$model = new MilestoneProgress();
|
||||
$model->user_id = $userId;
|
||||
|
||||
return $this->handler($milestone->progress(), $model);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class DeletesMilestone extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Milestone $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Milestone $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class FetchesMilestone extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Milestone */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesMilestone constructor.
|
||||
* @param Milestone $repository
|
||||
*/
|
||||
public function __construct(Milestone $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\MilestoneProgress;
|
||||
|
||||
class ListsMilestoneProgress extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var MilestoneProgress */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsMilestoneProgress constructor.
|
||||
* @param MilestoneProgress $repository
|
||||
*/
|
||||
public function __construct(MilestoneProgress $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class ListsMilestones extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var Milestone */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsMilestones constructor.
|
||||
* @param Milestone $repository
|
||||
*/
|
||||
public function __construct(Milestone $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class UpdatesMilestone extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param Milestone $model
|
||||
* @param MilestoneObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Milestone $model, MilestoneObject $object)
|
||||
{
|
||||
$model->name = $object->getName();
|
||||
$model->description = $object->getDescription();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Milestones\Standards\Validators\MilestoneRewardValidation;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanAssignReward extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var MilestoneRewardValidation */
|
||||
private $milestoneRewardValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanAssignReward constructor.
|
||||
* @param MilestoneRewardValidation $milestoneRewardValidation
|
||||
*/
|
||||
public function __construct(MilestoneRewardValidation $milestoneRewardValidation)
|
||||
{
|
||||
$this->milestoneRewardValidation = $milestoneRewardValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('edit milestone')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AchievementObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->milestoneRewardValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AchievementObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Milestones\Standards\Validators\MilestoneValidation;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanCreateMilestone extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var MilestoneValidation */
|
||||
private $milestoneValidation;
|
||||
|
||||
/**
|
||||
* CanCreateMilestone constructor.
|
||||
* @param MilestoneValidation $milestoneValidation
|
||||
*/
|
||||
public function __construct(MilestoneValidation $milestoneValidation)
|
||||
{
|
||||
$this->milestoneValidation = $milestoneValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('add milestone')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->milestoneValidation->validate($object, 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanDeleteMilestone extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('delete milestone')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Classes\Modules\Milestones\Standards\Validators\MilestoneValidation;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanUpdateMilestone extends AbstractRule
|
||||
{
|
||||
/** @var MilestoneValidation */
|
||||
private $milestoneValidation;
|
||||
|
||||
|
||||
/**
|
||||
* CanUpdateMilestone constructor.
|
||||
* @param MilestoneValidation $milestoneValidation
|
||||
*/
|
||||
public function __construct(MilestoneValidation $milestoneValidation)
|
||||
{
|
||||
$this->milestoneValidation = $milestoneValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('edit milestone')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->milestoneValidation->validate($object, 'PUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Validators;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\AchievementObject;
|
||||
|
||||
class MilestoneRewardValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param AchievementObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array
|
||||
{
|
||||
return [
|
||||
'milestone_id' => $object->getMilestone()->id,
|
||||
'reward_ids' => $object->getRewardIds()
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'milestone_id' => 'required',
|
||||
'reward_ids' => 'required',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Milestones\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Milestones\DataTransferObjects\MilestoneObject;
|
||||
use App\Models\Milestone;
|
||||
|
||||
class MilestoneValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param MilestoneObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
|
||||
$data = [
|
||||
'name'=> $object->getName(),
|
||||
'description' => $object->getDescription(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(?string $type = 'POST'): array {
|
||||
if ($type == 'POST') { //crete
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
function ($attribute, $value, $fail) {
|
||||
// Check if milestone name already exists in the database
|
||||
$existingMilestone = Milestone::where('name', $value)->first();
|
||||
if ($existingMilestone) {
|
||||
$fail("The {$attribute} milestone name already exists in the database.");
|
||||
}
|
||||
},
|
||||
],
|
||||
'description' => [
|
||||
'required',
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
elseif($type == 'PUT') { //update
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
],
|
||||
'description' => [
|
||||
'required',
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,8 +39,7 @@ class FetchesPerfexCRMTask
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
// Log::error($response);
|
||||
Helper::debugLoggerForPerfexCRM($response);
|
||||
Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -38,8 +38,7 @@ class UpdatesPerfexCRMCustomer
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
// Log::error($response);
|
||||
Helper::debugLoggerForPerfexCRM($response);
|
||||
Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesReward;
|
||||
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
||||
use App\Classes\Modules\Rewards\Standards\Rules\CanCreateReward;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateRewardLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Create/Update Reward',
|
||||
'message' => 'You have successfully created/updated a reward'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesReward */
|
||||
private $createsReward;
|
||||
|
||||
/** @var CanCreateReward */
|
||||
private $canCreateReward;
|
||||
|
||||
/**
|
||||
* CreateRewardLogic constructor.
|
||||
*/
|
||||
public function __construct(CreatesReward $createsMilestone, CanCreateReward $canCreateReward)
|
||||
{
|
||||
$this->createsReward = $createsMilestone;
|
||||
$this->canCreateReward = $canCreateReward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$userRewardObject = new RewardObject(
|
||||
$request->input('id'),
|
||||
$request->input('name'),
|
||||
$request->input('description'),
|
||||
$request->input('value'),
|
||||
$request->input('type'),
|
||||
$request->input('is_active'),
|
||||
$request->input('order'),
|
||||
);
|
||||
|
||||
$this->canCreateReward->passes($userRewardObject);
|
||||
|
||||
$result = $this->createsReward->execute($userRewardObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\ControllersLogic;
|
||||
|
||||
use App\Http\Resources\RewardResource;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Rewards\Services\FetchesReward;
|
||||
|
||||
use App\Classes\Modules\Rewards\Standards\Rules\CanDeleteReward;
|
||||
use App\Classes\Modules\Rewards\Services\DeletesReward;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteRewardLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Reward',
|
||||
'message' => 'You have successfully deleted the Reward'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanDeleteReward */
|
||||
private $canDeleteReward;
|
||||
|
||||
/** @var DeletesReward */
|
||||
private $deletesReward;
|
||||
|
||||
/** @var FetchesReward */
|
||||
private $fetchesReward;
|
||||
|
||||
|
||||
/**
|
||||
* DeleteRewardLogic constructor.
|
||||
* @param CanDeleteReward $canDeleteReward
|
||||
* @param DeletesReward $deletesReward
|
||||
* @param FetchesReward $fetchesReward
|
||||
*/
|
||||
public function __construct(
|
||||
CanDeleteReward $canDeleteReward,
|
||||
DeletesReward $deletesReward,
|
||||
FetchesReward $fetchesReward
|
||||
)
|
||||
{
|
||||
$this->canDeleteReward = $canDeleteReward;
|
||||
$this->deletesReward = $deletesReward;
|
||||
$this->fetchesReward = $fetchesReward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$query = $this->fetchesReward->execute(['id' => $request->route('id')]);
|
||||
$this->canDeleteReward->passes();
|
||||
$this->deletesReward->execute($query);
|
||||
|
||||
return $this->resourceResponse(new RewardResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\ListsRewards;
|
||||
use App\Http\Resources\RewardDetailsResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListRewardsDetailsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Rewards Details',
|
||||
'message' => 'You have successfully retrieved a list of Rewards Details'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsRewards */
|
||||
private $listsRewards;
|
||||
|
||||
/**
|
||||
* ListRewardsDetailsLogic constructor.
|
||||
* @param ListsRewards $listsRewards
|
||||
*/
|
||||
public function __construct(ListsRewards $listsRewards)
|
||||
{
|
||||
$this->listsRewards = $listsRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsRewards->execute($this->listsRewards->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(RewardDetailsResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\ListsRewards;
|
||||
use App\Http\Resources\RewardResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListRewardsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Rewards',
|
||||
'message' => 'You have successfully retrieved a list of Rewards'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsRewards */
|
||||
private $listsRewards;
|
||||
|
||||
/**
|
||||
* ListRewardsLogic constructor.
|
||||
* @param ListsRewards $listsRewards
|
||||
*/
|
||||
public function __construct(ListsRewards $listsRewards)
|
||||
{
|
||||
$this->listsRewards = $listsRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsRewards->execute($this->listsRewards->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(RewardResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class RewardObject implements DataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var string */
|
||||
private $description;
|
||||
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
/** @var string */
|
||||
private $type;
|
||||
|
||||
/** @var bool */
|
||||
private $isActive;
|
||||
|
||||
/** @var int */
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* RewardObject constructor.
|
||||
* @param int $id
|
||||
* @param string $name
|
||||
* @param string $description
|
||||
* @param string $value
|
||||
* @param string $type
|
||||
* @param bool $isActive
|
||||
* @param int $order
|
||||
*/
|
||||
public function __construct(int $id, string $name, string $description, string $value, string $type, bool $isActive = true, ?int $order = 9999)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$this->value = $value;
|
||||
$this->type = $type;
|
||||
$this->isActive = $isActive;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getValue(): string
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsActive(): bool
|
||||
{
|
||||
return $this->isActive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOrder(): int
|
||||
{
|
||||
return $this->order ?? 9999;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
||||
use App\Models\Reward;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
class CreatesReward extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(RewardObject $object) {
|
||||
|
||||
// $model = new Reward();
|
||||
// $model->name = $object->getName();
|
||||
// $model->description = $object->getDescription();
|
||||
// $model->value = $object->getValue();
|
||||
// $model->type = $object->getType();
|
||||
// $model->is_active = $object->getIsActive();
|
||||
// return $this->handler($model);
|
||||
|
||||
try{
|
||||
$data = [
|
||||
'id' => $object->getId(),
|
||||
'name' => $object->getName(),
|
||||
'description' => $object->getDescription(),
|
||||
'value' => $object->getValue(),
|
||||
'type' => $object->getType(),
|
||||
'is_active' => $object->getIsActive(),
|
||||
'order' => $object->getOrder(),
|
||||
];
|
||||
|
||||
return Reward::upsert([$data], ['id'], ['name', 'description', 'value', 'type', 'is_active', 'order']);
|
||||
|
||||
} catch (QueryException $exception){
|
||||
throw new MalformedRequestException($exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Models\Reward;
|
||||
use App\Models\User;
|
||||
use App\Models\UserReward;
|
||||
|
||||
class CreatesUserReward extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param Reward $reward
|
||||
* @param User $user
|
||||
* @param int $voucherId
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(?Reward $reward, User $user, int $voucherId) {
|
||||
if($reward){
|
||||
$model = new UserReward();
|
||||
$model->user_id = $user->id;
|
||||
$model->voucher_id = $voucherId;
|
||||
return $this->handler($reward->users(), $model);
|
||||
}
|
||||
else{
|
||||
$model = new UserReward();
|
||||
$model->voucher_id = $voucherId;
|
||||
return $this->handler($user->rewards(), $model);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Reward;
|
||||
|
||||
class DeletesReward extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Reward $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Reward $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Reward;
|
||||
|
||||
class FetchesReward extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Reward */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesReward constructor.
|
||||
* @param Reward $repository
|
||||
*/
|
||||
public function __construct(Reward $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Reward;
|
||||
|
||||
class ListsRewards extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var Reward */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsRewards constructor.
|
||||
* @param Reward $repository
|
||||
*/
|
||||
public function __construct(Reward $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\UserReward;
|
||||
|
||||
class ListsUserRewards extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var UserReward */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsUserRewards constructor.
|
||||
* @param UserReward $repository
|
||||
*/
|
||||
public function __construct(UserReward $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Rewards\Standards\Validators\RewardValidation;
|
||||
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanCreateReward extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var RewardValidation */
|
||||
private $rewardValidation;
|
||||
|
||||
/**
|
||||
* CanCreateReward constructor.
|
||||
* @param RewardValidation $rewardValidation
|
||||
*/
|
||||
public function __construct(RewardValidation $rewardValidation)
|
||||
{
|
||||
$this->rewardValidation = $rewardValidation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('add reward')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true; // $this->rewardValidation->validate($object, 'POST');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class CanDeleteReward extends AbstractRule
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
if (!Auth::user()->can('delete reward')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Rewards\Standards\Validators;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractValidation;
|
||||
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
||||
use App\Models\Reward;
|
||||
|
||||
class RewardValidation extends AbstractValidation
|
||||
{
|
||||
/**
|
||||
* @param RewardObject $object
|
||||
* @return array
|
||||
*/
|
||||
protected function data($object): array {
|
||||
|
||||
$data = [
|
||||
'name'=> $object->getName(),
|
||||
'description' => $object->getDescription(),
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $type
|
||||
* @return array
|
||||
*/
|
||||
protected function rules(): array {
|
||||
return [
|
||||
'name' => [
|
||||
'required',
|
||||
function ($attribute, $value, $fail) {
|
||||
// Check if reward name already exists in the database
|
||||
$existingMilestone = Reward::where('name', $value)->first();
|
||||
if ($existingMilestone) {
|
||||
$fail("The {$attribute} reward name already exists in the database.");
|
||||
}
|
||||
},
|
||||
],
|
||||
'description' => [
|
||||
'required',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function messages(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,19 +5,27 @@ namespace App\Classes\Modules\Transactions\Services;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\TransactionToPerfexCRMProcessorV2;
|
||||
use App\Models\Transaction;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\TransactionToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\TransactionToVoucherifyProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
|
||||
class UpdatesTransactionStatus extends AbstractUpdateRecord
|
||||
{
|
||||
/** @var TransactionToPerfexCRMProcessorV2 */
|
||||
private $transactionToPerfexCRMProcessor;
|
||||
|
||||
/** @var TransactionToVoucherifyProcessor */
|
||||
private $transactionToVoucherifyProcessor;
|
||||
|
||||
/**
|
||||
* UpdatesTransactionStatus constructor.
|
||||
* @param TransactionToPerfexCRMProcessorV2 $transactionToPerfexCRMProcessor
|
||||
* @param TransactionToVoucherifyProcessor $transactionToVoucherifyProcessor
|
||||
*/
|
||||
public function __construct(TransactionToPerfexCRMProcessorV2 $transactionToPerfexCRMProcessor)
|
||||
public function __construct(TransactionToPerfexCRMProcessorV2 $transactionToPerfexCRMProcessor, TransactionToVoucherifyProcessor $transactionToVoucherifyProcessor)
|
||||
{
|
||||
$this->transactionToPerfexCRMProcessor = $transactionToPerfexCRMProcessor;
|
||||
$this->transactionToVoucherifyProcessor = $transactionToVoucherifyProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +43,11 @@ class UpdatesTransactionStatus extends AbstractUpdateRecord
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->transactionToPerfexCRMProcessor->execute($transaction, $status);
|
||||
}
|
||||
|
||||
if($status == ApprovalStatus::APPROVED && ($transaction->type == TransactionType::PAYMENT || $transaction->type == TransactionType::TOP_UP)){
|
||||
$this->transactionToVoucherifyProcessor->execute($transaction, "PAID");
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Vouchers\Processors\CreateVoucherProcessor;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class CreateVoucherLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Create Voucher',
|
||||
'message' => 'You have successfully created a voucher'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreateVoucherProcessor */
|
||||
private $createVoucherProcessor;
|
||||
|
||||
/**
|
||||
* CreateVoucherLogic constructor.
|
||||
* @param CreateVoucherProcessor $createVoucherProcessor
|
||||
*/
|
||||
public function __construct(CreateVoucherProcessor $createVoucherProcessor)
|
||||
{
|
||||
$this->createVoucherProcessor = $createVoucherProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$user = User::where('id', $request->input('userId'))->first();
|
||||
$result = $this->createVoucherProcessor->execute($user, $request->input('voucherCode'), null);
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Rewards\Services\ListsUserRewards;
|
||||
use App\Http\Resources\UserRewardResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListUserVouchersLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* ListUserVouchersLogic constructor.
|
||||
* @param ListsUserRewards $listsUserRewards
|
||||
*/
|
||||
public function __construct(ListsUserRewards $listsUserRewards)
|
||||
{
|
||||
$this->listsUserRewards = $listsUserRewards;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved User Vouchers',
|
||||
'message' => 'You have successfully retrieved a list of user vouchers'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsUserRewards */
|
||||
private $listsUserRewards;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsUserRewards->execute($this->listsUserRewards->deserializeFilters($request->input('filters')));
|
||||
return $this->collectionResponse(UserRewardResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Vouchers\Services\RedeemsVoucher;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use ErrorException;
|
||||
|
||||
class RedeemVoucherLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Redeem Voucher',
|
||||
'message' => 'You have successfully redeemed a voucher'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var RedeemsVoucher */
|
||||
private $redeemsVoucher;
|
||||
|
||||
/**
|
||||
* RedeemVoucherLogic constructor.
|
||||
*/
|
||||
public function __construct(RedeemsVoucher $redeemVoucher)
|
||||
{
|
||||
$this->redeemsVoucher = $redeemVoucher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$result = $this->redeemsVoucher->execute($request->input('promoCode'), $request->input('amount'));
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -5,10 +5,11 @@ namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Vouchers\Services\ValidatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use ErrorException;
|
||||
use App\Models\Booking;
|
||||
|
||||
class ValidateVoucherLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -22,15 +23,16 @@ class ValidateVoucherLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ValidatesVoucher */
|
||||
private $validatesVoucher;
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/**
|
||||
* ValidateVoucherLogic constructor.
|
||||
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||
*/
|
||||
public function __construct(ValidatesVoucher $validatesVoucher)
|
||||
public function __construct(ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
||||
{
|
||||
$this->validatesVoucher = $validatesVoucher;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,9 +42,12 @@ class ValidateVoucherLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$result = $this->validatesVoucher->execute($request->input('voucherCode'), null, null);
|
||||
$booking = Booking::find($request->input('itemId'));
|
||||
$employee = $booking->company->employees()->first();
|
||||
|
||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($booking->company_id, $request->input('voucherCode'), $request->input('amount'), $employee);
|
||||
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreateVoucherifyCustomerObject implements DataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
private $companyId;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var bool */
|
||||
private $isNew; //this is to cater for creating customer that is existing in system but not yet exist in voucherify
|
||||
|
||||
/** @var string */
|
||||
private $acquisitionChannel;
|
||||
|
||||
/**
|
||||
* CreateVoucherifyCustomerObject constructor.
|
||||
* @param int $companyId
|
||||
* @param User $user
|
||||
* @param bool $isNew
|
||||
* @param string $acquisitionChannel
|
||||
*/
|
||||
public function __construct(int $companyId, User $user, bool $isNew, string $acquisitionChannel = 'exchange')
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->user = $user;
|
||||
$this->isNew = $isNew;
|
||||
$this->acquisitionChannel = $acquisitionChannel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): int
|
||||
{
|
||||
return $this->companyId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsNew(): bool
|
||||
{
|
||||
return $this->isNew;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAcquisitionChannel(): string
|
||||
{
|
||||
return $this->acquisitionChannel;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreateVoucherifyOrderObject implements DataTransferObject
|
||||
{
|
||||
/** @var User */
|
||||
private $employee;
|
||||
|
||||
/** @var int */
|
||||
private $companyId;
|
||||
|
||||
/** @var float */
|
||||
private $amount;
|
||||
|
||||
/** @var bool */
|
||||
private $isNoVoucher;
|
||||
|
||||
/** @var bool */
|
||||
private $isTopUpWallet;
|
||||
|
||||
/**
|
||||
* CreateVoucherifyOrderObject constructor.
|
||||
* @param User $employee
|
||||
* @param int $companyId
|
||||
* @param float $amount
|
||||
* @param bool $isNoVoucher
|
||||
* @param bool $isTopUpWallet
|
||||
*/
|
||||
public function __construct(User $employee, int $companyId, float $amount, bool $isNoVoucher, bool $isTopUpWallet)
|
||||
{
|
||||
$this->employee = $employee;
|
||||
$this->companyId = $companyId;
|
||||
$this->amount = $amount;
|
||||
$this->isNoVoucher = $isNoVoucher;
|
||||
$this->isTopUpWallet = $isTopUpWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): string
|
||||
{
|
||||
return $this->companyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getEmployee(): User
|
||||
{
|
||||
return $this->employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsNoVoucher(): bool
|
||||
{
|
||||
return $this->isNoVoucher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsTopUpWallet(): bool
|
||||
{
|
||||
return $this->isTopUpWallet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class RedeemVoucherifyVoucherObject implements DataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
private $companyId;
|
||||
|
||||
/** @var string */
|
||||
private $promoCode;
|
||||
|
||||
/** @var string */
|
||||
private $amount;
|
||||
|
||||
/** @var object */
|
||||
private $employee;
|
||||
|
||||
/**
|
||||
* RedeemVoucherifyVoucherObject constructor.
|
||||
* @param int $companyId
|
||||
* @param string $name
|
||||
* @param string $email
|
||||
* @param object $employee
|
||||
*/
|
||||
public function __construct(int $companyId, string $promoCode, string $amount, object $employee)
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->promoCode = $promoCode;
|
||||
$this->amount = $amount;
|
||||
$this->employee = $employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): int
|
||||
{
|
||||
return $this->companyId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPromoCode(): string
|
||||
{
|
||||
return $this->promoCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount(): string
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
public function getEmployee(): object
|
||||
{
|
||||
return $this->employee;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class UpdateVoucherifyOrderObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $status;
|
||||
|
||||
/**
|
||||
* UpdateVoucherifyOrderObject constructor.
|
||||
* @param string $id
|
||||
* @param string $status
|
||||
*/
|
||||
public function __construct(string $id, string $status)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\User;
|
||||
|
||||
class ValidateVoucherifyVoucherObject implements DataTransferObject
|
||||
{
|
||||
/** @var int */
|
||||
private $companyId;
|
||||
|
||||
/** @var string */
|
||||
private $voucherCode;
|
||||
|
||||
/** @var float */
|
||||
private $amount;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* ValidateVoucherifyVoucherObject constructor.
|
||||
* @param int $companyId
|
||||
* @param string $voucherCode
|
||||
* @param float $amount
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(int $companyId, string $voucherCode, float $amount, User $user)
|
||||
{
|
||||
$this->companyId = $companyId;
|
||||
$this->voucherCode = $voucherCode;
|
||||
$this->amount = $amount;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyId(): int
|
||||
{
|
||||
return $this->companyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVoucherCode(): string
|
||||
{
|
||||
return $this->voucherCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function getUser(): User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class VoucherEntityObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $id;
|
||||
|
||||
/** @var string */
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* VoucherEntityObject constructor.
|
||||
* @param string $id
|
||||
* @param string $type
|
||||
*/
|
||||
public function __construct(string $id, string $type)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getId(): string
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use DateTime;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class VoucherObject implements DataTransferObject
|
||||
{
|
||||
@@ -18,19 +20,29 @@ class VoucherObject implements DataTransferObject
|
||||
/** @var float|null */
|
||||
private $value;
|
||||
|
||||
/** @var string|null */
|
||||
private $startDate;
|
||||
|
||||
/** @var string|null */
|
||||
private $endDate;
|
||||
|
||||
/**
|
||||
* VoucherObject constructor.
|
||||
* @param string $code
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param float $value
|
||||
* @param string $startDate
|
||||
* @param string $endDate
|
||||
*/
|
||||
public function __construct(string $code, ?string $name, ?string $type, ?float $value)
|
||||
public function __construct(string $code, ?string $name, ?string $type, ?float $value, ?string $startDate = '', ?string $endDate = '')
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,4 +79,33 @@ class VoucherObject implements DataTransferObject
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getStartDate(): ?DateTime
|
||||
{
|
||||
try {
|
||||
if(!$this->startDate) return null;
|
||||
$dateTime = new DateTime($this->startDate);
|
||||
return $dateTime;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getEndDate(): ?DateTime
|
||||
{
|
||||
try {
|
||||
if(!$this->endDate) return null;
|
||||
$dateTime = new DateTime($this->endDate);
|
||||
return $dateTime;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Processors;
|
||||
|
||||
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class CreateVoucherProcessor
|
||||
{
|
||||
/** @var FetchesVoucherifyVoucher */
|
||||
private $fetchesVoucherifyVoucher;
|
||||
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/** @var CreatesVoucher */
|
||||
private $createsVoucher;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/** @var FetchesVoucher */
|
||||
private $fetchesVoucher;
|
||||
|
||||
/**
|
||||
* CreateVoucherProcessor constructor.
|
||||
* @param FetchesVoucherifyVoucher $fetchesVoucherifyVoucher
|
||||
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||
* @param CreatesVoucher $createsVoucher
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
* @param FetchesVoucher $fetchesVoucher
|
||||
*/
|
||||
public function __construct(FetchesVoucherifyVoucher $fetchesVoucherifyVoucher, CreatesVoucher $createsVoucher, CreatesUserReward $createsUserReward, FetchesVoucher $fetchesVoucher, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
|
||||
{
|
||||
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
|
||||
$this->createsVoucher = $createsVoucher;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ?User $userParam
|
||||
* @param string $voucherCodeInput
|
||||
* @return array
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
public function execute(?User $userParam, string $voucherCodeInput) {
|
||||
try{
|
||||
$result = null;
|
||||
$user = Auth::user(); /** @var User $user */
|
||||
if($user && isset($user->type) && in_array($user->type, RoleTypes::ADMIN_ROLES) && $userParam){
|
||||
$user = User::where('id', $userParam->id)->first();
|
||||
}
|
||||
else{
|
||||
$user = $userParam ? $userParam : $user;
|
||||
}
|
||||
|
||||
//Voucherify - Validates Voucher
|
||||
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $voucherCodeInput, 0.00, $user);
|
||||
$voucherifyVoucherValidated = $this->validatesVoucherifyVoucher->execute($ValidateVoucherifyVoucherObject);
|
||||
|
||||
if(isset($voucherifyVoucherValidated->reason)){
|
||||
$result = [];
|
||||
$result['reason'] = $voucherifyVoucherValidated->reason;
|
||||
}
|
||||
else if($voucherifyVoucherValidated){
|
||||
$voucher = $this->recordVoucherInfo($user, $voucherCodeInput);
|
||||
$voucherCount = $user->rewards->where('voucher_id', $voucher->id)->count();
|
||||
if($voucherCount == 0){
|
||||
$result = $this->createsUserReward->execute(null, $user, $voucher->id);
|
||||
}
|
||||
else{
|
||||
$result['reason'] = 'Voucher already added';
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
private function recordVoucherInfo(User $user, string $voucherCodeInput){
|
||||
//Voucherify - Get Voucher
|
||||
$voucherifyVoucherFetched = $this->fetchesVoucherifyVoucher->execute($user, $voucherCodeInput);
|
||||
|
||||
$voucherName = $voucherifyVoucherFetched->campaign;
|
||||
$voucherType = $voucherifyVoucherFetched->discount->type;
|
||||
$voucherValue = isset($voucherifyVoucherFetched->discount->amount_off) ? $voucherifyVoucherFetched->discount->amount_off : $voucherifyVoucherFetched->discount->percent_off;
|
||||
$voucherCode = $voucherifyVoucherFetched->code;
|
||||
$voucherStartDate = $voucherifyVoucherFetched->start_date;
|
||||
$voucherEndDate = $voucherifyVoucherFetched->expiration_date;
|
||||
|
||||
$voucherObject= new VoucherObject($voucherCode, isset($voucherName) ? $voucherName : "Voucherify Voucher Added Manually", $voucherType, $voucherValue, $voucherStartDate, $voucherEndDate);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherCodeInput]);
|
||||
return $voucher;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Processors\Voucherify;
|
||||
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherObject;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\RedeemsVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucherRedemption;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\RedeemVoucherifyVoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyOrderObject;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyOrder;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucherEntityMapping;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\VoucherifyEntityType;
|
||||
use App\Models\User;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Voucher;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class BookingToVoucherifyProcessor
|
||||
{
|
||||
/** @var CreatesVoucher */
|
||||
private $createsVoucher;
|
||||
|
||||
/** @var FetchesVoucher */
|
||||
private $fetchesVoucher;
|
||||
|
||||
/** @var CreatesVoucherRedemption */
|
||||
private $createsVoucherRedemption;
|
||||
|
||||
/** @var RedeemsVoucherifyVoucher */
|
||||
private $redeemsVoucherifyVoucher;
|
||||
|
||||
/** @var CreatesVoucherifyOrder */
|
||||
private $createsVoucherifyOrder;
|
||||
|
||||
/** @var CreatesVoucherEntityMapping */
|
||||
private $createsVoucherEntityMapping;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/**
|
||||
* BookingToVoucherifyProcessor constructor.
|
||||
* @param CreatesVoucher $createsVoucher
|
||||
* @param FetchesVoucher $fetchesVoucher
|
||||
* @param CreatesVoucherRedemption $createsVoucherRedemption
|
||||
* @param RedeemsVoucherifyVoucher $redeemsVoucherifyVoucher
|
||||
* @param CreatesVoucherifyOrder $createsVoucherifyOrder
|
||||
* @param CreatesVoucherEntityMapping $createsVoucherEntityMapping
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
*/
|
||||
public function __construct(CreatesVoucher $createsVoucher, FetchesVoucher $fetchesVoucher, CreatesVoucherRedemption $createsVoucherRedemption, RedeemsVoucherifyVoucher $redeemsVoucherifyVoucher, CreatesVoucherifyOrder $createsVoucherifyOrder, CreatesVoucherEntityMapping $createsVoucherEntityMapping, CreatesUserReward $createsUserReward)
|
||||
{
|
||||
$this->createsVoucher = $createsVoucher;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
$this->createsVoucherRedemption = $createsVoucherRedemption;
|
||||
$this->redeemsVoucherifyVoucher = $redeemsVoucherifyVoucher;
|
||||
$this->createsVoucherifyOrder = $createsVoucherifyOrder;
|
||||
$this->createsVoucherEntityMapping = $createsVoucherEntityMapping;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param Transaction $transaction
|
||||
* @param int $companyId
|
||||
* @param float $amount
|
||||
* @param float $voucherDiscountAmount
|
||||
* @param string $voucherCode
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(User $user, Transaction $transaction, int $companyId, float $amount, float $voucherDiscountAmount, ?string $voucherCode = "")
|
||||
{
|
||||
try{
|
||||
$voucherify_customer_id = "";
|
||||
$voucherify_order_id = "";
|
||||
if($voucherCode){
|
||||
$redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $voucherCode, $amount, $user);
|
||||
$redeemVoucherResult = $this->redeemsVoucherifyVoucher->execute($redeemVoucherifyVoucherObject);
|
||||
$redeemedVoucher = $redeemVoucherResult->voucher;
|
||||
$redemptionId = $redeemVoucherResult->id;
|
||||
|
||||
if($redeemVoucherResult && isset($redeemVoucherResult->order)){
|
||||
$voucherify_order_id = $redeemVoucherResult->order->id;
|
||||
}
|
||||
|
||||
if($redeemVoucherResult && isset($redeemVoucherResult->customer)){
|
||||
$voucherify_customer_id = $redeemVoucherResult->customer->id;
|
||||
}
|
||||
|
||||
$voucher = $this->recordVoucherInfo($redeemedVoucher, $transaction);
|
||||
$this->createsVoucherRedemption->execute($transaction, $voucher, $redemptionId, $voucherDiscountAmount);
|
||||
$this->recordVoucherForUserInfo($user, $voucher);
|
||||
}
|
||||
else{
|
||||
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $amount, true, $transaction->type == TransactionType::TOP_UP);
|
||||
$createVoucherufyOrderResult = $this->createsVoucherifyOrder->execute($createVoucherifyOrderObject);
|
||||
|
||||
if($createVoucherufyOrderResult && isset($createVoucherufyOrderResult->id)){
|
||||
$voucherify_order_id = $createVoucherufyOrderResult->id;
|
||||
if(isset($createVoucherufyOrderResult->customer)){
|
||||
$voucherify_customer_id = $createVoucherufyOrderResult->customer->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->recordVoucherifyOrderInfo($voucherify_order_id, $transaction);
|
||||
$this->recordVoucherifyCustomerInfo($voucherify_customer_id, $user);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
|
||||
private function recordVoucherInfo(object $redeemedVoucher){
|
||||
//Create records at 3 tables
|
||||
$voucherValue = isset($redeemedVoucher->discount->amount_off) ? $redeemedVoucher->discount->amount_off : $redeemedVoucher->discount->percent_off;
|
||||
$voucherType = $redeemedVoucher->discount ? $redeemedVoucher->discount->type : null;
|
||||
|
||||
$voucherObject= new VoucherObject($redeemedVoucher->code, isset($redeemedVoucher->metadata->name) ? $redeemedVoucher->metadata->name : "", $voucherType, $voucherValue);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
|
||||
|
||||
return $voucher;
|
||||
}
|
||||
|
||||
private function recordVoucherForUserInfo(User $user, Voucher $voucher){
|
||||
//create reward to user (user_reward)
|
||||
$voucherCount = $user->rewards->where('voucher_id', $voucher->id)->count();
|
||||
if($voucherCount == 0){
|
||||
$this->createsUserReward->execute(null, $user, $voucher->id);
|
||||
}
|
||||
}
|
||||
|
||||
private function recordVoucherifyOrderInfo(string $voucherify_order_id, Transaction $transaction){
|
||||
//Update Database - 1 table
|
||||
if($voucherify_order_id){
|
||||
$voucherify_entity = $transaction->voucherifyEntities()->first();
|
||||
if(!$voucherify_entity){
|
||||
$voucherEntityObject = new VoucherEntityObject($voucherify_order_id, VoucherifyEntityType::ORDER);
|
||||
$this->createsVoucherEntityMapping->execute($transaction, $voucherEntityObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function recordVoucherifyCustomerInfo(string $voucherify_customer_id, User $user){
|
||||
//Update Database - 1 table
|
||||
if($voucherify_customer_id){
|
||||
$voucherify_entity = $user->voucherifyEntities()->first();
|
||||
if(!$voucherify_entity){
|
||||
$voucherEntityObject = new VoucherEntityObject($voucherify_customer_id, VoucherifyEntityType::CUSTOMER);
|
||||
$this->createsVoucherEntityMapping->execute($user, $voucherEntityObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Processors\Voucherify;
|
||||
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucherEntityMapping;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyCustomer;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyCustomerObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
|
||||
use App\Classes\ValueObjects\Constants\VoucherifyEntityType;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class NewCustomerToVoucherifyProcessor
|
||||
{
|
||||
/** @var CreatesVoucherEntityMapping */
|
||||
private $createsVoucherEntityMapping;
|
||||
|
||||
/** @var CreatesVoucherifyCustomer */
|
||||
private $createsVoucherifyCustomer;
|
||||
|
||||
/**
|
||||
* NewCustomerToVoucherifyProcessor constructor.
|
||||
* @param CreatesVoucherEntityMapping $createsVoucherEntityMapping
|
||||
* @param CreatesVoucherifyCustomer $createsVoucherifyCustomer
|
||||
*/
|
||||
public function __construct(CreatesVoucherEntityMapping $createsVoucherEntityMapping, CreatesVoucherifyCustomer $createsVoucherifyCustomer)
|
||||
{
|
||||
$this->createsVoucherEntityMapping = $createsVoucherEntityMapping;
|
||||
$this->createsVoucherifyCustomer = $createsVoucherifyCustomer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $companyId
|
||||
* @param User $user
|
||||
* @param bool $isNew
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(int $companyId, User $user, bool $isNew)
|
||||
{
|
||||
try
|
||||
{
|
||||
$createVoucherifyCustomerObject = new CreateVoucherifyCustomerObject($companyId, $user, $isNew);
|
||||
$result = $this->createsVoucherifyCustomer->execute($createVoucherifyCustomerObject);
|
||||
|
||||
if($result && isset($result->id)){
|
||||
$voucherEntityObject = new VoucherEntityObject($result->id, VoucherifyEntityType::CUSTOMER);
|
||||
$this->createsVoucherEntityMapping->execute($createVoucherifyCustomerObject->getUser(), $voucherEntityObject);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Processors\Voucherify;
|
||||
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\UpdateVoucherifyOrderObject;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\UpdatesVoucherifyOrder;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TransactionToVoucherifyProcessor
|
||||
{
|
||||
/** @var UpdatesVoucherifyOrder */
|
||||
private $updatesVoucherifyOrder;
|
||||
|
||||
/**
|
||||
* TransactionToVoucherifyProcessor constructor.
|
||||
* @param UpdatesVoucherifyOrder $updatesVoucherifyOrder
|
||||
*/
|
||||
public function __construct(UpdatesVoucherifyOrder $updatesVoucherifyOrder)
|
||||
{
|
||||
$this->updatesVoucherifyOrder = $updatesVoucherifyOrder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @param string $status
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(Transaction $transaction, string $status)
|
||||
{
|
||||
try{
|
||||
$voucherify_entity = $transaction->voucherifyEntities()->first();
|
||||
if($voucherify_entity){
|
||||
$updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $status);
|
||||
$this->updatesVoucherifyOrder->execute($updateVoucherifyOrderObject);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ class CreatesVoucher extends AbstractUpdateRecord
|
||||
$model->name = $object->getName();
|
||||
$model->type = $object->getType();
|
||||
$model->value = $object->getValue();
|
||||
$model->start_date = $object->getStartDate();
|
||||
$model->end_date = $object->getEndDate();
|
||||
return $this->handler($model);
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
|
||||
use App\Classes\General\Interfaces\Voucherifiable;
|
||||
use App\Models\VoucherEntityMapping;
|
||||
|
||||
class CreatesVoucherEntityMapping extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param Voucherifiable $voucherifable
|
||||
* @param VoucherObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Voucherifiable $voucherifable, VoucherEntityObject $object) {
|
||||
$model = new VoucherEntityMapping();
|
||||
$model->voucherify_entity_id = $object->getId();
|
||||
$model->voucherify_entity_type = $object->getType();
|
||||
return $this->handler($voucherifable->voucherifyEntities(), $model);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
use ErrorException;
|
||||
|
||||
class RedeemsVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* RedeemsVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $promoCode
|
||||
* @param string $amount
|
||||
* @param object $employee
|
||||
* @return null|object
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function execute(string $promoCode, string $amount, object $employee)
|
||||
{
|
||||
try {
|
||||
$result = $this->voucherifyClient->redemptions->redeem($promoCode, [
|
||||
"customer" => [
|
||||
// "id" => $employee->id,
|
||||
"name" => $employee->name,
|
||||
"email" => $employee->email,
|
||||
],
|
||||
"order" => [
|
||||
"amount" => $amount * 100 //converting it to cents
|
||||
]
|
||||
]);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RollbacksRedemption
|
||||
@@ -24,7 +23,7 @@ class RollbacksRedemption
|
||||
/**
|
||||
* @param string $redemptionId
|
||||
* @return null|object
|
||||
* @throws ErrorException
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(string $redemptionId)
|
||||
{
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ValidatesVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* ValidatesVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $voucherCode
|
||||
* @param float $amount
|
||||
* @param object $employee
|
||||
* @return null|object
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function execute(string $voucherCode, ?float $amount, ?object $employee)
|
||||
{
|
||||
try {
|
||||
if($amount){
|
||||
$result = $this->voucherifyClient->validations->validateVoucher($voucherCode, [
|
||||
"customer" => [
|
||||
// "id" => $employee->id,
|
||||
"name" => $employee->name,
|
||||
"email" => $employee->email,
|
||||
],
|
||||
"order" => [
|
||||
"amount" => $amount * 100 //converting it to cents
|
||||
]
|
||||
]);
|
||||
}
|
||||
else{
|
||||
$res = $this->voucherifyClient->validations->validateVoucher($voucherCode);
|
||||
$result = [
|
||||
"valid" => $res->valid,
|
||||
"code" => $res->code
|
||||
];
|
||||
if (isset($res->reason)) {
|
||||
$result["reason"] = $res->reason;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
// throw $e;
|
||||
Log::error('ValidatesVoucher error:' . $e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyCustomerObject;
|
||||
|
||||
class CreatesVoucherifyCustomer
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* CreatesVoucherifyCustomer constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CreateVoucherifyCustomerObject $object
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(CreateVoucherifyCustomerObject $object)
|
||||
{
|
||||
try {
|
||||
|
||||
$customerObj = [
|
||||
"source_id" => $object->getUser()->id,
|
||||
"name" => $object->getUser()->name,
|
||||
"email" => $object->getUser()->email,
|
||||
"address" => [
|
||||
"city" => '',
|
||||
"country" => '',
|
||||
"line_1" => '',
|
||||
"line_2" => '',
|
||||
"postal_code" => '',
|
||||
"state" => '',
|
||||
],
|
||||
];
|
||||
|
||||
if ($object->getIsNew()) {
|
||||
$customerObj['metadata']["new_customer"] = date('Y-m-d H:i:s');
|
||||
}
|
||||
if ($object->getCompanyId()) {
|
||||
$customerObj['metadata']["exchange_company_id"] = $object->getCompanyId();
|
||||
$customerObj['metadata']["exchange_user_id"] = $object->getUser()->id;
|
||||
}
|
||||
if ($object->getAcquisitionChannel()) {
|
||||
$customerObj['metadata']["acquisition"] = $object->getAcquisitionChannel();
|
||||
}
|
||||
|
||||
$result = $this->voucherifyClient->customers->create($customerObj);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
// throw $e;
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyOrderObject;
|
||||
|
||||
class CreatesVoucherifyOrder
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* CreatesVoucherifyOrder constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CreateVoucherifyOrderObject $obj
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(CreateVoucherifyOrderObject $obj)
|
||||
{
|
||||
try {
|
||||
$orderObj = [
|
||||
"customer" => [
|
||||
"source_id" => $obj->getEmployee()->id,
|
||||
"name" => $obj->getEmployee()->name,
|
||||
"email" => $obj->getEmployee()->email,
|
||||
"metadata" => [
|
||||
"exchange_company_id" => $obj->getCompanyId(),
|
||||
"exchange_user_id" => $obj->getEmployee()->id
|
||||
]
|
||||
],
|
||||
"amount" => $obj->getAmount() * 100, //converting it to cents
|
||||
];
|
||||
|
||||
if ($obj->getIsNoVoucher()) {
|
||||
$orderObj['metadata']["no_voucher"] = true;
|
||||
}
|
||||
|
||||
if ($obj->getIsTopUpWallet()) {
|
||||
$orderObj['metadata']["is_wallet_top_up"] = true;
|
||||
}
|
||||
|
||||
$result = $this->voucherifyClient->orders->create($orderObj);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CreatesVoucherifyVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* CreatesVoucherifyVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param int $amount
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(User $user, int $amount)
|
||||
{
|
||||
$startDate = Carbon::now();
|
||||
$expirationDate = $startDate->copy()->addMonths(12)->endOfDay();
|
||||
try {
|
||||
$result = $this->voucherifyClient->vouchers->create([
|
||||
"code" => Str::random(10),
|
||||
"type" => "DISCOUNT_VOUCHER",
|
||||
"discount" => [
|
||||
"type" => "AMOUNT",
|
||||
"amount_off" => $amount * 100,
|
||||
],
|
||||
"redemption" => [
|
||||
"quantity" => 1
|
||||
],
|
||||
"metadata" => [
|
||||
"email" => $user->email
|
||||
],
|
||||
"start_date" => $startDate->format('Y-m-d H:i:s'),
|
||||
"expiration_date" => $expirationDate->format('Y-m-d H:i:s')
|
||||
]);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesVoucherifyVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesVoucherifyVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string $voucherifyVoucherCode
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(User $user, string $voucherifyVoucherCode)
|
||||
{
|
||||
try {
|
||||
$result = $this->voucherifyClient->vouchers->get($voucherifyVoucherCode);
|
||||
|
||||
if (isset($result->metadata) && isset($result->metadata->email)) {
|
||||
if($user->email != $result->metadata->email){
|
||||
$result->reason = 'Invalid Code';
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\RedeemVoucherifyVoucherObject;
|
||||
|
||||
class RedeemsVoucherifyVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* RedeemsVoucherifyVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RedeemVoucherifyVoucherObject $redeemVoucherifyVoucherObject
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(RedeemVoucherifyVoucherObject $redeemVoucherifyVoucherObject)
|
||||
{
|
||||
try {
|
||||
$result = $this->voucherifyClient->redemptions->redeem($redeemVoucherifyVoucherObject->getPromoCode(), [
|
||||
"customer" => [
|
||||
"source_id" => $redeemVoucherifyVoucherObject->getEmployee()->id,
|
||||
"name" => $redeemVoucherifyVoucherObject->getEmployee()->name,
|
||||
"email" => $redeemVoucherifyVoucherObject->getEmployee()->email,
|
||||
"metadata" => [
|
||||
"exchange_company_id" => $redeemVoucherifyVoucherObject->getCompanyId(),
|
||||
"exchange_user_id" => $redeemVoucherifyVoucherObject->getEmployee()->id
|
||||
]
|
||||
],
|
||||
"order" => [
|
||||
"amount" => $redeemVoucherifyVoucherObject->getAmount() * 100 //converting it to cents
|
||||
]
|
||||
]);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\UpdateVoucherifyOrderObject;
|
||||
|
||||
class UpdatesVoucherifyOrder
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* UpdatesVoucherifyOrder constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param UpdateVoucherifyOrderObject $obj
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(UpdateVoucherifyOrderObject $obj)
|
||||
{
|
||||
try {
|
||||
$result = $this->voucherifyClient->orders->update([
|
||||
"id" => $obj->getId(),
|
||||
"status" => $obj->getStatus(),
|
||||
]);
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\General\Helper;
|
||||
|
||||
class ValidatesVoucherifyVoucher
|
||||
{
|
||||
|
||||
/** @var VoucherifyClient */
|
||||
private $voucherifyClient;
|
||||
|
||||
|
||||
/**
|
||||
* ValidatesVoucherifyVoucher constructor.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->voucherifyClient = createVoucherifyClient();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ValidateVoucherifyVoucherObject $validateVoucherifyVoucherObject
|
||||
* @return null|object
|
||||
* @throws \Voucherify\ClientException
|
||||
*/
|
||||
public function execute(ValidateVoucherifyVoucherObject $validateVoucherifyVoucherObject)
|
||||
{
|
||||
try {
|
||||
$validateVoucherObj = [
|
||||
"customer" => [
|
||||
"source_id" => $validateVoucherifyVoucherObject->getUser()->id,
|
||||
"name" => $validateVoucherifyVoucherObject->getUser()->name,
|
||||
"email" => $validateVoucherifyVoucherObject->getUser()->email,
|
||||
"metadata" => [
|
||||
"exchange_company_id" => $validateVoucherifyVoucherObject->getCompanyId(),
|
||||
"exchange_user_id" => $validateVoucherifyVoucherObject->getUser()->id
|
||||
]
|
||||
]
|
||||
];
|
||||
if ($validateVoucherifyVoucherObject->getAmount()) {
|
||||
$validateVoucherObj['order'] = [
|
||||
"amount" => $validateVoucherifyVoucherObject->getAmount() * 100 //converting it to cents
|
||||
];
|
||||
}
|
||||
|
||||
$result = $this->voucherifyClient->validations->validateVoucher($validateVoucherifyVoucherObject->getVoucherCode(), $validateVoucherObj);
|
||||
|
||||
if (isset($result->metadata) && isset($result->metadata->email)) {
|
||||
if($validateVoucherifyVoucherObject->getUser()->email != $result->metadata->email){
|
||||
$result->reason = 'Invalid Code';
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($result->reason)) {
|
||||
Helper::debugLogger('ValidatesVoucherifyVoucher error: '. $result->reason);
|
||||
$result->reason = 'Invalid Code';
|
||||
}
|
||||
|
||||
return $result;
|
||||
} catch (\Voucherify\ClientException $e) {
|
||||
// throw $e;
|
||||
Log::error($e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -56,6 +57,8 @@ class TopUpWalletLogic extends AbstractControllerLogic
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var BookingToVoucherifyProcessor */
|
||||
private $bookingToVoucherifyProcessor;
|
||||
|
||||
/**
|
||||
* TopUpWalletLogic constructor.
|
||||
@@ -65,8 +68,9 @@ class TopUpWalletLogic extends AbstractControllerLogic
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesBillplzBill $createsBillplzBill
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param BookingToVoucherifyProcessor $bookingToVoucherifyProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransaction $createsTransaction)
|
||||
public function __construct(FetchesCompany $fetchesCompany, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransaction $createsTransaction, BookingToVoucherifyProcessor $bookingToVoucherifyProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
@@ -74,6 +78,7 @@ class TopUpWalletLogic extends AbstractControllerLogic
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->bookingToVoucherifyProcessor = $bookingToVoucherifyProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,6 +113,8 @@ class TopUpWalletLogic extends AbstractControllerLogic
|
||||
|
||||
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
|
||||
|
||||
$this->bookingToVoucherifyProcessor->execute($company->employees()->first(), $transaction, $company->id, $amount, 0);
|
||||
|
||||
return $this->resourceResponse(new WalletTransactionResource($transaction));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class MilestoneCreationOptions
|
||||
{
|
||||
const OPTIONS_MILESTONE_NAME= [
|
||||
['text' => 'MILESTONE 1', 'id' => Milestones::MILESTONE_1],
|
||||
['text' => 'MILESTONE 2', 'id' => Milestones::MILESTONE_2],
|
||||
['text' => 'MILESTONE 3', 'id' => Milestones::MILESTONE_3],
|
||||
// ['text' => 'MILESTONE 4', 'id' => Milestones::MILESTONE_4],
|
||||
// ['text' => 'MILESTONE 5', 'id' => Milestones::MILESTONE_5],
|
||||
// ['text' => 'MILESTONE 6', 'id' => Milestones::MILESTONE_6],
|
||||
// ['text' => 'MILESTONE 7', 'id' => Milestones::MILESTONE_7],
|
||||
// ['text' => 'MILESTONE 8', 'id' => Milestones::MILESTONE_8],
|
||||
// ['text' => 'MILESTONE 9', 'id' => Milestones::MILESTONE_9],
|
||||
// ['text' => 'MILESTONE 10', 'id' => Milestones::MILESTONE_10],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class Milestones
|
||||
{
|
||||
public const MILESTONE_1 = 'MILESTONE 1'; //Authentication (Sign in) or CreateCustomerLogic (Sign up)
|
||||
public const MILESTONE_2 = 'MILESTONE 2'; //Create Identification Document
|
||||
public const MILESTONE_3 = 'MILESTONE 3'; //Assign Company to Segment Logic -segment.assign when accept 1688
|
||||
// public const MILESTONE_4 = 'MILESTONE 4'; //Create Bank Logic (Transfer Now from dashboard)
|
||||
// public const MILESTONE_5 = 'MILESTONE 5'; //Create Booking Logic
|
||||
// public const MILESTONE_6 = 'MILESTONE 6'; //Create Address Logic (At transfer page before create booking)
|
||||
// public const MILESTONE_7 = 'MILESTONE 7';
|
||||
// public const MILESTONE_8 = 'MILESTONE 8';
|
||||
// public const MILESTONE_9 = 'MILESTONE 9';
|
||||
// public const MILESTONE_10 = 'MILESTONE 10';
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class RewardCreationOptions
|
||||
{
|
||||
const OPTIONS_IS_ACTIVE = [
|
||||
['text' => 'No', 'id' => 0],
|
||||
['text' => 'Yes', 'id' => 1],
|
||||
];
|
||||
|
||||
const OPTIONS_TYPE = [
|
||||
['text' => 'User Specific', 'id' => RewardType::REWARD_INDIVIDUAL],
|
||||
['text' => 'Amount', 'id' => RewardType::REWARD_AMOUNT],
|
||||
['text' => 'Code', 'id' => RewardType::REWARD_CODE],
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
class RewardType
|
||||
{
|
||||
public const REWARD_INDIVIDUAL = 1;
|
||||
public const REWARD_AMOUNT = 2;
|
||||
public const REWARD_CODE = 3;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\ValueObjects\Constants;
|
||||
|
||||
final class VoucherifyEntityType {
|
||||
|
||||
public const ORDER = 'order';
|
||||
|
||||
public const CUSTOMER = 'customer';
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Milestones;
|
||||
|
||||
use App\Classes\Modules\Milestones\ControllersLogic\CreateMilestoneLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateMilestoneController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param CreateMilestoneLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function create(Request $request, CreateMilestoneLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Milestones;
|
||||
|
||||
use App\Classes\Modules\Milestones\ControllersLogic\DeleteMilestoneLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteMilestoneController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param DeleteMilestoneLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function delete(Request $request, DeleteMilestoneLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Milestones;
|
||||
|
||||
use App\Classes\Modules\Milestones\ControllersLogic\ListMilestoneProgressLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListMilestoneProgressController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListMilestoneProgressLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function list(Request $request, ListMilestoneProgressLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Milestones;
|
||||
|
||||
use App\Classes\Modules\Milestones\ControllersLogic\ListMilestonesLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListMilestonesController
|
||||
{
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param ListMilestonesLogic $logic
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function list(Request $request, ListMilestonesLogic $logic): JsonResponse {
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user