Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
isPaymentChangeableByTransactionState example
'orderId' =>
$orderId
,
'changedPayment' => true,
]
)
;
/** @var OrderEntity|null $order */
$order
=
$this
->orderRoute->
load
(
$request
,
$context
,
new
Criteria
(
[
$orderId
]
)
)
->
getOrders
(
)
->
first
(
)
;
if
(
$order
=== null
)
{
throw
OrderException::
orderNotFound
(
$orderId
)
;
}
if
(
!
$this
->orderService->
isPaymentChangeableByTransactionState
(
$order
)
)
{
throw
OrderException::
paymentMethodNotChangeable
(
)
;
}
if
(
$context
->
getCurrency
(
)
->
getId
(
)
!==
$order
->
getCurrencyId
(
)
)
{
$this
->contextSwitchRoute->
switchContext
(
new
RequestDataBag
(
[
SalesChannelContextService::CURRENCY_ID =>
$order
->
getCurrencyId
(
)
]
)
,
$context
)
;
$context
=
$this
->contextService->
get
(
new
SalesChannelContextServiceParameters
(
throw
new
EntityNotFoundException
(
'order',
$orderId
)
;
}
return
$order
;
}
/** * @throws PaymentMethodNotChangeableException */
private
function
validatePaymentState
(
OrderEntity
$order
)
: void
{
if
(
$this
->orderService->
isPaymentChangeableByTransactionState
(
$order
)
)
{
return
;
}
throw
new
PaymentMethodNotChangeableException
(
$order
->
getId
(
)
)
;
}
}
$stateMachineState
=
$transaction
->
getStateMachineState
(
)
;
if
(
$stateMachineState
=== null
)
{
return
false;
}
return
$stateMachineState
->
getTechnicalName
(
)
=== OrderTransactionStates::STATE_PAID;
}
private
function
isPaymentChangeable
(
OrderRouteResponse
$orderRouteResponse
, AccountEditOrderPage
$page
)
: bool
{
$isChangeableByResponse
=
$orderRouteResponse
->
getPaymentsChangeable
(
)
[
$page
->
getOrder
(
)
->
getId
(
)
]
?? true;
$isChangeableByTransactionState
=
$this
->orderService->
isPaymentChangeableByTransactionState
(
$page
->
getOrder
(
)
)
;
return
$isChangeableByResponse
&&
$isChangeableByTransactionState
;
}
}