1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusAdyenPlugin\Controller; |
14
|
|
|
|
15
|
|
|
use Payum\Core\Exception\LogicException; |
16
|
|
|
use Payum\Core\Payum; |
17
|
|
|
use Payum\Core\Request\Notify; |
18
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
19
|
|
|
use Sylius\Component\Core\Repository\PaymentRepositoryInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpFoundation\Response; |
22
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
23
|
|
|
|
24
|
|
|
final class NotifyController |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var Payum |
28
|
|
|
*/ |
29
|
|
|
private $payum; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var PaymentRepositoryInterface |
33
|
|
|
*/ |
34
|
|
|
private $paymentRepository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param Payum $payum |
38
|
|
|
* @param PaymentRepositoryInterface $paymentRepository |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Payum $payum, PaymentRepositoryInterface $paymentRepository) |
41
|
|
|
{ |
42
|
|
|
$this->payum = $payum; |
43
|
|
|
$this->paymentRepository = $paymentRepository; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Request $request |
48
|
|
|
* |
49
|
|
|
* @return Response |
50
|
|
|
* |
51
|
|
|
* @throws \Payum\Core\Reply\ReplyInterface |
52
|
|
|
*/ |
53
|
|
|
public function doAction(Request $request): Response |
54
|
|
|
{ |
55
|
|
|
if (null === $merchantReference = $request->request->get('merchantReference', null)) { |
56
|
|
|
throw new LogicException("A parameter merchantReference not be found."); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$paymentId = 2 === count(explode('-', $merchantReference)) ? |
60
|
|
|
explode('-', $merchantReference)[1] : null |
61
|
|
|
; |
62
|
|
|
|
63
|
|
|
/** @var PaymentInterface $payment */ |
64
|
|
|
$payment = $this->paymentRepository->findOneBy(['id' => $paymentId]); |
65
|
|
|
|
66
|
|
|
if (null === $payment) { |
67
|
|
|
throw new NotFoundHttpException("Payment not found "); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$hash = null !== $payment ? json_decode($payment->getDetails()['extraData'], true)['notifyToken'] : ''; |
71
|
|
|
|
72
|
|
|
if (false === $token = $this->payum->getTokenStorage()->find($hash)) { |
73
|
|
|
throw new NotFoundHttpException(sprintf("A token with hash `%s` could not be found.", $hash)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
$gateway = $this->payum->getGateway($token->getGatewayName()); |
77
|
|
|
|
78
|
|
|
$gateway->execute(new Notify($token)); |
79
|
|
|
|
80
|
|
|
return new Response("[accepted]"); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|