Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getRefundPaymentHandler example
$sync
=
$registry
->
getSyncPaymentHandler
(
$this
->ids->
get
(
SynchronousPaymentHandlerInterface::
class
)
)
;
static
::
assertInstanceOf
(
SynchronousPaymentHandlerInterface::
class
,
$sync
)
;
$async
=
$registry
->
getAsyncPaymentHandler
(
$this
->ids->
get
(
AsynchronousPaymentHandlerInterface::
class
)
)
;
static
::
assertInstanceOf
(
AsynchronousPaymentHandlerInterface::
class
,
$async
)
;
$prepared
=
$registry
->
getPreparedPaymentHandler
(
$this
->ids->
get
(
PreparedPaymentHandlerInterface::
class
)
)
;
static
::
assertInstanceOf
(
PreparedPaymentHandlerInterface::
class
,
$prepared
)
;
$refund
=
$registry
->
getRefundPaymentHandler
(
$this
->ids->
get
(
RefundPaymentHandlerInterface::
class
)
)
;
static
::
assertInstanceOf
(
RefundPaymentHandlerInterface::
class
,
$refund
)
;
$recurring
=
$registry
->
getRecurringPaymentHandler
(
$this
->ids->
get
(
RecurringPaymentHandlerInterface::
class
)
)
;
static
::
assertInstanceOf
(
RecurringPaymentHandlerInterface::
class
,
$recurring
)
;
$foo
=
$registry
->
getRecurringPaymentHandler
(
Uuid::
randomHex
(
)
)
;
static
::
assertNull
(
$foo
)
;
}
public
function
testPaymentRegistryWithoutServices
(
)
: void
{
->
fetchAssociative
(
)
;
if
(
!
$result
|| !\
array_key_exists
(
'technical_name',
$result
)
|| !\
array_key_exists
(
'payment_method_id',
$result
)
)
{
throw
PaymentException::
unknownRefund
(
$refundId
)
;
}
if
(
$result
[
'technical_name'
]
!== OrderTransactionCaptureRefundStates::STATE_OPEN
)
{
throw
PaymentException::
refundInvalidTransition
(
$refundId
,
$result
[
'technical_name'
]
)
;
}
$paymentMethodId
= Uuid::
fromBytesToHex
(
$result
[
'payment_method_id'
]
)
;
$refundHandler
=
$this
->paymentHandlerRegistry->
getRefundPaymentHandler
(
$paymentMethodId
)
;
if
(
!
$refundHandler
instanceof RefundPaymentHandlerInterface
)
{
throw
PaymentException::
unknownRefundHandler
(
$refundId
)
;
}
try
{
$refundHandler
->
refund
(
$refundId
,
$context
)
;
}
catch
(
RefundException|PaymentException
$e
)
{
$this
->stateHandler->
fail
(
$refundId
,
$context
)
;
throw
$e
;
}
}
/** * @param array<class-string<PaymentHandlerInterface>> $handlerInstances * * @dataProvider paymentMethodDataProvider */
public
function
testGetRefundHandler
(
string
$handlerName
, string
$handlerClass
, array
$handlerInstances
)
: void
{
$paymentMethod
=
$this
->
getPaymentMethod
(
$handlerName
)
;
$handler
=
$this
->paymentHandlerRegistry->
getRefundPaymentHandler
(
$paymentMethod
->
getId
(
)
)
;
if
(
\
in_array
(
RefundPaymentHandlerInterface::
class
,
$handlerInstances
, true
)
)
{
static
::
assertInstanceOf
(
RefundPaymentHandlerInterface::
class
,
$handler
)
;
}
else
{
static
::
assertNull
(
$handler
)
;
}
}
/** * @dataProvider appPaymentMethodUrlProvider * * @param array<string, mixed> $appPaymentData * @param class-string<object> $expectedHandler */