Passed
Push — trunk ( 2ef630...41af6c )
by Christian
10:02 queued 15s
created

OrderException::missingOrderNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Shopware\Core\Checkout\Order;
4
5
use Shopware\Core\Checkout\Customer\Exception\CustomerAuthThrottledException;
6
use Shopware\Core\Framework\HttpException;
7
use Shopware\Core\Framework\Log\Package;
8
use Shopware\Core\Framework\ShopwareHttpException;
9
use Symfony\Component\HttpFoundation\Response;
10
11
#[Package('customer-order')]
12
class OrderException extends HttpException
13
{
14
    final public const ORDER_MISSING_ORDER_ASSOCIATION_CODE = 'CHECKOUT__ORDER_MISSING_ORDER_ASSOCIATION';
15
    final public const ORDER_ORDER_DELIVERY_NOT_FOUND_CODE = 'CHECKOUT__ORDER_ORDER_DELIVERY_NOT_FOUND';
16
    final public const ORDER_ORDER_NOT_FOUND_CODE = 'CHECKOUT__ORDER_ORDER_NOT_FOUND';
17
    final public const ORDER_MISSING_ORDER_NUMBER_CODE = 'CHECKOUT__ORDER_MISSING_ORDER_NUMBER';
18
    final public const ORDER_ORDER_TRANSACTION_NOT_FOUND_CODE = 'CHECKOUT__ORDER_ORDER_TRANSACTION_NOT_FOUND';
19
    final public const ORDER_ORDER_ALREADY_PAID_CODE = 'CHECKOUT__ORDER_ORDER_ALREADY_PAID';
20
    final public const ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION_CODE = 'CHECKOUT__ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION';
21
    final public const ORDER_PAYMENT_METHOD_NOT_CHANGEABLE_CODE = 'CHECKOUT__ORDER_PAYMENT_METHOD_NOT_CHANGEABLE';
22
23
    final public const ORDER_CUSTOMER_NOT_LOGGED_IN = 'CHECKOUT__ORDER_CUSTOMER_NOT_LOGGED_IN';
24
25
    public static function missingAssociation(string $association): self
26
    {
27
        return new self(
28
            Response::HTTP_BAD_REQUEST,
29
            self::ORDER_MISSING_ORDER_ASSOCIATION_CODE,
30
            'The required association "{{ association }}" is missing .',
31
            ['association' => $association]
32
        );
33
    }
34
35
    public static function orderDeliveryNotFound(string $id): self
36
    {
37
        return new self(
38
            Response::HTTP_NOT_FOUND,
39
            self::ORDER_ORDER_DELIVERY_NOT_FOUND_CODE,
40
            'Order delivery with id {{ id }} not found.',
41
            ['id' => $id]
42
        );
43
    }
44
45
    public static function canNotRecalculateLiveVersion(string $orderId): self
46
    {
47
        return new self(
48
            Response::HTTP_BAD_REQUEST,
49
            self::ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION_CODE,
50
            'Order with id {{ orderId }} can not be recalculated because it is in the live version. Please create a new version',
51
            ['orderId' => $orderId]
52
        );
53
    }
54
55
    public static function orderTransactionNotFound(string $id): self
56
    {
57
        return new self(
58
            Response::HTTP_NOT_FOUND,
59
            self::ORDER_ORDER_TRANSACTION_NOT_FOUND_CODE,
60
            'Order transaction with id {{ id }} not found.',
61
            ['id' => $id]
62
        );
63
    }
64
65
    public static function orderAlreadyPaid(string $orderId): self
66
    {
67
        return new self(
68
            Response::HTTP_BAD_REQUEST,
69
            self::ORDER_ORDER_ALREADY_PAID_CODE,
70
            'Order with id "{{ orderId }}" was already paid and cannot be edited afterwards.',
71
            ['orderId' => $orderId]
72
        );
73
    }
74
75
    public static function paymentMethodNotChangeable(): self
76
    {
77
        return new self(
78
            Response::HTTP_FORBIDDEN,
79
            self::ORDER_PAYMENT_METHOD_NOT_CHANGEABLE_CODE,
80
            'Payment methods of order with current payment transaction type can not be changed.'
81
        );
82
    }
83
84
    public static function orderNotFound(string $orderId): self
85
    {
86
        return new self(
87
            Response::HTTP_NOT_FOUND,
88
            self::ORDER_ORDER_NOT_FOUND_CODE,
89
            'Order with id {{ orderId }} not found.',
90
            ['orderId' => $orderId]
91
        );
92
    }
93
94
    public static function missingOrderNumber(string $orderId): self
95
    {
96
        return new self(
97
            Response::HTTP_BAD_REQUEST,
98
            self::ORDER_MISSING_ORDER_NUMBER_CODE,
99
            'Order with id {{ orderId }} has no order number.',
100
            ['orderId' => $orderId]
101
        );
102
    }
103
104
    public static function customerNotLoggedIn(): self
105
    {
106
        return new self(
107
            Response::HTTP_FORBIDDEN,
108
            self::ORDER_CUSTOMER_NOT_LOGGED_IN,
109
            'Customer is not logged in.',
110
        );
111
    }
112
113
    public static function customerAuthThrottledException(int $waitTime, ?\Throwable $e = null): ShopwareHttpException
114
    {
115
        return new CustomerAuthThrottledException(
116
            $waitTime,
117
            $e
118
        );
119
    }
120
}
121