mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Merge branch 'dillon/63.2-sorry-voucher' into 'master'
Sorry Voucher Implementation See merge request CIEFWorldwideSdnBhd/exchange-2.0!166
This commit is contained in:
@@ -10,7 +10,7 @@ use App\Classes\General\Interfaces\DataTransferObject;
|
||||
abstract class AbstractRule
|
||||
{
|
||||
|
||||
abstract protected function authorized(): bool;
|
||||
abstract protected function authorized($object): bool;
|
||||
|
||||
abstract protected function validators($object): bool;
|
||||
|
||||
@@ -26,7 +26,7 @@ abstract class AbstractRule
|
||||
*/
|
||||
public function passes(?DataTransferObject $object = null): bool {
|
||||
try {
|
||||
if(!$this->authorized()){
|
||||
if(!$this->authorized($object)){
|
||||
throw new AccessForbiddenException('You don\'t have permission to perform this action');
|
||||
}
|
||||
|
||||
@@ -43,4 +43,4 @@ abstract class AbstractRule
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Models\JobResult;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ListDocumentsJob implements ShouldQueue
|
||||
{
|
||||
@@ -43,18 +42,7 @@ class ListDocumentsJob implements ShouldQueue
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListDocumentsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
|
||||
//cief todo: Insert into DB: job id, query result, timestamp
|
||||
// Store the result in the job_results table
|
||||
|
||||
//cief todo: why cannot save data in table like this
|
||||
// $model = new JobResult();
|
||||
// $model->job_id = $this->job->getJobId();
|
||||
// $model->result = json_encode($result);
|
||||
// $model->save();
|
||||
|
||||
// Log::error(json_encode($model->id));
|
||||
(App()->make(ListDocumentsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
|
||||
public function getJobId(){
|
||||
|
||||
@@ -16,6 +16,7 @@ use App\Classes\Modules\Vouchers\Processors\Voucherify\NewCustomerToVoucherifyPr
|
||||
use App\Classes\Modules\Vouchers\Processors\CreateVoucherProcessor;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\EmploymentObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateLeadPerfexCRMObject;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\BusinessType;
|
||||
use App\Classes\ValueObjects\Constants\CompanyType;
|
||||
@@ -78,6 +79,9 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
/** @var CreateVoucherProcessor */
|
||||
private $createVoucherProcessor;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/**
|
||||
* CreateCustomerLogic constructor.
|
||||
* @param CreateUserProcessor $createUserProcessor
|
||||
@@ -91,9 +95,10 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
* @param CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor
|
||||
* @param NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor
|
||||
* @param CreateVoucherProcessor $createVoucherProcessor
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
*/
|
||||
public function __construct(CreateUserProcessor $createUserProcessor, CreateCompanyProcessor $createCompanyProcessor, CreateContactProcessor $createContactProcessor, AssignEmployeeProcessor $assignEmployeeProcessor, AssignSegmentProcessor $assignSegmentProcessor, AuthenticationProcessor $authenticationProcessor, GenerateEmailVerificationAttemptProcessor $generateEmailVerificationAttemptProcessor,
|
||||
CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor, CreateVoucherProcessor $createVoucherProcessor)
|
||||
CreatesSeasonalSegment $createsSeasonalSegment, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, NewCustomerToVoucherifyProcessor $newCustomerToVoucherifyProcessor, CreateVoucherProcessor $createVoucherProcessor, CreatesUserReward $createsUserReward)
|
||||
{
|
||||
$this->createUserProcessor = $createUserProcessor;
|
||||
$this->createCompanyProcessor = $createCompanyProcessor;
|
||||
@@ -106,6 +111,7 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
|
||||
$this->newCustomerToVoucherifyProcessor = $newCustomerToVoucherifyProcessor;
|
||||
$this->createVoucherProcessor = $createVoucherProcessor;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,7 +166,13 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
|
||||
$this->newCustomerToVoucherifyProcessor->execute($company->id, $user, true);
|
||||
|
||||
$this->createVoucherProcessor->execute($user, Vouchers::WELCOME_50_PERCENT_OFF);
|
||||
$voucher = $this->createVoucherProcessor->execute($user, Vouchers::WELCOME_50_PERCENT_OFF);
|
||||
if($voucher){
|
||||
$voucherCount = $user->rewards->where('voucher_id', $voucher->id)->count();
|
||||
if($voucherCount === 0){
|
||||
$this->createsUserReward->execute(null, $user, $voucher->id);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request, false));
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounts\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\KeyValuePair;
|
||||
|
||||
class UpdatesKeyValuePair extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param KeyValuePair $model
|
||||
* @param KeyValuePairObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(KeyValuePair $model, KeyValuePairObject $object) {
|
||||
$model->key = $object->getKey();
|
||||
$model->value = $object->getValue();
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanFetchUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListUsers extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanRegisterUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanResendEmailVerification extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class CanResetPassword extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanDeleteAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListAddresses extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanAssignSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanListAnnouncements extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanListBanks extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Models\Company;
|
||||
use App\Models\Currency;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchesBookingQuotation
|
||||
{
|
||||
@@ -62,6 +63,15 @@ class FetchesBookingQuotation
|
||||
$employee = $company->employees()->first();
|
||||
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
|
||||
|
||||
// //A minimum charge of RM5 applies when voucher used make price to be paid by customer RM0
|
||||
// if(isset($result->order->total_amount) && $result->order->total_amount === 0){
|
||||
// // $result->order->cief_original_total_amount = $result->order->total_amount;
|
||||
// $result->order->total_amount = 500;
|
||||
// $result->order->total_discount_amount = $result->order->total_discount_amount - $result->order->total_amount;
|
||||
// Log::info('FetchesBookingQuotation order total_amount RM0 (voucher applied) for company id ' . $company->id. ' with original amount ' . $calculationObject->getSubTotal());
|
||||
// }
|
||||
|
||||
$voucher = [
|
||||
"code" => $result->code,
|
||||
"discount" => property_exists($result, 'discount') ? $result->discount : null,
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanListBookings extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -33,7 +33,7 @@ class CanMergeBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateBooking extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanAssignEmployee extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanAssignSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateIdentificationDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanDeleteCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListCompanies extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanUpdateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateContact extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -24,7 +24,7 @@ class CanCreateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanDeleteCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanFetchCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!Auth::user()->can('add currency_rate')) {
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanListRates extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanApproveDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateFile extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -12,7 +12,7 @@ class CanDeleteDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListDocuments extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanRenderDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanUpdateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanUpdateDocumentReference extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -149,7 +149,7 @@ class CheckMilestonesForRewardProcessor
|
||||
$voucherEndDate = $result->expiration_date;
|
||||
|
||||
//create voucher
|
||||
$voucherObject = new VoucherObject($result->code, isset($voucherName) ? $voucherName : "", $voucherType, $voucherValue, $voucherStartDate, $voucherEndDate);
|
||||
$voucherObject = new VoucherObject($result->code, isset($voucherName) ? $voucherName : "", $voucherType, $voucherValue, null, $voucherStartDate, $voucherEndDate);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
|
||||
$voucherId = $voucher->id;
|
||||
|
||||
@@ -27,7 +27,7 @@ class CanAssignReward extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('edit milestone')) {
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateMilestone extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('add milestone')) {
|
||||
return false;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteMilestone extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('delete milestone')) {
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanUpdateMilestone extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('edit milestone')) {
|
||||
return false;
|
||||
|
||||
@@ -23,7 +23,7 @@ class CanCreateReceipt extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@ class CanCreateReceiptDetail extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateRemark extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanDeleteRemark extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchRemark extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListRemarks extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateRemark extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateReward extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('add reward')) {
|
||||
return false;
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteReward extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if (!Auth::user()->can('delete reward')) {
|
||||
return false;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateConstant extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -25,7 +25,7 @@ class CanCreateSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!Auth::user()->can('add segment')) {
|
||||
|
||||
@@ -11,7 +11,7 @@ class CanDeleteSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -10,7 +10,7 @@ class CanListSegments extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateConstant extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -27,7 +27,7 @@ class CanUpdateSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanCreateServiceType extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanDeleteServiceType extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchServiceType extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanListServiceTypes extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateServiceType extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@ class CanCreateTransaction extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -23,7 +23,7 @@ class CanCreateTransactionDetail extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -6,9 +6,31 @@ 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\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyVoucherInACampaign;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\ListsVoucherifyVouchers;
|
||||
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyCampaign;
|
||||
use App\Classes\Modules\Vouchers\Services\CreatesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
|
||||
use App\Classes\Modules\Vouchers\Services\UpdatesVoucherCampaign;
|
||||
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Classes\Modules\Accounts\Services\UpdatesKeyValuePair;
|
||||
use App\Classes\Modules\Vouchers\Standards\Rules\CanCreateVoucher;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherObject;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherCampaignObject;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\Vouchers;
|
||||
use App\Models\User;
|
||||
use App\Models\VoucherCampaign;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class CreateVoucherLogic extends AbstractControllerLogic
|
||||
@@ -23,16 +45,61 @@ class CreateVoucherLogic extends AbstractControllerLogic
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ValidatesVoucherifyVoucher */
|
||||
private $validatesVoucherifyVoucher;
|
||||
|
||||
/** @var CreatesVoucherifyVoucherInACampaign */
|
||||
private $createsVoucherifyVoucherInACampaign;
|
||||
|
||||
/** @var ListsVoucherifyVouchers */
|
||||
private $listsVoucherifyVouchers;
|
||||
|
||||
/** @var FetchesVoucherifyCampaign */
|
||||
private $fetchesVoucherifyCampaign;
|
||||
|
||||
/** @var CreatesUserReward */
|
||||
private $createsUserReward;
|
||||
|
||||
/** @var CreateVoucherProcessor */
|
||||
private $createVoucherProcessor;
|
||||
|
||||
/** @var CanCreateVoucher */
|
||||
private $canCreateVoucher;
|
||||
|
||||
/** @var CreatesKeyValuePair */
|
||||
private $createsKeyValuePair;
|
||||
|
||||
/** @var UpdatesKeyValuePair */
|
||||
private $updatesKeyValuePair;
|
||||
|
||||
/** @var UpdatesVoucherCampaign */
|
||||
private $updatesVoucherCampaign;
|
||||
|
||||
/**
|
||||
* CreateVoucherLogic constructor.
|
||||
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
|
||||
* @param CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign
|
||||
* @param ListsVoucherifyVouchers $listsVoucherifyVouchers
|
||||
* @param FetchesVoucherifyCampaign $fetchesVoucherifyCampaign
|
||||
* @param CreatesUserReward $createsUserReward
|
||||
* @param CreateVoucherProcessor $createVoucherProcessor
|
||||
* @param CanCreateVoucher $canCreateVoucher
|
||||
* @param CreatesKeyValuePair $createsKeyValuePair
|
||||
* @param UpdatesKeyValuePair $updatesKeyValuePair
|
||||
* @param UpdatesVoucherCampaign $updatesVoucherCampaign
|
||||
*/
|
||||
public function __construct(CreateVoucherProcessor $createVoucherProcessor)
|
||||
public function __construct(CreatesUserReward $createsUserReward, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, CreateVoucherProcessor $createVoucherProcessor, CreatesVoucherifyVoucherInACampaign $createsVoucherifyVoucherInACampaign, CanCreateVoucher $canCreateVoucher, ListsVoucherifyVouchers $listsVoucherifyVouchers, FetchesVoucherifyCampaign $fetchesVoucherifyCampaign, CreatesKeyValuePair $createsKeyValuePair, UpdatesKeyValuePair $updatesKeyValuePair, UpdatesVoucherCampaign $updatesVoucherCampaign)
|
||||
{
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
$this->createVoucherProcessor = $createVoucherProcessor;
|
||||
$this->createsVoucherifyVoucherInACampaign = $createsVoucherifyVoucherInACampaign;
|
||||
$this->canCreateVoucher = $canCreateVoucher;
|
||||
$this->listsVoucherifyVouchers = $listsVoucherifyVouchers;
|
||||
$this->fetchesVoucherifyCampaign = $fetchesVoucherifyCampaign;
|
||||
$this->createsKeyValuePair = $createsKeyValuePair;
|
||||
$this->updatesKeyValuePair = $updatesKeyValuePair;
|
||||
$this->updatesVoucherCampaign = $updatesVoucherCampaign;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,8 +109,125 @@ class CreateVoucherLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$user = User::where('id', $request->input('userId'))->first();
|
||||
$result = $this->createVoucherProcessor->execute($user, $request->input('voucherCode'), null);
|
||||
//Process request input
|
||||
$userParam = User::where('id', $request->input('userId'))->first();
|
||||
$voucherCodeInput = $request->input('voucherCode');
|
||||
$userRewardObject = new CreateVoucherObject(
|
||||
$voucherCodeInput,
|
||||
$userParam,
|
||||
);
|
||||
$this->canCreateVoucher->passes($userRewardObject);
|
||||
|
||||
//Initialize variables
|
||||
$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 - creates new voucher at voucherify
|
||||
if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 ) {
|
||||
$result = $this->newVoucherifyVoucherIssuanceHandler($voucherCodeInput);
|
||||
}
|
||||
else //Voucherify - validates existing voucher at voucherify
|
||||
{
|
||||
$result = $this->existingVoucherValidationHandler($voucherCodeInput, $user);
|
||||
}
|
||||
|
||||
//Save validated voucher info to local DB
|
||||
if(!isset($result['reason'] ) && $result['validatedVoucherCode']){
|
||||
$voucher = $this->createVoucherProcessor->execute($user, $result['validatedVoucherCode'], $result['voucherCampaignId'] ?? null);
|
||||
$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';
|
||||
}
|
||||
}
|
||||
|
||||
//Unset property that is set for internal processing
|
||||
unset($result['validatedVoucherCode']);
|
||||
unset($result['voucherCampaignId']);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
private function newVoucherifyVoucherIssuanceHandler($voucherCodeInput){
|
||||
$result = [];
|
||||
$total = 0;
|
||||
$limit = 0;
|
||||
$voucherCampaign = VoucherCampaign::where('slug', strtolower($voucherCodeInput))->first();
|
||||
|
||||
if($voucherCampaign){
|
||||
$result['voucherCampaignId'] = $voucherCampaign->id;
|
||||
$voucherList = $this->listsVoucherifyVouchers->execute($voucherCampaign->campaign_id); //Remote Voucherify
|
||||
if (isset($voucherList->vouchers) && isset($voucherList->total)) {
|
||||
$total = $voucherList->total;
|
||||
}
|
||||
$voucherifyCampaign = $this->fetchesVoucherifyCampaign->execute($voucherCampaign->campaign_id); //Remote Voucherify
|
||||
|
||||
$campaignName = $voucherifyCampaign->name;
|
||||
$campaignId = $voucherifyCampaign->id;
|
||||
$campaignMetadata = $voucherifyCampaign->metadata;
|
||||
|
||||
if(isset($campaignMetadata) && isset($campaignMetadata['voucher_limit_per_month'])){
|
||||
$limit = (int) $campaignMetadata['voucher_limit_per_month'];
|
||||
}
|
||||
|
||||
$voucherCampaignObject= new VoucherCampaignObject($campaignId, $campaignName, null, $limit);
|
||||
$this->updatesVoucherCampaign->execute($voucherCampaign, $voucherCampaignObject);
|
||||
|
||||
if($total >= $voucherCampaign['limit_per_month']){
|
||||
$result['reason'] = 'Quota for the month exceeded';
|
||||
}
|
||||
else{
|
||||
//To track voucher issuance by admin
|
||||
$total = $voucherList->total + 1;
|
||||
$key = strtoupper($campaignId)."_".strtoupper(Carbon::now()->format('M'))."_TOTAL";
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
$key,
|
||||
$total
|
||||
);
|
||||
$metadata = $voucherCampaign->attributes()->where('key', $key)->first();
|
||||
if($metadata){
|
||||
$this->updatesKeyValuePair->execute($metadata, $keyValuePairObject);
|
||||
}
|
||||
else{
|
||||
$this->createsKeyValuePair->execute($voucherCampaign, $keyValuePairObject);
|
||||
}
|
||||
|
||||
$createdVoucher = $this->createsVoucherifyVoucherInACampaign->execute($campaignName, ""); //Remote Voucherify
|
||||
if(isset($createdVoucher->message)){
|
||||
$result['reason'] = $createdVoucher->message;
|
||||
}
|
||||
else{
|
||||
$result['validatedVoucherCode'] = $createdVoucher->code;
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result['reason'] = 'Campaign not set';
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function existingVoucherValidationHandler(string $voucherCodeInput, User $user){
|
||||
$result = [];
|
||||
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $voucherCodeInput, 0.00, $user);
|
||||
$voucherifyVoucherValidated = $this->validatesVoucherifyVoucher->execute($ValidateVoucherifyVoucherObject); //Remote Voucherify
|
||||
|
||||
if(isset($voucherifyVoucherValidated->reason)){
|
||||
$result['reason'] = $voucherifyVoucherValidated->reason;
|
||||
}
|
||||
else if($voucherifyVoucherValidated){
|
||||
$result['validatedVoucherCode'] = $voucherCodeInput;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Vouchers\Services\ListsVoucherCampaigns;
|
||||
use App\Classes\Modules\Vouchers\Standards\Rules\CanListVoucherCampaigns;
|
||||
use App\Http\Resources\VoucherCampaignResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListVoucherCampaignsLogic extends AbstractControllerLogic
|
||||
{
|
||||
/** @var ListsVoucherCampaigns */
|
||||
private $listsVoucherCampaigns;
|
||||
|
||||
/** @var CanListVoucherCampaigns */
|
||||
private $canListVoucherCampaigns;
|
||||
|
||||
/**
|
||||
* ListVoucherCampaignsLogic constructor.
|
||||
* @param ListsVoucherCampaigns $listsVoucherCampaigns
|
||||
* @param CanListVoucherCampaigns $canListVoucherCampaigns
|
||||
*/
|
||||
public function __construct(ListsVoucherCampaigns $listsVoucherCampaigns, CanListVoucherCampaigns $canListVoucherCampaigns)
|
||||
{
|
||||
$this->listsVoucherCampaigns = $listsVoucherCampaigns;
|
||||
$this->canListVoucherCampaigns = $canListVoucherCampaigns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Voucher Campaigns',
|
||||
'message' => 'You have successfully retrieved a list of voucher campaigns'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canListVoucherCampaigns->passes();
|
||||
|
||||
$query = $this->listsVoucherCampaigns->execute($this->listsVoucherCampaigns->deserializeFilters($request->input('filters')));
|
||||
|
||||
$filters = json_decode($request->input('filters'), true);
|
||||
if(isset($filters['include_metadata'])){
|
||||
$request->merge(['include_metadata' => true]);
|
||||
}
|
||||
|
||||
return $this->collectionResponse(VoucherCampaignResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\User;
|
||||
|
||||
class CreateVoucherObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $voucherCode;
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* CreateVoucherObject constructor.
|
||||
* @param string $voucherCode
|
||||
* @param null|User $user
|
||||
*/
|
||||
public function __construct(string $voucherCode, ?User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->voucherCode = $voucherCode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getVoucherCode(): string
|
||||
{
|
||||
return $this->voucherCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|User
|
||||
*/
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class VoucherCampaignObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $campaign_id;
|
||||
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var string|null */
|
||||
private $description;
|
||||
|
||||
/** @var int */
|
||||
private $limitPerMonth;
|
||||
|
||||
/**
|
||||
* VoucherCampaignObject constructor.
|
||||
* @param string $campaign_id
|
||||
* @param string $name
|
||||
* @param null|string $description
|
||||
* @param int $limitPerMonth
|
||||
*/
|
||||
public function __construct(string $campaign_id, string $name, ?string $description, int $limitPerMonth)
|
||||
{
|
||||
$this->campaign_id = $campaign_id;
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$this->limitPerMonth = $limitPerMonth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCampaignId(): string
|
||||
{
|
||||
return $this->campaign_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getLimitPerMonth(): int
|
||||
{
|
||||
return $this->limitPerMonth;
|
||||
}
|
||||
}
|
||||
@@ -27,21 +27,26 @@ class VoucherObject implements DataTransferObject
|
||||
/** @var string|null */
|
||||
private $endDate;
|
||||
|
||||
/** @var int */
|
||||
private $voucherCampaignId;
|
||||
|
||||
/**
|
||||
* VoucherObject constructor.
|
||||
* @param string $code
|
||||
* @param string $name
|
||||
* @param string $type
|
||||
* @param float $value
|
||||
* @param int $voucherCampaignId
|
||||
* @param string $startDate
|
||||
* @param string $endDate
|
||||
*/
|
||||
public function __construct(string $code, ?string $name, ?string $type, ?float $value, ?string $startDate = '', ?string $endDate = '')
|
||||
public function __construct(string $code, ?string $name, ?string $type, ?float $value, ?int $voucherCampaignId, ?string $startDate = '', ?string $endDate = '')
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
$this->value = $value;
|
||||
$this->voucherCampaignId = $voucherCampaignId;
|
||||
$this->startDate = $startDate;
|
||||
$this->endDate = $endDate;
|
||||
}
|
||||
@@ -62,7 +67,6 @@ class VoucherObject implements DataTransferObject
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
@@ -71,7 +75,6 @@ class VoucherObject implements DataTransferObject
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
@@ -80,6 +83,14 @@ class VoucherObject implements DataTransferObject
|
||||
return $this->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getVoucherCampaignId(): ?int
|
||||
{
|
||||
return $this->voucherCampaignId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
|
||||
@@ -4,110 +4,76 @@ 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 Carbon\Carbon;
|
||||
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)
|
||||
public function __construct(FetchesVoucherifyVoucher $fetchesVoucherifyVoucher, CreatesVoucher $createsVoucher, FetchesVoucher $fetchesVoucher)
|
||||
{
|
||||
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
|
||||
$this->createsVoucher = $createsVoucher;
|
||||
$this->createsUserReward = $createsUserReward;
|
||||
$this->fetchesVoucher = $fetchesVoucher;
|
||||
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ?User $userParam
|
||||
* @param null|User $user
|
||||
* @param string $voucherCodeInput
|
||||
* @return array
|
||||
* @param null|int $campaignId
|
||||
* @return mixed
|
||||
* @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
|
||||
public function execute(?User $user, string $voucherCodeInput, ?int $campaignId = null) {
|
||||
//Remotely - Get Voucher Voucherify
|
||||
$voucherifyVoucherFetched = $this->fetchesVoucherifyVoucher->execute($user, $voucherCodeInput);
|
||||
|
||||
$voucherName = $voucherifyVoucherFetched->campaign;
|
||||
//Voucher stored locally need a name, by default use campaign name, else look into campaign metadata for displayname
|
||||
if(isset($voucherifyVoucherFetched->metadata) && isset($voucherifyVoucherFetched->metadata->displayname)){
|
||||
$voucherName = $voucherifyVoucherFetched->metadata->displayname;
|
||||
}
|
||||
else{
|
||||
$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);
|
||||
//Locally - Create and Fetch Voucher
|
||||
$voucherObject = new VoucherObject(
|
||||
$voucherCode,
|
||||
isset($voucherName) ? $voucherName : "Voucher ".Carbon::now()->format('Ymd'),
|
||||
$voucherType,
|
||||
$voucherValue,
|
||||
$campaignId,
|
||||
$voucherStartDate,
|
||||
$voucherEndDate);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherCodeInput]);
|
||||
return $voucher;
|
||||
}
|
||||
|
||||
@@ -84,6 +84,9 @@ class BookingToVoucherifyProcessor
|
||||
if($voucherCode){
|
||||
$redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $transaction->id, $voucherCode, $amount, $user);
|
||||
$redeemVoucherResult = $this->redeemsVoucherifyVoucher->execute($redeemVoucherifyVoucherObject);
|
||||
|
||||
// Log::info('redeemVoucherResult: '.json_encode($redeemVoucherResult));
|
||||
|
||||
$redeemedVoucher = $redeemVoucherResult->voucher;
|
||||
$redemptionId = $redeemVoucherResult->id;
|
||||
|
||||
@@ -123,8 +126,9 @@ class BookingToVoucherifyProcessor
|
||||
//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;
|
||||
$voucherCampaignId = isset($redeemedVoucher->campaign_id) ? $redeemedVoucher->campaign_id : null;
|
||||
|
||||
$voucherObject= new VoucherObject($redeemedVoucher->code, isset($redeemedVoucher->metadata->name) ? $redeemedVoucher->metadata->name : "", $voucherType, $voucherValue);
|
||||
$voucherObject= new VoucherObject($redeemedVoucher->code, isset($redeemedVoucher->metadata->name) ? $redeemedVoucher->metadata->name : "", $voucherType, $voucherValue, $voucherCampaignId);
|
||||
$voucher = $this->createsVoucher->execute($voucherObject);
|
||||
if(!$voucher) $voucher = $this->fetchesVoucher->execute(['code' => $voucherObject->getCode()]);
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
use App\Models\VoucherCampaign;
|
||||
|
||||
class CheckIfVoucherCampaignExists
|
||||
{
|
||||
|
||||
/** @var VoucherCampaign */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* CheckIfVoucherCampaignExists constructor.
|
||||
* @param VoucherCampaign $repository
|
||||
*/
|
||||
public function __construct(VoucherCampaign $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function execute(string $campaignId): bool {
|
||||
return $this->repository->where('campaign_id', $campaignId)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ class CreatesVoucher extends AbstractUpdateRecord
|
||||
|
||||
/**
|
||||
* @param VoucherObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(VoucherObject $object) {
|
||||
@@ -33,6 +33,7 @@ class CreatesVoucher extends AbstractUpdateRecord
|
||||
$model->name = $object->getName();
|
||||
$model->type = $object->getType();
|
||||
$model->value = $object->getValue();
|
||||
$model->voucher_campaign_id = $object->getVoucherCampaignId();
|
||||
$model->start_date = $object->getStartDate();
|
||||
$model->end_date = $object->getEndDate();
|
||||
return $this->handler($model);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Vouchers\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherCampaignObject;
|
||||
use App\Models\VoucherCampaign;
|
||||
|
||||
class CreatesVoucherCampaign extends AbstractUpdateRecord
|
||||
{
|
||||
/** @var CheckIfVoucherCampaignExists */
|
||||
private $campaignExists;
|
||||
|
||||
/**
|
||||
* CreatesVoucherCampaign constructor.
|
||||
* @param CheckIfVoucherCampaignExists $campaignExists
|
||||
*/
|
||||
public function __construct(CheckIfVoucherCampaignExists $campaignExists)
|
||||
{
|
||||
$this->campaignExists = $campaignExists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param VoucherCampaignObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(VoucherCampaignObject $object) {
|
||||
if(!$this->campaignExists->execute($object->getCampaignId()))
|
||||
{
|
||||
$model = new VoucherCampaign();
|
||||
$model->campaign_id = $object->getCampaignId();
|
||||
$model->name = $object->getName();
|
||||
$model->description = $object->getDescription();
|
||||
$model->limit_per_month = $object->getLimitPerMonth();
|
||||
return $this->handler($model);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user