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
|
|
|
|