EscolaLMS/Cart

View on GitHub
src/Listeners/PaymentSuccessListener.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace EscolaLms\Cart\Listeners;

use EscolaLms\Cart\Models\Order;
use EscolaLms\Cart\Services\Contracts\OrderServiceContract;
use EscolaLms\Payments\Events\PaymentSuccess;

class PaymentSuccessListener
{
    protected OrderServiceContract $orderService;

    public function __construct(OrderServiceContract $orderService)
    {
        $this->orderService = $orderService;
    }

    public function handle(PaymentSuccess $event)
    {
        $payment = $event->getPayment();
        if ($payment->payable instanceof Order) {
            $this->orderService->setPaid($payment->payable->refresh());
        }
    }
}