Passed
Push — trunk ( 26fc38...0b2f4f )
by Christian
13:44 queued 13s
created

OrderTransactionCaptureBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 31
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A amount() 0 5 1
A addRefund() 0 22 1
A __construct() 0 13 1
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Test\Integration\Builder\Order;
4
5
use Shopware\Core\Checkout\Cart\Price\Struct\CalculatedPrice;
6
use Shopware\Core\Checkout\Cart\Tax\Struct\CalculatedTaxCollection;
7
use Shopware\Core\Checkout\Cart\Tax\Struct\TaxRuleCollection;
8
use Shopware\Core\Checkout\Order\Aggregate\OrderTransactionCapture\OrderTransactionCaptureStates;
9
use Shopware\Core\Checkout\Order\Aggregate\OrderTransactionCaptureRefund\OrderTransactionCaptureRefundStates;
10
use Shopware\Core\Framework\Log\Package;
11
use Shopware\Core\Framework\Test\IdsCollection;
12
use Shopware\Core\Framework\Test\TestCaseBase\BasicTestDataBehaviour;
13
use Shopware\Core\Framework\Test\TestCaseBase\KernelTestBehaviour;
14
use Shopware\Core\Test\TestBuilderTrait;
15
16
/**
17
 * @final
18
 */
19
#[Package('customer-order')]
20
class OrderTransactionCaptureBuilder
21
{
22
    use BasicTestDataBehaviour;
23
    use KernelTestBehaviour;
24
    use TestBuilderTrait;
25
26
    protected string $id;
27
28
    protected CalculatedPrice $amount;
29
30
    protected string $stateId;
31
32
    /**
33
     * @var array<string, array<string, mixed>>
34
     */
35
    protected array $refunds = [];
36
37
    public function __construct(
38
        IdsCollection $ids,
39
        string $key,
40
        protected string $orderTransactionId,
41
        float $amount = 420.69,
42
        string $state = OrderTransactionCaptureStates::STATE_PENDING,
43
        protected ?string $externalReference = null
44
    ) {
45
        $this->id = $ids->get($key);
46
        $this->ids = $ids;
47
        $this->stateId = $this->getStateMachineState(OrderTransactionCaptureStates::STATE_MACHINE, $state);
48
49
        $this->amount($amount);
50
    }
51
52
    public function amount(float $amount): self
53
    {
54
        $this->amount = new CalculatedPrice($amount, $amount, new CalculatedTaxCollection(), new TaxRuleCollection());
55
56
        return $this;
57
    }
58
59
    /**
60
     * @param array<string, mixed> $customParams
61
     */
62
    public function addRefund(string $key, array $customParams = []): self
63
    {
64
        $refund = \array_replace([
65
            'id' => $this->ids->get($key),
66
            'captureId' => $this->id,
67
            'stateId' => $this->getStateMachineState(
68
                OrderTransactionCaptureRefundStates::STATE_MACHINE,
69
                OrderTransactionCaptureRefundStates::STATE_OPEN
70
            ),
71
            'externalReference' => null,
72
            'reason' => null,
73
            'amount' => new CalculatedPrice(
74
                420.69,
75
                420.69,
76
                new CalculatedTaxCollection(),
77
                new TaxRuleCollection()
78
            ),
79
        ], $customParams);
80
81
        $this->refunds[$this->ids->get($key)] = $refund;
82
83
        return $this;
84
    }
85
}
86