New voucher CIEFPC30 setup with new business logic - Initial Commit

This commit is contained in:
Dillon Ngo
2024-12-09 05:23:53 +08:00
parent 0824a45b41
commit 0ab5ed76a5
29 changed files with 401 additions and 104 deletions
@@ -4,24 +4,22 @@ namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Banks\Services\FetchesBank;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\Modules\Bookings\Standards\Rules\CanCreateBooking;
use App\Classes\Modules\Bookings\Services\CreatesBooking;
use App\Classes\Modules\Bookings\Services\GeneratesBookingMarking;
use App\Classes\Modules\Bookings\DataTransferObjects\BookingObject;
use App\Classes\Modules\PerfexCRM\Processors\BookingToPerfexCRMProcessor;
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyOrderObject;
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyOrder;
use App\Classes\Modules\Vouchers\Services\CreatesVoucherEntityMapping;
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
use App\Classes\ValueObjects\Constants\Milestones;
use App\Classes\ValueObjects\Constants\VoucherifyEntityType;
use App\Http\Resources\BookingResource;
use App\Models\User;
use App\Models\Booking;
use ErrorException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -56,6 +54,11 @@ class CreateBookingLogic extends AbstractControllerLogic
/** @var CheckMilestonesForRewardProcessor */
private $checkMilestonesForRewardProcessor;
/** @var CreatesVoucherifyOrder */
private $createsVoucherifyOrder;
/** @var CreatesVoucherEntityMapping */
private $createsVoucherEntityMapping;
/**
* CreateBookingLogic constructor.
@@ -65,8 +68,10 @@ class CreateBookingLogic extends AbstractControllerLogic
* @param FetchesCompany $fetchesCompany
* @param BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor
* @param CheckMilestoneForRewardProcessor $checkMilestonesForRewardProcessor
* @param CreatesVoucherifyOrder $createsVoucherifyOrder
* @param CreatesVoucherEntityMapping $createsVoucherEntityMapping
*/
public function __construct(CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany, BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor)
public function __construct(CanCreateBooking $canCreateBooking, CreatesBooking $createsBooking, GeneratesBookingMarking $generatesBookingMarking, FetchesCompany $fetchesCompany, BookingToPerfexCRMProcessor $bookingToPerfexCRMProcessor, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, CreatesVoucherifyOrder $createsVoucherifyOrder, CreatesVoucherEntityMapping $createsVoucherEntityMapping)
{
$this->canCreateBooking = $canCreateBooking;
$this->createsBooking = $createsBooking;
@@ -74,6 +79,8 @@ class CreateBookingLogic extends AbstractControllerLogic
$this->fetchesCompany = $fetchesCompany;
$this->bookingToPerfexCRMProcessor = $bookingToPerfexCRMProcessor;
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
$this->createsVoucherifyOrder = $createsVoucherifyOrder;
$this->createsVoucherEntityMapping = $createsVoucherEntityMapping;
}
@@ -123,6 +130,23 @@ class CreateBookingLogic extends AbstractControllerLogic
}
}
$voucherify_customer_id = "";
$voucherify_order_id = "";
$user = $company->employees()->first();
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $company->id, 0, 0, 0, false, false);
$createVoucherufyOrderResult = $this->createsVoucherifyOrder->execute($createVoucherifyOrderObject);
if($createVoucherufyOrderResult && isset($createVoucherufyOrderResult->id)){
$voucherify_order_id = $createVoucherufyOrderResult->id;
if(isset($createVoucherufyOrderResult->customer)){
$voucherify_customer_id = $createVoucherufyOrderResult->customer->id;
}
}
$this->recordVoucherifyOrderInfo($voucherify_order_id, $booking);
$this->recordVoucherifyCustomerInfo($voucherify_customer_id, $user);
//cief todo: case study 5 voucherify
// $user = $company->employees()->first();
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_5]);
@@ -130,4 +154,24 @@ class CreateBookingLogic extends AbstractControllerLogic
return $this->resourceResponse(new BookingResource($booking));
}
private function recordVoucherifyOrderInfo(string $voucherify_order_id, Booking $booking){
if($voucherify_order_id){
$voucherify_entity = $booking->voucherifyEntities()->first();
if(!$voucherify_entity){
$voucherEntityObject = new VoucherEntityObject($voucherify_order_id, VoucherifyEntityType::ORDER);
$this->createsVoucherEntityMapping->execute($booking, $voucherEntityObject);
}
}
}
private function recordVoucherifyCustomerInfo(string $voucherify_customer_id, User $user){
if($voucherify_customer_id){
$voucherify_entity = $user->voucherifyEntities()->first();
if(!$voucherify_entity){
$voucherEntityObject = new VoucherEntityObject($voucherify_customer_id, VoucherifyEntityType::CUSTOMER);
$this->createsVoucherEntityMapping->execute($user, $voucherEntityObject);
}
}
}
}
@@ -14,23 +14,22 @@ use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
use App\Classes\Modules\Transactions\Processors\CreateCashBackTransactionProcessor;
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Http\Resources\TransactionResource;
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
use App\Classes\Modules\Transactions\Processors\CreateCashBackTransactionProcessor;
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
use App\Models\Booking;
use App\Models\Transaction;
use App\Models\Wallet;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance;
use Illuminate\Support\Facades\Log;
class CreateBookingPaymentLogic extends AbstractControllerLogic
{
@@ -129,7 +128,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
if($conversionObject->getAmount() > round($outstanding, 2)) throw new MalformedRequestException('Your payment must not be greater than '. $outstanding .'.');
$configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject, $voucherCode);
$configurations = $this->fetchBookingQuotation->execute($booking->company, $conversionObject, $voucherCode, null, $booking);
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
@@ -173,7 +172,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
$transaction = $this->createsTransaction->execute($booking, $object);
// $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction);
$this->bookingToVoucherifyProcessor->execute($booking->company->employees()->first(), $transaction, $booking->company->id, $configurations->getSubTotal(), $configurations->getVoucherDiscountAmount(), $voucherCode);
$this->bookingToVoucherifyProcessor->execute($booking->company->employees()->first(), $transaction, $booking->company->id, $configurations->getSubTotal(), $configurations->getServiceCharge(), $configurations->getVoucherDiscountAmount(), $voucherCode);
if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::WALLET){
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED);
@@ -115,27 +115,26 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
$refundAmount = bcdiv($request->input('amount'), $transaction->currency_rate, 7);
$bookingAmountBeforeCurrentRefund = $booking->fix_amount - $refundInPending;
$bookingAmountAfterRefunded = $booking->fix_amount - $refundInPending - $request->input('amount');
$isFullyRefund = ($refund + $request->input('amount')) == $transaction->original_amount;
$voucherCode = null;
$redemptionId = null;
if ($transaction->voucherRedemption) {
// $voucherCode = $transaction->voucherRedemption->voucher->code;
$redemptionId = $transaction->voucherRedemption->redemption_id;
}
$conversionObjectBeforeCurrentRefund = new CurrencyConversionObject($bookingAmountBeforeCurrentRefund, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
$conversionObjectAfterRefund = new CurrencyConversionObject($isFullyRefund ? $request->input('amount') : $bookingAmountAfterRefunded, $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1, $transaction->payment_method);
$quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode, $redemptionId);
$quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode, $redemptionId);
$quotationBeforeCurrentRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectBeforeCurrentRefund, $voucherCode, $redemptionId, $booking);
$quotationAfterRefund = $this->fetchBookingQuotation->execute($booking->company, $conversionObjectAfterRefund, $voucherCode, $redemptionId, $booking);
$service_charges_to_refund = $isFullyRefund ? $quotationBeforeCurrentRefund->getServiceCharge() : $quotationBeforeCurrentRefund->getServiceCharge() - $quotationAfterRefund->getServiceCharge();
}
@@ -186,4 +185,4 @@ class CreateBookingRefundLogic extends AbstractControllerLogic
}
}
}
@@ -50,6 +50,7 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
* @param GeneratesBookingQuotation $generatesBookingQuotation
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
* @param CalculatesBookingRefundAmount $calculatesBookingRefundAmount
*/
public function __construct(FetchesBookingQuotation $fetchBookingQuotation, GeneratesBookingQuotation $generatesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, CalculatesBookingOutstanding $calculatesBookingOutstanding, CalculatesBookingRefundAmount $calculatesBookingRefundAmount)
{
@@ -78,7 +79,7 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic
$voucherCode = $request->input('voucherCode');
return $this->response(['data' => $this->generatesBookingQuotation->execute(
$this->fetchBookingQuotation->execute($booking->company, $conversionObject, $voucherCode),
$this->fetchBookingQuotation->execute($booking->company, $conversionObject, $voucherCode, null, $booking),
$this->fetchesCompanyPaymentAttemptLimit->execute($booking->company),
$conversionObject
)]);
@@ -12,8 +12,11 @@ use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherOb
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyRedemption;
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
use App\Models\Booking;
use App\Models\Company;
use App\Models\Currency;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
class FetchesBookingQuotation
@@ -31,19 +34,24 @@ class FetchesBookingQuotation
/** @var FetchesVoucherifyRedemption */
private $fetchesVoucherifyRedemption;
/** @var FetchesVoucherifyVoucher */
private $fetchesVoucherifyVoucher;
/**
* FetchesBookingQuotation constructor.
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
* @param FetchesCurrency $fetchesCurrency
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
* @param FetchesVoucherifyRedemption $fetchesVoucherifyRedemption
* @param FetchesVoucherifyVoucher $fetchesVoucherifyVoucher
*/
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, FetchesVoucherifyRedemption $fetchesVoucherifyRedemption)
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, FetchesVoucherifyRedemption $fetchesVoucherifyRedemption, FetchesVoucherifyVoucher $fetchesVoucherifyVoucher)
{
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
$this->fetchesCurrency = $fetchesCurrency;
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
$this->fetchesVoucherifyRedemption = $fetchesVoucherifyRedemption;
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
}
@@ -55,7 +63,7 @@ class FetchesBookingQuotation
* @return CalculationObject
* @throws MalformedRequestException
*/
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null, ?string $redemptionId = null){
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null, ?string $redemptionId = null, ?Booking $booking = null){
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
$configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject);
@@ -66,9 +74,8 @@ class FetchesBookingQuotation
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
$voucher = null;
//Voucherify
$voucher = null;
if($voucherCode){
$employeeWhoOwnsTheVoucher = null;
@@ -89,13 +96,28 @@ class FetchesBookingQuotation
$employeeWhoOwnsTheVoucher = $company->employees()->first();
}
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $employeeWhoOwnsTheVoucher);
$isNewOrder = false;
$voucherifyVoucherFetched = $this->fetchesVoucherifyVoucher->execute($employeeWhoOwnsTheVoucher, $voucherCode);
if($booking && $voucherifyVoucherFetched && isset($voucherifyVoucherFetched->created_at)) {
$voucherifyDate = Carbon::parse($voucherifyVoucherFetched->created_at);
$bookingDate = Carbon::parse($booking->created_at);
if ($voucherifyDate->gt($bookingDate)) { // 'gt' means 'greater than'
Log::info("voucherifyVoucherFetched created_at: " . json_encode($voucherifyVoucherFetched->created_at));
Log::info("booking created_at: " . json_encode($booking->created_at));
Log::info("The voucherify voucher was created later than the booking.");
} else {
$isNewOrder = true;
}
}
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($company->id, $voucherCode, $calculationObject->getSubTotal(), $calculationObject->getServiceCharge(), $employeeWhoOwnsTheVoucher, $isNewOrder);
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
$voucher = [
"code" => $result->code,
"discount" => property_exists($result, 'discount') ? $result->discount : null,
"metadata" => $result->metadata,
"order" => $result->order,
"metadata" => property_exists($result, 'metadata') ? $result->metadata : null,
"order" => property_exists($result, 'order') ? $result->order : null,
];
}
else if($redemptionId){
@@ -109,12 +131,22 @@ class FetchesBookingQuotation
}
if($voucher){
$totalDiscountAmount = 0;
$totalAmount = 0;
if(isset($voucher['order']->total_discount_amount)){
$totalDiscountAmount = $voucher['order']->total_discount_amount;
}
if(isset($voucher['order']->total_amount)){
$totalAmount = $voucher['order']->total_amount;
}
$validatedVoucherObject = new ValidatedVoucherObject(
isset($voucher['metadata']->name) ? $voucher['metadata']->name : "",
$voucher['code'],
$voucher['discount']->type ?? 'AMOUNT',
$voucher['order']->total_discount_amount,
$voucher['order']->total_amount);
$totalDiscountAmount,
$totalAmount);
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
}
@@ -65,7 +65,7 @@ class FetchCompanyBookingQuotationLogic extends AbstractControllerLogic
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $request->input('currency_id'), $request->input('service_id'), $request->input('type'));
$calculationObject = $this->fetchBookingQuotation->execute($company, $conversionObject);
$calculationObject = $this->fetchBookingQuotation->execute($company, $conversionObject); //cief todo: 76
/** @var Currency $currency */
$currency = $this->fetchesCurrency->execute(['id' => $conversionObject->getCurrencyId()]);
@@ -77,4 +77,4 @@ class FetchCompanyBookingQuotationLogic extends AbstractControllerLogic
}
}
}
@@ -132,7 +132,7 @@ class CheckMilestonesForRewardProcessor
}
else{
//Voucherify - Validates Voucher
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $reward->value, 0.00, $user);
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $reward->value, 0, 0, $user);
$voucherifyVoucherValidated = $this->validatesVoucherifyVoucher->execute($ValidateVoucherifyVoucherObject);
if(!isset($voucherifyVoucherValidated->reason)){
@@ -5,14 +5,10 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\ListsTransactions;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Vouchers\Services\FetchesVoucherRedemption;
use App\Classes\Modules\Vouchers\Services\CreatesVoucherRedemption;
use App\Classes\Modules\Vouchers\Services\RollbacksRedemption;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Http\Resources\BookingResource;
use App\Http\Resources\TransactionResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -38,9 +34,6 @@ class SuspendTransactionLogic extends AbstractControllerLogic
/** @var RollbacksRedemption */
private $rollbacksRedemption;
/** @var FetchesVoucherRedemption */
private $fetchesVoucherRedemption;
/** @var CreatesVoucherRedemption */
private $createsVoucherRedemption;
@@ -49,35 +42,34 @@ class SuspendTransactionLogic extends AbstractControllerLogic
* @param FetchesTransaction $fetchesTransaction
* @param UpdatesTransactionStatus $updatesTransactionStatus
*/
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, RollbacksRedemption $rollbacksRedemption, FetchesVoucherRedemption $fetchesVoucherRedemption, CreatesVoucherRedemption $createsVoucherRedemption)
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, RollbacksRedemption $rollbacksRedemption, CreatesVoucherRedemption $createsVoucherRedemption)
{
$this->fetchesTransaction = $fetchesTransaction;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->rollbacksRedemption = $rollbacksRedemption;
$this->fetchesVoucherRedemption = $fetchesVoucherRedemption;
$this->createsVoucherRedemption = $createsVoucherRedemption;
}
public function logic(Request $request) : JsonResponse
{
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::SUSPENDED);
if($transaction->voucherRedemption) {
$result = $this->rollbacksRedemption->execute($transaction->voucherRedemption->redemption_id);
//Soft delete voucher redeemed record
$transaction->voucherRedemption->delete();
if($result){
$redemptionId = $result->id;
$this->createsVoucherRedemption->execute($transaction, $transaction->voucherRedemption->voucher, $redemptionId, $transaction->voucherRedemption->value);
$rollbackRecord = $this->createsVoucherRedemption->execute($transaction, $transaction->voucherRedemption->voucher, $redemptionId, $transaction->voucherRedemption->value);
//Soft delete the rollback record immediately, for recording purpose only
$rollbackRecord->delete();
}
}
return $this->response([]);
}
}
@@ -117,11 +117,11 @@ class CreateProformaInvoiceTransactionProcessor
$outstanding = $this->calculatesBookingOutstanding->execute($booking);
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $outstanding)), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0 : 1, PaymentMethodType::CASH);
$configurations = $this->fetchesBookingQuotation->execute($booking->company, $conversionObject);
$configurations = $this->fetchesBookingQuotation->execute($booking->company, $conversionObject); //cief todo: 76
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
$object = new TransactionObject(
@@ -142,7 +142,7 @@ class CreateVoucherLogic extends AbstractControllerLogic
}
//Voucherify - creates new voucher at voucherify
if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 ) {
if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 || $voucherCodeInput === Vouchers::CIEFPC30) {
$result = $this->newVoucherifyVoucherIssuanceHandler($voucherCodeInput);
}
else //Voucherify - validates existing voucher at voucherify
@@ -190,6 +190,9 @@ class CreateVoucherLogic extends AbstractControllerLogic
if(isset($campaignMetadata) && isset($campaignMetadata['voucher_limit_per_month'])){
$limit = (int) $campaignMetadata['voucher_limit_per_month'];
}
else{
$limit = 9999;
}
$voucherCampaignObject= new VoucherCampaignObject($campaignId, $campaignName, null, $limit);
$this->updatesVoucherCampaign->execute($voucherCampaign, $voucherCampaignObject);
@@ -231,7 +234,7 @@ class CreateVoucherLogic extends AbstractControllerLogic
private function existingVoucherValidationHandler(string $voucherCodeInput, User $user){
$result = [];
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $voucherCodeInput, 0.00, $user);
$ValidateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject(0, $voucherCodeInput, 0, 0, $user, true); //When adding voucher into user account, isNewOrder is marked as true, some campaign has validation on this property
$voucherifyVoucherValidated = $this->validatesVoucherifyVoucher->execute($ValidateVoucherifyVoucherObject); //Remote Voucherify
if(isset($voucherifyVoucherValidated->reason)){
@@ -7,10 +7,16 @@ use App\Classes\Exceptions\MalformedRequestException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Vouchers\Services\Voucherify\ValidatesVoucherifyVoucher;
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidateVoucherifyVoucherObject;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject;
use App\Classes\Modules\Companies\Services\FetchesCompanyServiceSettings;
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
use App\Models\Booking;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Models\Booking;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Carbon;
class ValidateVoucherLogic extends AbstractControllerLogic
{
@@ -19,21 +25,36 @@ class ValidateVoucherLogic extends AbstractControllerLogic
*/
protected function notification():array {
return [
'title' => 'Fetch Voucher',
'message' => 'You have successfully fetched a voucher'
'title' => 'Validate Voucher',
'message' => 'You have successfully validated a voucher'
];
}
/** @var ValidatesVoucherifyVoucher */
private $validatesVoucherifyVoucher;
/** @var FetchesVoucherifyVoucher */
private $fetchesVoucherifyVoucher;
/** @var FetchesCompanyServiceSettings */
private $fetchesCompanyServiceSettings;
/** @var FetchesCurrency */
private $fetchesCurrency;
/**
* ValidateVoucherLogic constructor.
* @param ValidatesVoucherifyVoucher $validatesVoucherifyVoucher
* @param FetchesVoucherifyVoucher $fetchesVoucherifyVoucher
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
* @param FetchesCurrency $fetchesCurrency
*/
public function __construct(ValidatesVoucherifyVoucher $validatesVoucherifyVoucher)
public function __construct(ValidatesVoucherifyVoucher $validatesVoucherifyVoucher, FetchesVoucherifyVoucher $fetchesVoucherifyVoucher, FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency)
{
$this->validatesVoucherifyVoucher = $validatesVoucherifyVoucher;
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
$this->fetchesCurrency = $fetchesCurrency;
}
/**
@@ -45,6 +66,21 @@ class ValidateVoucherLogic extends AbstractControllerLogic
{
$employeeWhoOwnsTheVoucher = null;
$booking = Booking::find($request->input('itemId'));
//Need to get amount in MYR, not currency to be exchanged - starts
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $request->input('amount'))), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0:1); //default $paymentMethod = PaymentMethodType::CASH
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
$configurations = $this->fetchesCompanyServiceSettings->execute($booking->company, $conversionObject);
/** @var Currency $currency */
$currency = $this->fetchesCurrency->execute(['id' => $conversionObject->getCurrencyId()]);
if($conversionObject->getAmount() > $configurations->getMaxLimit()) throw new MalformedRequestException('Your transfer can\'t be greater than '.number_format( floatval(str_replace(',', '', $configurations->getMaxLimit())), 2, '.', ',').' '.$currency->short_code);
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
//Need to get amount in MYR, not currency to be exchanged - ends
$employees = $booking->company->employees()->get();
if(count($employees) > 1){
@@ -63,10 +99,26 @@ class ValidateVoucherLogic extends AbstractControllerLogic
$employeeWhoOwnsTheVoucher = $booking->company->employees()->first();
}
$amount = $this->floatvalue($request->input('amount'));
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($booking->company_id, $request->input('voucherCode'), $amount, $employeeWhoOwnsTheVoucher);
$isNewOrder = false;
$voucherifyVoucherFetched = $this->fetchesVoucherifyVoucher->execute($employeeWhoOwnsTheVoucher, $request->input('voucherCode'));
if($voucherifyVoucherFetched && isset($voucherifyVoucherFetched->created_at)) {
$voucherifyDate = Carbon::parse($voucherifyVoucherFetched->created_at);
$bookingDate = Carbon::parse($booking->created_at);
if ($voucherifyDate->gt($bookingDate)) { // 'gt' means 'greater than'
Log::info("voucherifyVoucherFetched created_at: " . json_encode($voucherifyVoucherFetched->created_at));
Log::info("booking created_at: " . json_encode($booking->created_at));
Log::info("The voucherify voucher was created later than the booking.");
} else {
$isNewOrder = true;
}
}
$validateVoucherifyVoucherObject = new ValidateVoucherifyVoucherObject($booking->company_id, $request->input('voucherCode'), $calculationObject->getTotal(), $calculationObject->getServiceCharge(), $employeeWhoOwnsTheVoucher, $isNewOrder);
$result = $this->validatesVoucherifyVoucher->execute($validateVoucherifyVoucherObject);
Log::info("ValidateVoucherLogic validatesVoucherifyVoucher: " .json_encode($result));
return $this->response(['data' => $result]);
}
@@ -20,6 +20,9 @@ class CreateVoucherifyOrderObject implements DataTransferObject
/** @var float */
private $amount;
/** @var float */
private $serviceCharge;
/** @var bool */
private $isNoVoucher;
@@ -32,15 +35,17 @@ class CreateVoucherifyOrderObject implements DataTransferObject
* @param int $companyId
* @param int $transactionId
* @param float $amount
* @param float $serviceCharge
* @param bool $isNoVoucher
* @param bool $isTopUpWallet
*/
public function __construct(User $employee, int $companyId, int $transactionId, float $amount, bool $isNoVoucher, bool $isTopUpWallet)
public function __construct(User $employee, int $companyId, int $transactionId, float $amount, float $serviceCharge, bool $isNoVoucher = false, bool $isTopUpWallet = false)
{
$this->employee = $employee;
$this->companyId = $companyId;
$this->transactionId = $transactionId;
$this->amount = $amount;
$this->serviceCharge = $serviceCharge;
$this->isNoVoucher = $isNoVoucher;
$this->isTopUpWallet = $isTopUpWallet;
}
@@ -69,6 +74,14 @@ class CreateVoucherifyOrderObject implements DataTransferObject
return $this->amount;
}
/**
* @return float
*/
public function getServiceCharge(): float
{
return $this->serviceCharge;
}
/**
* @return User
*/
@@ -15,27 +15,42 @@ class RedeemVoucherifyVoucherObject implements DataTransferObject
/** @var string */
private $promoCode;
/** @var string */
/** @var float */
private $amount;
/** @var float */
private $serviceCharge;
/** @var object */
private $employee;
/** @var string */
private $voucherifyOrderId;
/** @var bool */
private $isNewOrder; //comparing booking and voucher date, an order is deemed new when booking is created after receiving voucher
/**
* RedeemVoucherifyVoucherObject constructor.
* @param int $companyId
* @param int $transactionId
* @param string $name
* @param string $email
* @param string $promoCode
* @param float $amount
* @param float $serviceCharge
* @param object $employee
* @param string $voucherifyOrderId
* @param bool $isNewOrder
*/
public function __construct(int $companyId, int $transactionId, string $promoCode, string $amount, object $employee)
public function __construct(int $companyId, int $transactionId, string $promoCode, float $amount, float $serviceCharge, object $employee, string $voucherifyOrderId, ?bool $isNewOrder = null)
{
$this->companyId = $companyId;
$this->transactionId = $transactionId;
$this->promoCode = $promoCode;
$this->amount = $amount;
$this->serviceCharge = $serviceCharge;
$this->employee = $employee;
$this->voucherifyOrderId = $voucherifyOrderId;
$this->isNewOrder = $isNewOrder;
}
/**
@@ -65,13 +80,21 @@ class RedeemVoucherifyVoucherObject implements DataTransferObject
}
/**
* @return string
* @return float
*/
public function getAmount(): string
public function getAmount(): float
{
return $this->amount;
}
/**
* @return float
*/
public function getServiceCharge(): float
{
return $this->serviceCharge;
}
/**
* @return object
*/
@@ -80,4 +103,19 @@ class RedeemVoucherifyVoucherObject implements DataTransferObject
return $this->employee;
}
/**
* @return string
*/
public function getVoucherifyOrderId(): string
{
return $this->voucherifyOrderId;
}
/**
* @return bool|null
*/
public function getIsNewOrder(): ?bool
{
return $this->isNewOrder;
}
}
@@ -17,22 +17,32 @@ class ValidateVoucherifyVoucherObject implements DataTransferObject
/** @var float */
private $amount;
/** @var float */
private $serviceCharge;
/** @var User */
private $user; //this will affect certain voucher that limit user redemption e.g. one user one redemption per campaign
/** @var bool */
private $isNewOrder; //comparing booking and voucher date, an order is deemed new when booking is created after receiving voucher
/**
* ValidateVoucherifyVoucherObject constructor.
* @param int $companyId
* @param string $voucherCode
* @param float $amount
* @param float $serviceCharge
* @param User $user
* @param bool $isNewOrder
*/
public function __construct(int $companyId, string $voucherCode, float $amount, User $user)
public function __construct(int $companyId, string $voucherCode, float $amount, float $serviceCharge, User $user, ?bool $isNewOrder = null)
{
$this->companyId = $companyId;
$this->voucherCode = $voucherCode;
$this->amount = $amount;
$this->serviceCharge = $serviceCharge;
$this->user = $user;
$this->isNewOrder = $isNewOrder;
}
/**
@@ -59,6 +69,14 @@ class ValidateVoucherifyVoucherObject implements DataTransferObject
return $this->amount;
}
/**
* @return float
*/
public function getServiceCharge(): float
{
return $this->serviceCharge;
}
/**
* @return User
*/
@@ -67,4 +85,12 @@ class ValidateVoucherifyVoucherObject implements DataTransferObject
return $this->user;
}
/**
* @return bool|null
*/
public function getIsNewOrder(): ?bool
{
return $this->isNewOrder;
}
}
@@ -69,6 +69,10 @@ class CreateVoucherProcessor
$voucherStartDate = $voucherifyVoucherFetched->start_date;
$voucherEndDate = $voucherifyVoucherFetched->expiration_date;
if(isset($voucherifyVoucherFetched->discount->amount_off_formula)){
$voucherType = 'PERCENT';
}
//Locally - Create and Fetch Voucher
$voucherObject = new VoucherObject(
$voucherCode,
@@ -11,6 +11,7 @@ use App\Classes\Modules\Vouchers\DataTransferObjects\RedeemVoucherifyVoucherObje
use App\Classes\Modules\Vouchers\DataTransferObjects\CreateVoucherifyOrderObject;
use App\Classes\Modules\Vouchers\Services\Voucherify\CreatesVoucherifyOrder;
use App\Classes\Modules\Vouchers\Services\CreatesVoucherEntityMapping;
use App\Classes\Modules\Vouchers\Services\Voucherify\FetchesVoucherifyVoucher;
use App\Classes\Modules\Vouchers\DataTransferObjects\VoucherEntityObject;
use App\Classes\Modules\Rewards\Services\CreatesUserReward;
use App\Classes\ValueObjects\Constants\TransactionType;
@@ -19,6 +20,7 @@ use App\Models\User;
use App\Models\Transaction;
use App\Models\Voucher;
use App\Models\VoucherCampaign;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
class BookingToVoucherifyProcessor
@@ -44,6 +46,9 @@ class BookingToVoucherifyProcessor
/** @var CreatesUserReward */
private $createsUserReward;
/** @var FetchesVoucherifyVoucher */
private $fetchesVoucherifyVoucher;
/**
* BookingToVoucherifyProcessor constructor.
* @param CreatesVoucher $createsVoucher
@@ -53,8 +58,9 @@ class BookingToVoucherifyProcessor
* @param CreatesVoucherifyOrder $createsVoucherifyOrder
* @param CreatesVoucherEntityMapping $createsVoucherEntityMapping
* @param CreatesUserReward $createsUserReward
* @param FetchesVoucherifyVoucher $fetchesVoucherifyVoucher
*/
public function __construct(CreatesVoucher $createsVoucher, FetchesVoucher $fetchesVoucher, CreatesVoucherRedemption $createsVoucherRedemption, RedeemsVoucherifyVoucher $redeemsVoucherifyVoucher, CreatesVoucherifyOrder $createsVoucherifyOrder, CreatesVoucherEntityMapping $createsVoucherEntityMapping, CreatesUserReward $createsUserReward)
public function __construct(CreatesVoucher $createsVoucher, FetchesVoucher $fetchesVoucher, CreatesVoucherRedemption $createsVoucherRedemption, RedeemsVoucherifyVoucher $redeemsVoucherifyVoucher, CreatesVoucherifyOrder $createsVoucherifyOrder, CreatesVoucherEntityMapping $createsVoucherEntityMapping, CreatesUserReward $createsUserReward, FetchesVoucherifyVoucher $fetchesVoucherifyVoucher)
{
$this->createsVoucher = $createsVoucher;
$this->fetchesVoucher = $fetchesVoucher;
@@ -63,6 +69,7 @@ class BookingToVoucherifyProcessor
$this->createsVoucherifyOrder = $createsVoucherifyOrder;
$this->createsVoucherEntityMapping = $createsVoucherEntityMapping;
$this->createsUserReward = $createsUserReward;
$this->fetchesVoucherifyVoucher = $fetchesVoucherifyVoucher;
}
@@ -71,13 +78,14 @@ class BookingToVoucherifyProcessor
* @param Transaction $transaction
* @param int $companyId
* @param float $amount
* @param float $serviceCharge
* @param float $voucherDiscountAmount
* @param string $voucherCode
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \Voucherify\ClientException
*/
public function execute(User $user, Transaction $transaction, int $companyId, float $amount, float $voucherDiscountAmount, ?string $voucherCode = "")
public function execute(User $user, Transaction $transaction, int $companyId, float $amount, float $serviceCharge, float $voucherDiscountAmount, ?string $voucherCode = "")
{
try{
$voucherify_customer_id = "";
@@ -102,11 +110,25 @@ class BookingToVoucherifyProcessor
$employeeWhoOwnsTheVoucher = $user;
}
$redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $transaction->id, $voucherCode, $amount, $employeeWhoOwnsTheVoucher);
$isNewOrder = false;
$booking = $transaction->booking;
$voucherifyVoucherFetched = $this->fetchesVoucherifyVoucher->execute($employeeWhoOwnsTheVoucher, $voucherCode);
if($voucherifyVoucherFetched && isset($voucherifyVoucherFetched->created_at)) {
$voucherifyDate = Carbon::parse($voucherifyVoucherFetched->created_at);
$bookingDate = Carbon::parse($booking->created_at);
if ($voucherifyDate->gt($bookingDate)) { // 'gt' means 'greater than'
Log::info("voucherifyVoucherFetched created_at: " . json_encode($voucherifyVoucherFetched->created_at));
Log::info("booking created_at: " . json_encode($booking->created_at));
Log::info("The voucherify voucher was created later than the booking.");
} else {
$isNewOrder = true;
}
}
$voucherify_entity = $booking->voucherifyEntities()->first(); //cief todo: 76 could be filtered more precisely to prevent fetching wrong record
$redeemVoucherifyVoucherObject = new RedeemVoucherifyVoucherObject($companyId, $transaction->id, $voucherCode, $amount, $serviceCharge, $employeeWhoOwnsTheVoucher, $voucherify_entity->voucherify_entity_id, $isNewOrder);
$redeemVoucherResult = $this->redeemsVoucherifyVoucher->execute($redeemVoucherifyVoucherObject);
// Log::info('redeemVoucherResult: '.json_encode($redeemVoucherResult));
$redeemedVoucher = $redeemVoucherResult->voucher;
$redemptionId = $redeemVoucherResult->id;
@@ -123,7 +145,7 @@ class BookingToVoucherifyProcessor
$this->recordVoucherForUserInfo($employeeWhoOwnsTheVoucher, $voucher);
}
else{
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $transaction->id, $amount, true, $transaction->type == TransactionType::TOP_UP);
$createVoucherifyOrderObject = new CreateVoucherifyOrderObject($user, $companyId, $transaction->id, $amount, $transaction->service_charge, true, $transaction->type == TransactionType::TOP_UP);
$createVoucherufyOrderResult = $this->createsVoucherifyOrder->execute($createVoucherifyOrderObject);
if($createVoucherufyOrderResult && isset($createVoucherufyOrderResult->id)){
@@ -52,6 +52,10 @@ class CreatesVoucherifyOrder
$orderObj['metadata']["is_wallet_top_up"] = true;
}
if ($obj->getServiceCharge()) {
$orderObj['metadata']["service_charge"] = $obj->getServiceCharge();
}
$result = $this->voucherifyClient->orders->create($orderObj);
return $result;
} catch (\Voucherify\ClientException $e) {
@@ -29,7 +29,7 @@ class RedeemsVoucherifyVoucher
public function execute(RedeemVoucherifyVoucherObject $redeemVoucherifyVoucherObject)
{
try {
$result = $this->voucherifyClient->redemptions->redeem($redeemVoucherifyVoucherObject->getPromoCode(), [
$redeemVoucherObject = [
"customer" => [
"source_id" => $redeemVoucherifyVoucherObject->getEmployee()->id,
"name" => $redeemVoucherifyVoucherObject->getEmployee()->name,
@@ -40,10 +40,22 @@ class RedeemsVoucherifyVoucher
]
],
"order" => [
"id" => $redeemVoucherifyVoucherObject->getVoucherifyOrderId(),
"source_id" => $redeemVoucherifyVoucherObject->getTransactionId(),
"amount" => $redeemVoucherifyVoucherObject->getAmount() * 100 //converting it to cents
]
]);
];
if ($redeemVoucherifyVoucherObject->getServiceCharge()) {
$serviceCharge = round($redeemVoucherifyVoucherObject->getServiceCharge(), 2);
$redeemVoucherObject['order']['metadata']['service_charge'] = $serviceCharge;
}
if ($redeemVoucherifyVoucherObject->getIsNewOrder()) {
$redeemVoucherObject['order']['metadata']['is_new_order'] = $redeemVoucherifyVoucherObject->getIsNewOrder();
}
$result = $this->voucherifyClient->redemptions->redeem($redeemVoucherifyVoucherObject->getPromoCode(), $redeemVoucherObject);
return $result;
} catch (\Voucherify\ClientException $e) {
Log::error('RedeemsVoucherifyVoucher '.$e);
@@ -29,6 +29,7 @@ class ValidatesVoucherifyVoucher
*/
public function execute(ValidateVoucherifyVoucherObject $validateVoucherifyVoucherObject)
{
try {
$validateVoucherObj = [
"customer" => [
@@ -42,15 +43,19 @@ class ValidatesVoucherifyVoucher
]
];
if ($validateVoucherifyVoucherObject->getAmount()) {
$validateVoucherObj['order'] = [
"amount" => $validateVoucherifyVoucherObject->getAmount() * 100 //converting it to cents
];
$validateVoucherObj['order']['amount'] = $validateVoucherifyVoucherObject->getAmount() * 100; // converting to cents
if ($validateVoucherifyVoucherObject->getServiceCharge()) {
$serviceCharge = round($validateVoucherifyVoucherObject->getServiceCharge(), 2);
$validateVoucherObj['order']['metadata']['service_charge'] = $serviceCharge;
}
if ($validateVoucherifyVoucherObject->getIsNewOrder()) {
$validateVoucherObj['order']['metadata']['is_new_order'] = $validateVoucherifyVoucherObject->getIsNewOrder();
}
$result = $this->voucherifyClient->validations->validateVoucher($validateVoucherifyVoucherObject->getVoucherCode(), $validateVoucherObj);
if (isset($result->metadata) && isset($result->metadata->email)) {
if (isset($result->metadata) && isset($result->metadata->email)) { // used in CheckMilestonesForRewardProcessor
if($validateVoucherifyVoucherObject->getUser()->email != $result->metadata->email){
$result->reason = 'Invalid Code';
}
@@ -113,7 +113,7 @@ class TopUpWalletLogic extends AbstractControllerLogic
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
$this->bookingToVoucherifyProcessor->execute($company->employees()->first(), $transaction, $company->id, $amount, 0);
$this->bookingToVoucherifyProcessor->execute($company->employees()->first(), $transaction, $company->id, $amount, 0, 0);
return $this->resourceResponse(new WalletTransactionResource($transaction));
}
@@ -10,11 +10,13 @@ final class Vouchers {
public const SORRY_100 = 'SORRY100';
public const SORRY_200 = 'SORRY200';
public const PROM150PERCENT = 'PROM150%';
public const CIEFPC30 = 'CIEFPC30';
const OPTIONS_SORRY = [
['text' => 'SORRY 50', 'id' => Vouchers::SORRY_50],
['text' => 'SORRY 100', 'id' => Vouchers::SORRY_100],
['text' => 'SORRY 200', 'id' => Vouchers::SORRY_200],
['text' => 'PROM150%', 'id' => Vouchers::PROM150PERCENT],
['text' => 'CIEFPC30', 'id' => Vouchers::CIEFPC30],
];
}
@@ -23,11 +23,12 @@ class LogRequestPathMiddleware
$fullUrl = $request->fullUrl();
LogHelper::channel('request_path')->info('Request Method: ' . $method);
LogHelper::channel('request_path')->info('Request URL: ' . $fullUrl);
}
if ($request->isMethod('post')) {
$payload = $request->all();
LogHelper::channel('request_path')->info('Request Payload POST: ', $payload);
if ($request->isMethod('post')) {
$payload = $request->all();
LogHelper::channel('request_path')->info('Request Payload POST: ', $payload);
}
}
return $next($request);
+9 -1
View File
@@ -4,6 +4,7 @@ namespace App\Models;
use App\Classes\General\Interfaces\Documentable;
use App\Classes\General\Interfaces\Transactionable;
use App\Classes\General\Interfaces\Voucherifiable;
use App\Classes\General\Traits\LogData;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Scopes\CustomerBookingsScope;
@@ -25,7 +26,7 @@ use Staudenmeir\EloquentHasManyDeep\HasRelationships;
* @property int convertible_currency_id
* @property int conversion_currency_id
*/
class Booking extends AbstractModel implements Documentable, Transactionable
class Booking extends AbstractModel implements Documentable, Transactionable, Voucherifiable
{
use HasRelationships;
use SoftDeletes;
@@ -121,5 +122,12 @@ class Booking extends AbstractModel implements Documentable, Transactionable
}
}
/**
* @return MorphMany
*/
public function voucherifyEntities(): MorphMany
{
return $this->morphMany(VoucherEntityMapping::class, 'owner');
}
}
+3 -2
View File
@@ -3,11 +3,12 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
class VoucherRedemption extends AbstractModel
{
use SoftDeletes;
protected $table = 'voucher_redemptions';
/**
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddDeletedAtToVoucherRedemptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('voucher_redemptions', function (Blueprint $table) {
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('voucher_redemptions', function (Blueprint $table) {
$table->dropSoftDeletes();
});
}
}
@@ -11,6 +11,7 @@
</div>
<div class="col text-right no-padding" v-if="item.voucher.type == 'PERCENT'">
<span v-if="item.voucher.value === 1">50% Discount</span>
<span v-else>{{ item.voucher.name }}</span>
</div>
</div>
<div class="row">
@@ -696,7 +696,8 @@
this.parameters = {
voucherCode: this.voucherCode,
amount: this.amount,
itemId: this.item.id
itemId: this.item.id,
payment_method: this.paymentMethod.id,
};
if(this.voucherCode.trim() !== ''){
this.submit(route('api.voucher.validate'), 'post', '', false, false);
@@ -3,10 +3,14 @@
<div class="card-body">
<h5 class="card-title">{{ item.name }}</h5>
<p class="card-text">{{ item.description }}</p>
<p v-if="item.voucher && item.user_rewards.voucher.is_redeemed" class="text-secondary"> {{ item.voucher.code }}</p>
<p v-else-if="item.voucher" class="text-primary"> {{ item.voucher.code }}</p>
<p v-if="item.voucher && item.voucher.type == 'AMOUNT'">RM{{ item.voucher.value/100 }} Discount</p>
<p v-if="item.voucher && item.voucher.type == 'PERCENT'">{{ item.voucher.value }}% Discount</p>
<p v-if="item.voucher && item.voucher.type == 'PERCENT' && item.voucher.value > 0">{{ item.voucher.value }}% Discount</p>
<p v-else>Discount</p>
</div>
<div class="card-footer text-muted">
<p v-if="item.user_rewards && item.user_rewards.voucher.is_redeemed">
@@ -19,7 +19,8 @@
<p v-if="item.voucher.type == 'AMOUNT'">RM{{ item.voucher.value / 100 }} Discount</p>
<p v-if="item.voucher.type == 'PERCENT'">
<span v-if="item.voucher.value === 1">50% discount on service fee only</span>
<span v-else>{{ item.voucher.value }}% Discount</span>
<span v-else-if="item.voucher.value > 0">{{ item.voucher.value }}% Discount</span>
<span v-else>Discount</span>
</p>
</div>
<div class="col-md-1">