mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
Vourcherify
This commit is contained in:
@@ -7,7 +7,9 @@ use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyServiceSettings;
|
||||
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
|
||||
use App\Classes\Modules\Vouchers\DataTransferObjects\ValidatedVoucherObject;
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\Modules\Vouchers\Services\ValidatesVoucher;
|
||||
use App\Models\Company;
|
||||
use App\Models\Currency;
|
||||
|
||||
@@ -20,25 +22,30 @@ class FetchesBookingQuotation
|
||||
/** @var FetchesCurrency */
|
||||
private $fetchesCurrency;
|
||||
|
||||
/** @var ValidatesVoucher */
|
||||
private $validatesVoucher;
|
||||
|
||||
/**
|
||||
* FetchesBookingQuotation constructor.
|
||||
* @param FetchesCompanyServiceSettings $fetchesCompanyServiceSettings
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
*/
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency)
|
||||
public function __construct(FetchesCompanyServiceSettings $fetchesCompanyServiceSettings, FetchesCurrency $fetchesCurrency, ValidatesVoucher $validatesVoucher)
|
||||
{
|
||||
$this->fetchesCompanyServiceSettings = $fetchesCompanyServiceSettings;
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
$this->validatesVoucher = $validatesVoucher;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Company $company
|
||||
* @param CurrencyConversionObject $conversionObject
|
||||
* @param string $voucherCode
|
||||
* @return CalculationObject
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, CurrencyConversionObject $conversionObject){
|
||||
public function execute(Company $company, CurrencyConversionObject $conversionObject, ?string $voucherCode = null){
|
||||
if($conversionObject->getAmount() <= 0) throw new MalformedRequestException('Your transfer must be greater than zero.');
|
||||
|
||||
$configurations = $this->fetchesCompanyServiceSettings->execute($company, $conversionObject);
|
||||
@@ -47,9 +54,24 @@ class FetchesBookingQuotation
|
||||
$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);
|
||||
$calculationObject = new CalculationObject($conversionObject, $configurations, null);
|
||||
|
||||
//Voucherify
|
||||
if($voucherCode){
|
||||
$employee = $company->employees()->first();
|
||||
|
||||
$result = $this->validatesVoucher->execute($voucherCode, $calculationObject->getSubTotal(), $employee);
|
||||
$voucher = [
|
||||
"code" => $result->code,
|
||||
"discount" => $result->discount,
|
||||
"metadata" => $result->metadata,
|
||||
"order" => $result->order,
|
||||
];
|
||||
$validatedVoucherObject = new ValidatedVoucherObject(isset($voucher['metadata']->name) ? $voucher['metadata']->name: "", $voucher['code'], $voucher['discount']->type, $voucher['order']->total_discount_amount, $voucher['order']->total_amount);
|
||||
$calculationObject = new CalculationObject($conversionObject, $configurations, $validatedVoucherObject);
|
||||
}
|
||||
|
||||
return $calculationObject;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user