Files
exchange-2.0/app/Classes/Modules/Vouchers/Processors/Voucherify/TransactionToVoucherifyProcessor.php
T
2024-12-09 07:48:13 +08:00

46 lines
1.6 KiB
PHP

<?php
namespace App\Classes\Modules\Vouchers\Processors\Voucherify;
use App\Classes\Modules\Vouchers\DataTransferObjects\UpdateVoucherifyOrderObject;
use App\Classes\Modules\Vouchers\Services\Voucherify\UpdatesVoucherifyOrder;
use App\Models\Transaction;
use Illuminate\Support\Facades\Log;
class TransactionToVoucherifyProcessor
{
/** @var UpdatesVoucherifyOrder */
private $updatesVoucherifyOrder;
/**
* TransactionToVoucherifyProcessor constructor.
* @param UpdatesVoucherifyOrder $updatesVoucherifyOrder
*/
public function __construct(UpdatesVoucherifyOrder $updatesVoucherifyOrder)
{
$this->updatesVoucherifyOrder = $updatesVoucherifyOrder;
}
/**
* @param Transaction $transaction
* @param string $status
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \Voucherify\ClientException
*/
public function execute(Transaction $transaction, string $status)
{
try{
$voucherify_entity = $transaction->voucherifyEntities()->first(); //cief todo: 76 could be filtered more precisely to prevent fetching wrong record
if($voucherify_entity){
$booking = $transaction->booking;
$updateVoucherifyOrderObject = new UpdateVoucherifyOrderObject($voucherify_entity->voucherify_entity_id, $booking->id, $transaction->id, $status);
$this->updatesVoucherifyOrder->execute($updateVoucherifyOrderObject);
}
} catch (\Exception $e) {
Log::error($e);
}
}
}