Sorry Voucher with new features enhancement requested by KS

This commit is contained in:
Dillon Ngo
2024-07-23 19:11:36 +08:00
parent c3961d102e
commit 0d60226c44
49 changed files with 1325 additions and 103 deletions
+2 -14
View File
@@ -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(){
@@ -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);
}
}
@@ -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,
@@ -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;
@@ -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;
}
}
@@ -0,0 +1,34 @@
<?php
namespace App\Classes\Modules\Vouchers\Services;
use App\Classes\General\Eloquent\AbstractFetchRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\VoucherCampaign;
class FetchesVoucherCampaign extends AbstractFetchRecord
{
/** @var VoucherCampaign */
private $repository;
/**
* FetchesVoucherCampaign constructor.
* @param VoucherCampaign $repository
*/
public function __construct(VoucherCampaign $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
public function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Vouchers\Services;
use App\Classes\General\Eloquent\AbstractListRecord;
use Illuminate\Database\Eloquent\Builder;
use App\Models\VoucherCampaign;
class ListsVoucherCampaigns extends AbstractListRecord
{
/** @var VoucherCampaign */
private $repository;
/**
* ListsVoucherCampaigns constructor.
* @param VoucherCampaign $repository
*/
public function __construct(VoucherCampaign $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -0,0 +1,26 @@
<?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 UpdatesVoucherCampaign extends AbstractUpdateRecord
{
/**
* @param VoucherCampaign $model
* @param VoucherCampaignObject $object
* @return \Illuminate\Database\Eloquent\Model
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(VoucherCampaign $model, VoucherCampaignObject $object) {
$model->name = $object->getName();
$model->description = $object->getDescription();
$model->limit_per_month = $object->getLimitPerMonth();
return $this->handler($model);
}
}
@@ -59,7 +59,7 @@ class CreatesVoucherifyCustomer
return $result;
} catch (\Voucherify\ClientException $e) {
// throw $e;
Log::error($e);
Log::error('CreatesVoucherifyCustomer '.$e);
return null;
}
}
@@ -55,7 +55,7 @@ class CreatesVoucherifyOrder
$result = $this->voucherifyClient->orders->create($orderObj);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error($e);
Log::error('CreatesVoucherifyOrder '.$e);
return null;
}
}
@@ -52,7 +52,7 @@ class CreatesVoucherifyVoucher
]);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error($e);
Log::error('CreatesVoucherifyVoucher '.$e);
return null;
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
use Illuminate\Support\Facades\Log;
class CreatesVoucherifyVoucherInACampaign
{
/** @var VoucherifyClient */
private $voucherifyClient;
/**
* CreatesVoucherifyVoucherInACampaign constructor.
*
*/
public function __construct()
{
$this->voucherifyClient = createVoucherifyClient();
}
/**
* @param string $campaignName
* @param string $code
* @return null|object
* @throws \Voucherify\ClientException
*/
public function execute(string $campaignName, string $code)
{
try {
$result = $this->voucherifyClient->campaigns->addVoucherWithCode($campaignName, $code);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error('CreatesVoucherifyVoucherInACampaign '.$e);
return null;
}
}
}
@@ -0,0 +1,60 @@
<?php
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
use Illuminate\Support\Facades\Http;
use App\Classes\Exceptions\MalformedRequestException;
use Illuminate\Support\Facades\Log;
class FetchesVoucherifyCampaign
{
/** @var VoucherifyClient */
private $voucherifyClient;
/**
* FetchesVoucherifyCampaign constructor.
*
*/
public function __construct()
{
$this->voucherifyClient = createVoucherifyClient();
}
/**
* @param string $campaignId
* @return null|object
* @throws \Voucherify\ClientException
*/
public function execute(string $campaignId)
{
//REST API - Direct Query
try{
$response = Http::withHeaders([
'X-App-Id' => config('voucherify.application_id'),
'X-App-Token' => config('voucherify.client_secret_key'),
])
->get(config('voucherify.url').'/v1/campaigns/'.$campaignId);
if($response->successful()){
$data = $response->json();
return (object) $data;
}else{
Log::error($response);
return null;
}
}catch(\Exception $exception){
throw new MalformedRequestException('Unable to get correct response from Voucherify: ' . $exception->getMessage());
}
//PHP SDK
// try {
// $result = $this->voucherifyClient->campaigns->get($name); //this is undefined in voucherify php sdk
// return $result;
// } catch (\Voucherify\ClientException $e) {
// Log::error('FetchesVoucherifyCampaign '.$e);
// return null;
// }
}
}
@@ -40,7 +40,7 @@ class FetchesVoucherifyVoucher
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error($e);
Log::error('FetchesVoucherifyVoucher '.$e);
return null;
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
use Illuminate\Support\Facades\Http;
use App\Classes\Exceptions\MalformedRequestException;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class ListsVoucherifyVouchers
{
/** @var VoucherifyClient */
private $voucherifyClient;
/**
* ListsVoucherifyVouchers constructor.
*
*/
public function __construct()
{
$this->voucherifyClient = createVoucherifyClient();
}
/**
* @param string $campaignId
* @return null|object
* @throws \Voucherify\ClientException
*/
public function execute(string $campaignId)
{
//PHP SDK
// try {
// $listVouchers = $this->voucherifyClient->vouchers->getList([
// "campaign" => $campaignName,
// ]);
// if (isset($listVouchers->vouchers) && isset($listVouchers->total) && $listVouchers->total > 0) {
// $campaignId = $listVouchers->vouchers[0]->campaign_id;
// }
// } catch (\Voucherify\ClientException $e) {
// Log::error('ListsVoucherifyVouchers '.$e);
// return null;
// }
//REST API - Direct Query
try{
$dateRange = $this->getDateRangeForMonth(Carbon::now()->year, Carbon::now()->month);
$queryString = http_build_query([
'limit' => 50,
'campaign_id' => $campaignId,
'[created_at][after]' => $dateRange['start'],
'[created_at][before]' => $dateRange['end'],
]);
//$queryString = 'limit=50&campaign_id=' . $campaignId . '&[created_at][after]='. $dateRange['start'] . '&[created_at][before]='. $dateRange['end'];
$response = Http::withHeaders([
'X-App-Id' => config('voucherify.application_id'),
'X-App-Token' => config('voucherify.client_secret_key'),
])
->get(config('voucherify.url').'/v1/vouchers?'.$queryString);
if($response->successful()){
$data = $response->json();
return (object) $data;
}else{
Log::error($response);
return null;
}
}catch(\Exception $exception){
throw new MalformedRequestException('Unable to get correct response from Voucherify: ' . $exception->getMessage());
}
}
private function getDateRangeForMonth($year, $month) {
$startDate = Carbon::createFromFormat('Y-m-d H:i:s', "{$year}-{$month}-01 00:00:00", 'Asia/Kuala_Lumpur')->startOfDay()->setTimezone('UTC');
$endDate = Carbon::createFromFormat('Y-m-d H:i:s', "{$year}-{$month}-01 00:00:00", 'Asia/Kuala_Lumpur')->endOfMonth()->setTimezone('UTC');
return [
'start' => $startDate->toISOString(),
'end' => $endDate->toISOString(), //'2024-07-11T15:59:59.999999Z'
];
}
}
@@ -3,6 +3,7 @@
namespace App\Classes\Modules\Vouchers\Services\Voucherify;
use App\Classes\Modules\Vouchers\DataTransferObjects\RedeemVoucherifyVoucherObject;
use Illuminate\Support\Facades\Log;
class RedeemsVoucherifyVoucher
{
@@ -45,6 +46,7 @@ class RedeemsVoucherifyVoucher
]);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error('RedeemsVoucherifyVoucher '.$e);
throw $e;
}
}
@@ -36,7 +36,7 @@ class UpdatesVoucherifyOrder
]);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error($e);
Log::error('UpdatesVoucherifyOrder '.$e);
return null;
}
}
@@ -41,6 +41,7 @@ class ValidatesVoucherifyVoucher
]
]
];
if ($validateVoucherifyVoucherObject->getAmount()) {
$validateVoucherObj['order'] = [
"amount" => $validateVoucherifyVoucherObject->getAmount() * 100 //converting it to cents
@@ -63,7 +64,7 @@ class ValidatesVoucherifyVoucher
return $result;
} catch (\Voucherify\ClientException $e) {
// throw $e;
Log::error($e);
Log::error('ValidatesVoucherifyVoucher '.$e);
return null;
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Classes\Modules\Vouchers\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Vouchers\Standards\Validators\VoucherValidation;
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherObject;
use Illuminate\Support\Facades\Auth;
use App\Classes\ValueObjects\Constants\Vouchers;
class CanCreateVoucher extends AbstractRule
{
/** @var VoucherValidation */
private $voucherValidation;
/**
* CanCreateVoucher constructor.
* @param VoucherValidation $voucherValidation
*/
public function __construct(VoucherValidation $voucherValidation)
{
$this->voucherValidation = $voucherValidation;
}
/**
* @param CreateVoucherObject $object
* @return bool
*/
protected function authorized($object): bool
{
$isAuthorized = true;
switch ($object->getVoucherCode()) {
case Vouchers::SORRY_50:
case Vouchers::SORRY_100:
case Vouchers::SORRY_200:
$isAuthorized = Auth::user()->can('add voucher');
break;
default:
$isAuthorized = true;
break;
}
return $isAuthorized;
}
/**
* @param CreateVoucherObject $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return true;
}
/**
* @param CreateVoucherObject $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,40 @@
<?php
namespace App\Classes\Modules\Vouchers\Standards\Rules;
use App\Classes\General\Abstracts\AbstractRule;
use Illuminate\Support\Facades\Auth;
class CanListVoucherCampaigns extends AbstractRule
{
/**
* @param $object
* @return bool
*/
protected function authorized($object): bool
{
if (!Auth::user()->can('list voucher campaigns')) {
return false;
}
return true;
}
/**
* @param $object
* @return bool
* @throws \App\Classes\Exceptions\RequestValidationException
*/
protected function validators($object): bool
{
return true;
}
/**
* @param $object
* @return bool
*/
protected function criteria($object): bool
{
return true;
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Classes\Modules\Vouchers\Standards\Validators;
use App\Classes\General\Abstracts\AbstractValidation;
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherObject;
class VoucherValidation extends AbstractValidation
{
/**
* @param CreateVoucherObject $object
* @return array
*/
protected function data($object): array {
$data = [
'user'=> $object->getUser(),
'voucherCode' => $object->getVoucherCode(),
];
return $data;
}
/**
* @param null|string $type
* @return array
*/
protected function rules(): array {
return [
'user' => [
'required',
],
'voucherCode' => [
'required',
]
];
}
/**
* @return array
*/
protected function messages(): array {
return [];
}
}
@@ -5,4 +5,14 @@ namespace App\Classes\ValueObjects\Constants;
final class Vouchers {
public const WELCOME_50_PERCENT_OFF = 'WELCOME50%OFF';
public const SORRY_50 = 'SORRY50';
public const SORRY_100 = 'SORRY100';
public const SORRY_200 = 'SORRY200';
const OPTIONS_SORRY = [
['text' => 'SORRY 50', 'id' => Vouchers::SORRY_50],
['text' => 'SORRY 100', 'id' => Vouchers::SORRY_100],
['text' => 'SORRY 200', 'id' => Vouchers::SORRY_200],
];
}
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Vouchers;
use App\Classes\Modules\Vouchers\ControllersLogic\ListVoucherCampaignsLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListVoucherCampaignsController
{
/**
* @param Request $request
* @param ListVoucherCampaignsLogic $logic
* @return JsonResponse
*/
public function list(Request $request, ListVoucherCampaignsLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class VoucherCampaignResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
$metadata = null;
if ($request->has('include_metadata')) {
$metadata = KeyValueBasicResource::collection($this->attributes);
}
return [
// 'id' => $this->id,
'campaign_id' => $this->campaign_id,
'name' => $this->name,
'description' => $this->description,
'limit_per_month' => $this->limit_per_month,
'metadata' => $metadata
];
}
}
+10 -1
View File
@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -14,6 +15,14 @@ class Voucher extends AbstractModel
*/
public function redemptions(): HasMany
{
return $this->HasMany(VoucherRedemption::class, 'voucher_id', 'id');
return $this->hasMany(VoucherRedemption::class, 'voucher_id', 'id');
}
/**
* @return BelongsTo
*/
public function campaign(): BelongsTo
{
return $this->belongsTo(VoucherCampaign::class, 'voucher_campaign_id');
}
}
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace App\Models;
use App\Classes\General\Interfaces\KeyValueInterface;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
class VoucherCampaign extends AbstractModel implements KeyValueInterface
{
protected $table = 'voucher_campaigns';
/**
* @return HasMany
*/
public function vouchers()
{
return $this->hasMany(Voucher::class, 'voucher_campaign_id');
}
/**
* @return MorphMany
*/
public function attributes(): MorphMany
{
return $this->morphMany(KeyValuePair::class, 'owner');
}
}
@@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateVoucherCampaignsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('voucher_campaigns', function (Blueprint $table) {
$table->id();
$table->string('campaign_id');
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->integer('limit_per_month')->default(0);
$table->boolean('is_display')->default(false);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('voucher_campaigns');
}
}
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddVoucherCampaignIdToVouchersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('vouchers', function (Blueprint $table) {
$table->foreignId('voucher_campaign_id')->nullable()->constrained('voucher_campaigns')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('vouchers', function (Blueprint $table) {
$table->dropForeign(['voucher_campaign_id']);
$table->dropColumn('voucher_campaign_id');
});
}
}
@@ -71,6 +71,8 @@ class AdminUserPermissionsTableSeeder extends Seeder
['name' => 'delete milestone', 'guard_name' => 'web'],
['name' => 'delete reward', 'guard_name' => 'web'],
['name' => 'add voucher', 'guard_name' => 'web'],
['name' => 'list voucher campaigns', 'guard_name' => 'web'],
];
foreach ($permissions as $permission){
@@ -5,11 +5,13 @@
<div class="row text-left no-margin bg-white p-b-10" v-if="!isLoading" v-for="item in vouchers" v-bind:key="item.id" >
<div id="select-option" name="select-option" class="col b-b b-grey p-t-10 p-b-10 pointer p-t-10 p-b-10" @click="selectVoucher(item)">
<div class="row">
<!-- <div class="col">
<p v-if="item.voucher.type == 'AMOUNT'">RM{{ item.voucher.value/100 }} Discount</p>
<p v-if="item.voucher.type == 'PERCENT'">{{ item.voucher.value }}% Discount</p>
<div class="col text-left no-padding">{{ item.voucher.code }}</div>
<div class="col text-right no-padding" v-if="item.voucher.type == 'AMOUNT'">
RM{{ item.voucher.value/100 }} Discount
</div>
<!-- <div class="col text-right no-padding" v-if="item.voucher.type == 'PERCENT'">
{{ item.voucher.value }}% Discount
</div> -->
<span>{{ item.voucher.code }}</span>
</div>
<div class="row">
<span v-if="item.voucher.end_date">
@@ -697,6 +697,7 @@
this.submit(route('api.voucher.validate'), 'post', '', false, false);
}
else{
this.voucherCodeFailedReason = 'Please enter voucher code';
this.voucherValidated = true;
this.voucherIsChecking = false;
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,110 @@
<template>
<div class="row">
<div class="col">
<div class="row">
<div class="col ml-md-3 ml-0 mt-md-0 mt-3 bg-white padding-15">
<div class="row">
<div class="col">
<div class="row m-b-10">
<div class="col">
<div class="font-heading fs-16 all-caps bold m-b-15">Add Sorry Voucher</div>
</div>
</div>
<div class="row">
<div class="col">
<validation-wrapper-component selectable :validator="$v.voucherCode">
<label>Voucher Options</label>
<selectable-hard-coded-component section="rewardisActiveOptions" :selectable-options="options" v-model="voucherCode"></selectable-hard-coded-component >
</validation-wrapper-component>
</div>
</div>
<div class="row m-l-0 m-r-0" style="height: 20px">
<i class="fa fa-spinner fa-spin m-b-5" v-show="$store.getters.isLoading(section) && voucherIsChecking"></i>
<span class="text-danger" v-if="voucherCodeFailedReason">{{ voucherCodeFailedReason }}</span>
<span class="text-success" v-if="voucherCodeFailedReason === '' && voucherFetched">Voucher added</span>
</div>
<div class="row m-t-20">
<div class="col">
<button type="button" class="btn btn-block p-t-10 p-b-10 p-r-35 p-l-35 btn-success b-rad-none" @click="submitForm">Add Voucher</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { required } from "vuelidate/lib/validators";
export default {
props: {
id: {
type: String,
required: true
},
section:{
type: String,
required: true
},
options: {
type: Array,
required: true
},
},
data(){
return {
parameters: {
voucherCode: '',
},
voucherCode: '',
voucherCodeFailedReason: '',
voucherFetched: false,
voucherIsChecking: false,
}
},
validations: {
voucherCode: {
required
},
},
methods: {
successHandler(response){
if(response.payload.data && response.payload.data.voucher_id !== undefined){
this.voucherFetched = true;
this.$store.dispatch('reloadList', {'name': "customerVouchersListSection"});
this.voucherCode = '';
this.$v.$reset();
}
else{
this.voucherFetched = false;
this.voucherCodeFailedReason = 'Voucher Invalid';
if(response.payload.data && response.payload.data.reason){
this.voucherCodeFailedReason = response.payload.data.reason;
}
}
this.$store.dispatch('reloadList', {'name': "voucherCampaignsSection"});
this.voucherIsChecking = false;
},
submitForm(){
this.reset();
this.voucherIsChecking = true;
this.parameters = {
voucherCode: this.voucherCode,
userId: this.id
};
this.submit(this.route('api.voucher.create'), 'post', this.section, false, false);
},
errorHandler(error){
this.voucherCodeFailedReason = 'Some went wrong, please report this to tech';
this.voucherFetched = false;
this.voucherIsChecking = false;
},
reset(){
this.voucherFetched = false;
this.voucherCodeFailedReason = "";
}
}
}
</script>
@@ -75,12 +75,10 @@
}
else{
this.voucherFetched = false;
this.voucherCodeFailedReason = 'Voucher Invalid';
if(response.payload.data && response.payload.data.reason){
this.voucherCodeFailedReason = response.payload.data.reason;
}
else{
this.voucherCodeFailedReason = 'Voucher Invalid';
}
}
this.voucherIsChecking = false;
},
@@ -94,6 +92,7 @@
this.submit(this.route('api.voucher.create'), 'post', this.section, false, false);
},
errorHandler(error){
this.voucherCodeFailedReason = 'Something went wrong, please report this to our customer service';
this.voucherFetched = false;
this.voucherIsChecking = false;
},
@@ -1,6 +1,11 @@
<template>
<div class="row d-none" :class="[{'d-flex': $store.getters.isAdmin}]" v-if="$store.getters.isAdmin" >
<div class="col-md-12 col-lg col-xl">
<div class="row m-b-10">
<div class="col">
<div class="font-heading fs-16 all-caps bold m-b-15">Customer Vouchers</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="row tabsContainer">
@@ -0,0 +1,23 @@
<template>
<div class="row bg-white padding-10 m-b-10 rounded">
<div class="col-2 fs-12">{{data.name}}</div>
<div class="col-1 text-success text-center">{{data.metadata && data.metadata.length > 0 ? data.metadata[0].value : 0 }}</div>
<div class="col-1 text-center">{{data.limit_per_month}}</div>
<div class="col-3 fs-12">{{data.campaign_id}}</div>
</div>
</template>
<script>
import componentHandler from '../../../general/mixins/componentHandler';
export default {
props: {
data: {
required: true,
type: Object
},
},
methods: {
},
mixins: [componentHandler],
}
</script>
@@ -0,0 +1,42 @@
<template>
<div class="row">
<div class="col">
<div class="row m-b-10">
<div class="col">
<div class="font-heading fs-16 all-caps bold m-b-15">Voucher Campaigns ALL CUSTOMERS</div>
</div>
</div>
<div class="row">
<div class="col">
<div class="row padding-10">
<div class="col-2 fs-10">Name</div>
<div class="col-1 fs-10 text-center">Issued (this month)</div>
<div class="col-1 fs-10 text-center">Limit Per Month</div>
<div class="col-3 fs-10">Campaign Id</div>
</div>
<list-component section="voucherCampaignsSection" :endpoint="route('api.voucher.campaigns.list')" :options="options">
<template slot="list" slot-scope="{data}">
<single-voucher-campaign-item-component :data="data"></single-voucher-campaign-item-component>
</template>
</list-component>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
},
data(){
return {
options: {
include_metadata: true,
}
}
},
methods: {
},
}
</script>
@@ -3,11 +3,9 @@
<div class="row">
<div class="col-12 col-md-8 bg-white p-l-25 p-r-25 p-t-15 p-b-15">
<loading-component style="height: 200px; top: 0;" key="1" color="success" v-show="$store.getters.isLoading('rewardProfileSection')"></loading-component>
<div class="row p-b-5 m-b-20 b-b b-grey align-items-center parentContainer">
<div class="row">
<div class="col">
<div class="font-heading all-caps fs-10 hint-text">
Vouchers
</div>
<voucher-campaigns-section-component></voucher-campaigns-section-component>
</div>
</div>
<div class="row">
@@ -22,6 +20,11 @@
<add-voucher-section-component id="{{$id}}" section="addVoucherSection"></add-voucher-section-component>
</div>
</div>
<div class="row">
<div class="col">
<add-voucher-options-section-component id="{{$id}}" section="addSorryVoucherSection" :options="{{ json_encode(\App\Classes\ValueObjects\Constants\Vouchers::OPTIONS_SORRY) }}" ></add-voucher-options-section-component>
</div>
</div>
</div>
</div>
@endsection
+1 -3
View File
@@ -60,7 +60,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
require __DIR__ . '/wallet.php';
require __DIR__ . '/voucher.php';
require __DIR__ . '/accounting.php';
require __DIR__ . '/reward.php';
@@ -69,8 +69,6 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function
require __DIR__.'/remark.php';
// require __DIR__ . '/accounting.php'; //cief todo: To check if this is needed
require __DIR__ . '/job.php';
// require __DIR__ . '/rate.php';
+1
View File
@@ -7,4 +7,5 @@ Route::group(['prefix' => 'voucher', 'as' => 'voucher.', 'namespace' => 'Voucher
Route::post('create', 'CreateVoucherController@create')->name('create');
// Route::post('redeem', 'RedeemVoucherController@redeem')->name('redeem');
Route::get('/user/list', 'ListUserVouchersController@list')->name('user.list');
Route::get('/voucher/camapaigns/list', 'ListVoucherCampaignsController@list')->name('campaigns.list');
});