1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller\Paypal; |
4
|
|
|
|
5
|
|
|
use Adyen\AdyenException; |
6
|
|
|
use App\Service\AdyenService; |
7
|
|
|
use App\Service\PaypalService; |
8
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class AdyenController |
16
|
|
|
* @package App\Controller\Paypal |
17
|
|
|
* |
18
|
|
|
* @Route("/paypal/adyen", name="paypal-adyen-") |
19
|
|
|
*/ |
20
|
|
|
class AdyenController extends AbstractController |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var AdyenService |
24
|
|
|
*/ |
25
|
|
|
protected $adyenService; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* AdyenController constructor. |
29
|
|
|
* @param PaypalService $paypalService |
30
|
|
|
* @param AdyenService $adyenService |
31
|
|
|
*/ |
32
|
|
|
public function __construct(PaypalService $paypalService, AdyenService $adyenService) |
33
|
|
|
{ |
34
|
|
|
$this->adyenService = $adyenService; |
35
|
|
|
parent::__construct($paypalService); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @Route("/", name="index", methods={"GET"}) |
40
|
|
|
* @return Response | RedirectResponse |
41
|
|
|
* @throws AdyenException |
42
|
|
|
*/ |
43
|
|
|
public function index() |
44
|
|
|
{ |
45
|
|
|
$paymentMethods = $this->adyenService->getPaymentMethods(); |
46
|
|
|
$clientKey = $this->adyenService->getClientKey(); |
47
|
|
|
$paypalId = $this->adyenService->getPayPalId(); |
48
|
|
|
return $this->render('paypal/adyen/index.html.twig', [ |
49
|
|
|
'paymentMethods' => $paymentMethods, |
50
|
|
|
'clientKey' => $clientKey, |
51
|
|
|
'paypalId' => $paypalId, |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @Route("/make-payment", name="make-payment", methods={"POST"}) |
57
|
|
|
* @return JsonResponse |
58
|
|
|
* @throws AdyenException |
59
|
|
|
*/ |
60
|
|
|
public function makePayment() |
61
|
|
|
{ |
62
|
|
|
$request = Request::createFromGlobals(); |
63
|
|
|
$paymentData = $request->request->all(); |
64
|
|
|
$action = $this->adyenService->makePayment($paymentData); |
65
|
|
|
|
66
|
|
|
return new JsonResponse($action); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @Route("/payment-details", name="payment-details", methods={"POST"}) |
71
|
|
|
* @return Response |
72
|
|
|
* @throws AdyenException |
73
|
|
|
*/ |
74
|
|
View Code Duplication |
public function paymentDetails() |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
$request = Request::createFromGlobals(); |
77
|
|
|
$paymentData = $request->request->all(); |
78
|
|
|
$paymentDetails = $this->adyenService->paymentDetails($paymentData); |
79
|
|
|
|
80
|
|
|
return $this->render('default/dump.html.twig', [ |
81
|
|
|
'result' => $paymentDetails, |
82
|
|
|
'raw_result' => false, |
83
|
|
|
]); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.