Passed
Push — trunk ( 49986f...44ff76 )
by Christian
22:08 queued 08:23
created

SyncTestPaymentHandler::pay()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 3
dl 0
loc 17
rs 9.9332
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Test\Integration\PaymentHandler;
4
5
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler;
6
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\SynchronousPaymentHandlerInterface;
7
use Shopware\Core\Checkout\Payment\Cart\SyncPaymentTransactionStruct;
8
use Shopware\Core\Checkout\Payment\Exception\SyncPaymentProcessException;
9
use Shopware\Core\Framework\Log\Package;
10
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
11
use Shopware\Core\System\SalesChannel\SalesChannelContext;
12
13
/**
14
 * @internal
15
 */
16
#[Package('checkout')]
17
class SyncTestPaymentHandler implements SynchronousPaymentHandlerInterface
18
{
19
    public function __construct(private readonly OrderTransactionStateHandler $transactionStateHandler)
20
    {
21
    }
22
23
    public function pay(SyncPaymentTransactionStruct $transaction, RequestDataBag $dataBag, SalesChannelContext $salesChannelContext): void
24
    {
25
        $transactionId = $transaction->getOrderTransaction()->getId();
26
        $order = $transaction->getOrder();
27
28
        $lineItems = $order->getLineItems();
29
        if ($lineItems === null) {
30
            throw new SyncPaymentProcessException($transactionId, 'lineItems is null');
31
        }
32
33
        $customer = $order->getOrderCustomer()?->getCustomer();
34
        if ($customer === null) {
35
            throw new SyncPaymentProcessException($transactionId, 'customer is null');
36
        }
37
38
        $context = $salesChannelContext->getContext();
39
        $this->transactionStateHandler->process($transactionId, $context);
40
    }
41
}
42