|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright Iain Cambridge 2020-2023. |
|
7
|
|
|
* |
|
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
|
9
|
|
|
* |
|
10
|
|
|
* Change Date: TBD ( 3 years after 2.2.0 release ) |
|
11
|
|
|
* |
|
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Parthenon\Billing\Webhook\Handler; |
|
16
|
|
|
|
|
17
|
|
|
use Obol\Model\Events\AbstractDispute; |
|
18
|
|
|
use Obol\Model\Events\EventInterface; |
|
19
|
|
|
use Parthenon\Billing\ChargeBack\ChargeBackFactoryInterface; |
|
20
|
|
|
use Parthenon\Billing\Enum\ChargeBackReason; |
|
21
|
|
|
use Parthenon\Billing\Enum\ChargeBackStatus; |
|
22
|
|
|
use Parthenon\Billing\Repository\ChargeBackRepositoryInterface; |
|
23
|
|
|
use Parthenon\Billing\Webhook\HandlerInterface; |
|
24
|
|
|
use Parthenon\Common\Exception\NoEntityFoundException; |
|
25
|
|
|
|
|
26
|
|
|
class ChargeBackHandler implements HandlerInterface |
|
27
|
|
|
{ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
private ChargeBackRepositoryInterface $chargeBackRepository, |
|
30
|
|
|
private ChargeBackFactoryInterface $factory, |
|
31
|
|
|
) { |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function supports(EventInterface $event): bool |
|
35
|
|
|
{ |
|
36
|
|
|
return $event instanceof AbstractDispute; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param AbstractDispute $event |
|
41
|
|
|
*/ |
|
42
|
|
|
public function handle(EventInterface $event): void |
|
43
|
|
|
{ |
|
44
|
|
|
try { |
|
45
|
|
|
$chargeBack = $this->chargeBackRepository->getByExternalReference($event->getId()); |
|
46
|
|
|
} catch (NoEntityFoundException $e) { |
|
47
|
|
|
$chargeBack = $this->factory->buildFromEvent($event); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$chargeBack->setStatus(ChargeBackStatus::fromName($event->getStatus())); |
|
|
|
|
|
|
51
|
|
|
$chargeBack->setReason(ChargeBackReason::fromName($event->getReason())); |
|
|
|
|
|
|
52
|
|
|
$chargeBack->setUpdatedAt(new \DateTime()); |
|
53
|
|
|
|
|
54
|
|
|
$this->chargeBackRepository->save($chargeBack); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|