Passed
Push — trunk ( 04b0a9...ad65a5 )
by Christian
24:30 queued 13:01
created

OrderException::paymentMethodNotAvailable()   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
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
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_PAYMENT_METHOD_UNAVAILABLE = 'CHECKOUT__ORDER_PAYMENT_METHOD_NOT_AVAILABLE';
20
    final public const ORDER_ORDER_ALREADY_PAID_CODE = 'CHECKOUT__ORDER_ORDER_ALREADY_PAID';
21
    final public const ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION_CODE = 'CHECKOUT__ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION';
22
    final public const ORDER_PAYMENT_METHOD_NOT_CHANGEABLE_CODE = 'CHECKOUT__ORDER_PAYMENT_METHOD_NOT_CHANGEABLE';
23
24
    final public const ORDER_CUSTOMER_NOT_LOGGED_IN = 'CHECKOUT__ORDER_CUSTOMER_NOT_LOGGED_IN';
25
26
    public static function missingAssociation(string $association): self
27
    {
28
        return new self(
29
            Response::HTTP_BAD_REQUEST,
30
            self::ORDER_MISSING_ORDER_ASSOCIATION_CODE,
31
            'The required association "{{ association }}" is missing .',
32
            ['association' => $association]
33
        );
34
    }
35
36
    public static function orderDeliveryNotFound(string $id): self
37
    {
38
        return new self(
39
            Response::HTTP_NOT_FOUND,
40
            self::ORDER_ORDER_DELIVERY_NOT_FOUND_CODE,
41
            'Order delivery with id {{ id }} not found.',
42
            ['id' => $id]
43
        );
44
    }
45
46
    public static function canNotRecalculateLiveVersion(string $orderId): self
47
    {
48
        return new self(
49
            Response::HTTP_BAD_REQUEST,
50
            self::ORDER_CAN_NOT_RECALCULATE_LIVE_VERSION_CODE,
51
            'Order with id {{ orderId }} can not be recalculated because it is in the live version. Please create a new version',
52
            ['orderId' => $orderId]
53
        );
54
    }
55
56
    public static function orderTransactionNotFound(string $id): self
57
    {
58
        return new self(
59
            Response::HTTP_NOT_FOUND,
60
            self::ORDER_ORDER_TRANSACTION_NOT_FOUND_CODE,
61
            'Order transaction with id {{ id }} not found.',
62
            ['id' => $id]
63
        );
64
    }
65
66
    public static function paymentMethodNotAvailable(string $id): self
67
    {
68
        return new self(
69
            Response::HTTP_NOT_FOUND,
70
            self::ORDER_PAYMENT_METHOD_UNAVAILABLE,
71
            'The payment method with id {{ id }} is not available.',
72
            ['id' => $id]
73
        );
74
    }
75
76
    public static function orderAlreadyPaid(string $orderId): self
77
    {
78
        return new self(
79
            Response::HTTP_BAD_REQUEST,
80
            self::ORDER_ORDER_ALREADY_PAID_CODE,
81
            'Order with id "{{ orderId }}" was already paid and cannot be edited afterwards.',
82
            ['orderId' => $orderId]
83
        );
84
    }
85
86
    public static function paymentMethodNotChangeable(): self
87
    {
88
        return new self(
89
            Response::HTTP_FORBIDDEN,
90
            self::ORDER_PAYMENT_METHOD_NOT_CHANGEABLE_CODE,
91
            'Payment methods of order with current payment transaction type can not be changed.'
92
        );
93
    }
94
95
    public static function orderNotFound(string $orderId): self
96
    {
97
        return new self(
98
            Response::HTTP_NOT_FOUND,
99
            self::ORDER_ORDER_NOT_FOUND_CODE,
100
            'Order with id {{ orderId }} not found.',
101
            ['orderId' => $orderId]
102
        );
103
    }
104
105
    public static function missingOrderNumber(string $orderId): self
106
    {
107
        return new self(
108
            Response::HTTP_BAD_REQUEST,
109
            self::ORDER_MISSING_ORDER_NUMBER_CODE,
110
            'Order with id {{ orderId }} has no order number.',
111
            ['orderId' => $orderId]
112
        );
113
    }
114
115
    public static function customerNotLoggedIn(): self
116
    {
117
        return new self(
118
            Response::HTTP_FORBIDDEN,
119
            self::ORDER_CUSTOMER_NOT_LOGGED_IN,
120
            'Customer is not logged in.',
121
        );
122
    }
123
124
    public static function customerAuthThrottledException(int $waitTime, ?\Throwable $e = null): ShopwareHttpException
125
    {
126
        return new CustomerAuthThrottledException(
127
            $waitTime,
128
            $e
129
        );
130
    }
131
}
132