|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Core\Test\Integration\PaymentHandler; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Checkout\Order\Aggregate\OrderTransaction\OrderTransactionStateHandler; |
|
6
|
|
|
use Shopware\Core\Checkout\Payment\Cart\AsyncPaymentTransactionStruct; |
|
7
|
|
|
use Shopware\Core\Checkout\Payment\Cart\PaymentHandler\AsynchronousPaymentHandlerInterface; |
|
8
|
|
|
use Shopware\Core\Checkout\Payment\Exception\CustomerCanceledAsyncPaymentException; |
|
9
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
10
|
|
|
use Shopware\Core\Framework\Validation\DataBag\RequestDataBag; |
|
11
|
|
|
use Shopware\Core\System\SalesChannel\SalesChannelContext; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @internal |
|
17
|
|
|
*/ |
|
18
|
|
|
#[Package('checkout')] |
|
19
|
|
|
class AsyncTestPaymentHandler implements AsynchronousPaymentHandlerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
final public const REDIRECT_URL = 'https://shopware.com'; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct(private readonly OrderTransactionStateHandler $transactionStateHandler) |
|
24
|
|
|
{ |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function pay(AsyncPaymentTransactionStruct $transaction, RequestDataBag $dataBag, SalesChannelContext $salesChannelContext): RedirectResponse |
|
28
|
|
|
{ |
|
29
|
|
|
$context = $salesChannelContext->getContext(); |
|
30
|
|
|
|
|
31
|
|
|
$this->transactionStateHandler->process($transaction->getOrderTransaction()->getId(), $context); |
|
32
|
|
|
|
|
33
|
|
|
return new RedirectResponse(self::REDIRECT_URL); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function finalize( |
|
37
|
|
|
AsyncPaymentTransactionStruct $transaction, |
|
38
|
|
|
Request $request, |
|
39
|
|
|
SalesChannelContext $salesChannelContext |
|
40
|
|
|
): void { |
|
41
|
|
|
$context = $salesChannelContext->getContext(); |
|
42
|
|
|
|
|
43
|
|
|
if ($request->query->getBoolean('cancel')) { |
|
44
|
|
|
throw new CustomerCanceledAsyncPaymentException( |
|
45
|
|
|
$transaction->getOrderTransaction()->getId(), |
|
46
|
|
|
'Async Test Payment canceled' |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->transactionStateHandler->paid($transaction->getOrderTransaction()->getId(), $context); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|