ldc-boutique-cnc/app/Jobs/Order/RefundOrder.php
2023-05-19 12:11:38 +02:00

90 lines
2.2 KiB
PHP

<?php
namespace App\Jobs\Order;
use App\Enums\Order\PaymentModeEnum;
use App\Models\Payment\Transaction;
use App\Models\Shop\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class RefundOrder implements ShouldQueue
{
use Dispatchable;
use InteractsWithQueue;
use Queueable;
use SerializesModels;
/**
* Order
*
* @var \App\Models\Shop\Order
*/
private $order;
/**
* Transaction that was refund
*
* @var \App\Models\Payment\Transaction
*/
private $transaction;
/**
* Amount to refund
*
* @var integer
*/
private $amountToRefund;
/**
* Items that are refunded
*
* @var object
*/
private $items;
/**
* Create a new job instance.
*
* @param \App\Models\Shop\Order $order
* @param \App\Models\Payment\Transaction $transaction
* @param integer $amountToRefund
* @param object $items
* @return void
*/
public function __construct(
Order $order,
Transaction $transaction,
int $amountToRefund,
object $items
) {
$this->order = $order;
$this->transaction = $transaction;
$this->amountToRefund = $amountToRefund;
$this->items = $items;
}
/**
* Execute the job.
*
* @return void
* @throws \RuntimeException If the transaction payment mode given is inShop or if the transaction refund failed.
* @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
*/
public function handle()
{
// phpcs:enable
if ($this->transaction->payment_mode->equals(PaymentModeEnum::inShop())) {
throw new \RuntimeException('An inShop transaction cannot be refunded by the platform');
}
$this->transaction->getAdapter()->doRefundCustomer(
$this->transaction,
$this->amountToRefund,
$this->items
);
}
}