Passed
Push — main ( a0fff1...ecb15a )
by Iain
04:46
created

ChargeBackFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
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\ChargeBack;
16
17
use Obol\Model\Events\AbstractDispute;
18
use Parthenon\Billing\Entity\ChargeBack;
19
use Parthenon\Billing\Factory\EntityFactory;
20
use Parthenon\Billing\Repository\PaymentRepositoryInterface;
21
22
class ChargeBackFactory implements ChargeBackFactoryInterface
23
{
24
    public function __construct(
25
        private PaymentRepositoryInterface $paymentRepository,
26
        private EntityFactory $entityFactory,
27
    ) {
28
    }
29
30
    public function buildFromEvent(AbstractDispute $event): ChargeBack
31
    {
32
        $chargeBack = $this->entityFactory->getChargeBackEntity();
33
34
        $payment = $this->paymentRepository->getPaymentForReference($event->getDisputedPaymentReference());
35
        $chargeBack->setExternalReference($event->getId());
36
        $chargeBack->setPayment($payment);
37
        $chargeBack->setCustomer($payment->getCustomer());
38
        $chargeBack->setCreatedAt(new \DateTime('now'));
39
        $chargeBack->setUpdatedAt(new \DateTime('now'));
40
41
        return $chargeBack;
42
    }
43
44
    public function buildFromChargeBack(\Obol\Model\ChargeBack\ChargeBack $obolChargeBack): ChargeBack
45
    {
46
        $chargeBack = $this->entityFactory->getChargeBackEntity();
47
48
        $payment = $this->paymentRepository->getPaymentForReference($obolChargeBack->getPaymentReference());
49
        $chargeBack->setExternalReference($event->getId());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $event seems to be never defined.
Loading history...
50
        $chargeBack->setPayment($payment);
51
        $chargeBack->setCustomer($payment->getCustomer());
52
        $chargeBack->setCreatedAt(new \DateTime('now'));
53
        $chargeBack->setUpdatedAt(new \DateTime('now'));
54
55
        return $chargeBack;
56
    }
57
}
58