Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
signResponse example
'https://brokenServer.com',
$appUrl
,
'1.0.0',
'product',
'detail',
[
]
,
's3cr3t',
Random::
getAlphanumericString
(
12
)
,
Uuid::
randomHex
(
)
)
;
$this
->
signResponse
(
'123455'
)
;
static
::
expectException
(
AppException::
class
)
;
$this
->executor->
execute
(
$action
, Context::
createDefaultContext
(
)
)
;
}
public
function
testExecutorReturnMessageWithInvalidResponseFormat
(
)
: void
{
$appUrl
= EnvironmentHelper::
getVariable
(
'APP_URL'
)
;
static
::
assertIsString
(
$appUrl
)
;
$appSecret
= 's3cr3t';
class
AppSyncPaymentHandlerTest
extends
AbstractAppPaymentHandlerTestCase
{
public
function
testPay
(
)
: void
{
$paymentMethodId
=
$this
->
getPaymentMethodId
(
'syncTracked'
)
;
$orderId
=
$this
->
createOrder
(
$paymentMethodId
)
;
$transactionId
=
$this
->
createTransaction
(
$orderId
,
$paymentMethodId
)
;
$salesChannelContext
=
$this
->
getSalesChannelContext
(
$paymentMethodId
)
;
$response
=
new
SyncPayResponse
(
)
;
$this
->
appendNewResponse
(
$this
->
signResponse
(
$response
->
jsonSerialize
(
)
)
)
;
$data
=
new
RequestDataBag
(
[
'foo' => 'bar'
]
)
;
$this
->paymentService->
handlePaymentByOrder
(
$orderId
,
$data
,
$salesChannelContext
)
;
/** @var Request $request */
$request
=
$this
->
getLastRequest
(
)
;
$body
=
$request
->
getBody
(
)
->
getContents
(
)
;
$appSecret
=
$this
->app->
getAppSecret
(
)
;
static
::
assertNotNull
(
$appSecret
)
;
class
AppPreparedPaymentHandlerTest
extends
AbstractAppPaymentHandlerTestCase
{
public
function
testValidate
(
)
: void
{
$paymentMethodId
=
$this
->
getPaymentMethodId
(
'prepared'
)
;
$cart
= Generator::
createCart
(
)
;
$customerId
=
$this
->
createCustomer
(
)
;
$salesChannelContext
=
$this
->
getSalesChannelContext
(
$paymentMethodId
,
$customerId
)
;
$response
= ValidateResponse::
create
(
null,
[
'preOrderPayment' =>
[
'test' => 'response'
]
]
)
;
$this
->
appendNewResponse
(
$this
->
signResponse
(
$response
->
jsonSerialize
(
)
)
)
;
$returnValue
=
$this
->preparedPaymentService->
handlePreOrderPayment
(
$cart
,
new
RequestDataBag
(
)
,
$salesChannelContext
)
;
static
::
assertInstanceOf
(
ArrayStruct::
class
,
$returnValue
)
;
static
::
assertSame
(
[
'test' => 'response'
]
,
$returnValue
->
all
(
)
)
;
/** @var Request $request */
$request
=
$this
->
getLastRequest
(
)
;
$body
=
$request
->
getBody
(
)
->
getContents
(
)
;
$appSecret
=
$this
->app->
getAppSecret
(
)
;
static
::
assertNotNull
(
$appSecret
)
;
$orderId
=
$this
->
createOrder
(
$paymentMethodId
)
;
$transactionId
=
$this
->
createTransaction
(
$orderId
,
$paymentMethodId
)
;
$captureId
=
$this
->
createCapture
(
$transactionId
)
;
$refundId
=
$this
->
createRefund
(
$captureId
)
;
$salesChannelContext
=
$this
->
getSalesChannelContext
(
$paymentMethodId
)
;
$response
= RefundResponse::
create
(
$transactionId
,
[
'status' => 'complete',
]
)
;
$this
->
appendNewResponse
(
$this
->
signResponse
(
$response
->
jsonSerialize
(
)
)
)
;
$this
->paymentRefundProcessor->
processRefund
(
$refundId
,
$salesChannelContext
->
getContext
(
)
)
;
/** @var Request $request */
$request
=
$this
->
getLastRequest
(
)
;
$body
=
$request
->
getBody
(
)
->
getContents
(
)
;
$appSecret
=
$this
->app->
getAppSecret
(
)
;
static
::
assertNotNull
(
$appSecret
)
;
static
::
assertTrue
(
$request
->
hasHeader
(
'shopware-shop-signature'
)
)
;
public
function
testRecurring
(
)
: void
{
$paymentMethodId
=
$this
->
getPaymentMethodId
(
'recurring'
)
;
$orderId
=
$this
->
createOrder
(
$paymentMethodId
)
;
$transactionId
=
$this
->
createTransaction
(
$orderId
,
$paymentMethodId
)
;
$response
= RecurringPayResponse::
create
(
$transactionId
,
[
'status' => OrderTransactionStates::STATE_PAID,
]
)
;
$this
->
appendNewResponse
(
$this
->
signResponse
(
$response
->
jsonSerialize
(
)
)
)
;
$paymentHandler
=
$this
->
getContainer
(
)
->
get
(
AppPaymentHandler::
class
)
;
$paymentHandler
->
captureRecurring
(
$this
->
getRecurringStruct
(
)
, Context::
createDefaultContext
(
)
)
;
/** @var Request $request */
$request
=
$this
->
getLastRequest
(
)
;
$body
=
$request
->
getBody
(
)
->
getContents
(
)
;
$appSecret
=
$this
->app->
getAppSecret
(
)
;
static
::
assertNotNull
(
$appSecret
)
;
public
function
testPayOtherState
(
)
: void
{
$paymentMethodId
=
$this
->
getPaymentMethodId
(
'async'
)
;
$orderId
=
$this
->
createOrder
(
$paymentMethodId
)
;
$transactionId
=
$this
->
createTransaction
(
$orderId
,
$paymentMethodId
)
;
$salesChannelContext
=
$this
->
getSalesChannelContext
(
$paymentMethodId
)
;
$response
=
(
new
AsyncPayResponse
(
)
)
->
assign
(
[
'redirectUrl' => self::REDIRECT_URL,
'status' => StateMachineTransitionActions::ACTION_PAID_PARTIALLY,
]
)
;
$this
->
appendNewResponse
(
$this
->
signResponse
(
$response
->
jsonSerialize
(
)
)
)
;
$this
->paymentService->
handlePaymentByOrder
(
$orderId
,
new
RequestDataBag
(
)
,
$salesChannelContext
)
;
$this
->
assertOrderTransactionState
(
OrderTransactionStates::STATE_PARTIALLY_PAID,
$transactionId
)
;
}
public
function
testPayFailedState
(
)
: void
{
$paymentMethodId
=
$this
->
getPaymentMethodId
(
'async'
)
;
$orderId
=
$this
->
createOrder
(
$paymentMethodId
)
;
$this
->
createTransaction
(
$orderId
,
$paymentMethodId
)
;
$salesChannelContext
=
$this
->
getSalesChannelContext
(
$paymentMethodId
)
;