Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
recurringInterrupted example
->
method
(
'get'
)
->
with
(
OrderTransactionStates::STATE_MACHINE
)
->
willReturn
(
'initial_state_id'
)
;
$struct
=
new
RecurringPaymentTransactionStruct
(
$transaction
,
$order
)
;
$handler
=
$this
->
createMock
(
RecurringPaymentHandlerInterface::
class
)
;
$handler
->
expects
(
static
::
once
(
)
)
->
method
(
'captureRecurring'
)
->
with
(
$struct
, Context::
createDefaultContext
(
)
)
->
willThrowException
(
PaymentException::
recurringInterrupted
(
$transaction
->
getId
(
)
, 'error_foo'
)
)
;
$registry
=
$this
->
createMock
(
PaymentHandlerRegistry::
class
)
;
$registry
->
expects
(
static
::
once
(
)
)
->
method
(
'getRecurringPaymentHandler'
)
->
with
(
'foo'
)
->
willReturn
(
$handler
)
;
$stateHandler
=
$this
->
createMock
(
OrderTransactionStateHandler::
class
)
;
$stateHandler
->
expects
(
static
::
once
(
)
)
public
function
captureRecurring
(
RecurringPaymentTransactionStruct
$transaction
, Context
$context
)
: void
{
$recurringUrl
=
$this
->
getAppPaymentMethod
(
$transaction
->
getOrderTransaction
(
)
)
->
getRecurringUrl
(
)
;
if
(
empty
(
$recurringUrl
)
)
{
return
;
}
$payload
=
$this
->
buildRecurringPayload
(
$transaction
)
;
$app
=
$this
->
getAppPaymentMethod
(
$transaction
->
getOrderTransaction
(
)
)
->
getApp
(
)
;
if
(
$app
=== null
)
{
throw
PaymentException::
recurringInterrupted
(
$transaction
->
getOrderTransaction
(
)
->
getId
(
)
, 'App not defined'
)
;
}
try
{
$response
=
$this
->payloadService->
request
(
$recurringUrl
,
$payload
,
$app
, RecurringPayResponse::
class
,
$context
)
;
}
catch
(
ClientExceptionInterface
$exception
)
{
throw
PaymentException::
recurringInterrupted
(
$transaction
->
getOrderTransaction
(
)
->
getId
(
)
,
sprintf
(
'App error: %s',
$exception
->
getMessage
(
)
)
)
;
}
if
(
!
$response
instanceof RecurringPayResponse
)
{
throw
PaymentException::
recurringInterrupted
(
$transaction
->
getOrderTransaction
(
)
->
getId
(
)
, 'Invalid app response'
)
;
}