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

PreparedTestPaymentHandler::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 12
rs 10
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\Cart\Cart;
6
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\PreparedPaymentHandlerInterface;
7
use Shopware\Core\Checkout\Payment\Cart\PreparedPaymentTransactionStruct;
8
use Shopware\Core\Checkout\Payment\Exception\ValidatePreparedPaymentException;
9
use Shopware\Core\Checkout\Payment\PaymentException;
10
use Shopware\Core\Framework\Log\Package;
11
use Shopware\Core\Framework\Struct\ArrayStruct;
12
use Shopware\Core\Framework\Struct\Struct;
13
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag;
14
use Shopware\Core\System\SalesChannel\SalesChannelContext;
15
16
/**
17
 * @internal
18
 */
19
#[Package('checkout')]
20
class PreparedTestPaymentHandler implements PreparedPaymentHandlerInterface
21
{
22
    final public const TEST_STRUCT_CONTENT = ['testValue'];
23
24
    public static ?Struct $preOrderPaymentStruct = null;
25
26
    public static bool $fail = false;
27
28
    public function validate(
29
        Cart $cart,
30
        RequestDataBag $requestDataBag,
31
        SalesChannelContext $context
32
    ): Struct {
33
        if (self::$fail) {
34
            throw new ValidatePreparedPaymentException('this is supposed to fail');
35
        }
36
37
        self::$preOrderPaymentStruct = null;
38
39
        return new ArrayStruct(self::TEST_STRUCT_CONTENT);
40
    }
41
42
    public function capture(
43
        PreparedPaymentTransactionStruct $transaction,
44
        RequestDataBag $requestDataBag,
45
        SalesChannelContext $context,
46
        Struct $preOrderPaymentStruct
47
    ): void {
48
        if (self::$fail) {
49
            throw PaymentException::capturePreparedException($transaction->getOrderTransaction()->getId(), 'this is supposed to fail');
50
        }
51
52
        self::$preOrderPaymentStruct = $preOrderPaymentStruct;
53
    }
54
}
55