|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Paypal; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
7
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
9
|
|
|
use Exception; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ConnectController |
|
13
|
|
|
* @package App\Controller\Paypal |
|
14
|
|
|
* |
|
15
|
|
|
* @Route("/paypal/connect", name="paypal-connect-") |
|
16
|
|
|
*/ |
|
17
|
|
|
class ConnectController extends AbstractController |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @Route("/", name="index", methods={"GET"}) |
|
21
|
|
|
* |
|
22
|
|
|
* @return Response |
|
23
|
|
|
*/ |
|
24
|
|
|
public function index() |
|
25
|
|
|
{ |
|
26
|
|
|
if ($this->paypalService->getSessionService()->isActive()) { |
|
27
|
|
|
return $this->render('paypal/connect/authenticated.html.twig'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return $this->render('paypal/connect/authenticate.html.twig'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @Route("/auth-token", name="auth-token", methods={"POST"}) |
|
35
|
|
|
* |
|
36
|
|
|
* @return Response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function authToken() |
|
39
|
|
|
{ |
|
40
|
|
|
$request = Request::createFromGlobals(); |
|
41
|
|
|
$authToken = $request->request->get('auth_token'); |
|
42
|
|
|
if ($authToken) { |
|
43
|
|
|
$openIdTokeninfo = $this->paypalService->getIdentityService()->getAccessTokenFromAuthToken($authToken); |
|
44
|
|
View Code Duplication |
if ($openIdTokeninfo) { |
|
|
|
|
|
|
45
|
|
|
return $this->render('default/dump-input-id.html.twig', [ |
|
46
|
|
|
'raw_result' => false, |
|
47
|
|
|
'result' => $openIdTokeninfo, |
|
48
|
|
|
'result_id' => $openIdTokeninfo->getRefreshToken() |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @Route("/login", name="login", methods={"POST"}) |
|
56
|
|
|
* @return RedirectResponse|Response |
|
57
|
|
|
*/ |
|
58
|
|
|
public function login() |
|
59
|
|
|
{ |
|
60
|
|
|
$request = Request::createFromGlobals(); |
|
61
|
|
|
$refreshToken = $request->request->get('refresh_token', null); |
|
62
|
|
|
if ($refreshToken) { |
|
63
|
|
|
$userInfo = $this->paypalService->getIdentityService()->getUserInfoFromRefreshToken($refreshToken); |
|
64
|
|
|
if ($userInfo) { |
|
65
|
|
|
$this->paypalService->getSessionService()->login($userInfo, $refreshToken); |
|
66
|
|
|
return $this->render('default/dump-input-id.html.twig', [ |
|
67
|
|
|
'raw_result' => false, |
|
68
|
|
|
'result' => $userInfo, |
|
69
|
|
|
'result_id' => $userInfo->getEmail() |
|
70
|
|
|
]); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @Route("/logout", name="logout", methods={"GET"}) |
|
77
|
|
|
* |
|
78
|
|
|
* @return RedirectResponse |
|
79
|
|
|
*/ |
|
80
|
|
|
public function logout() |
|
81
|
|
|
{ |
|
82
|
|
|
$this->paypalService->getSessionService()->logout(); |
|
83
|
|
|
return $this->redirectToRoute('paypal-connect-index'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @Route("/transactions", name="transactions", methods={"GET"}) |
|
88
|
|
|
* |
|
89
|
|
|
* @return Response | RedirectResponse |
|
90
|
|
|
*/ |
|
91
|
|
|
public function myAccount() |
|
92
|
|
|
{ |
|
93
|
|
|
$refreshToken = $this->paypalService->getSessionService()->getRefreshToken(); |
|
94
|
|
|
$myTransactions = $this->paypalService |
|
95
|
|
|
->getReportingService() |
|
96
|
|
|
->getUserTransactionsFromRefreshToken($refreshToken); |
|
97
|
|
|
if ($myTransactions) { |
|
98
|
|
|
return $this->render('default/dump.html.twig', [ |
|
99
|
|
|
'raw_result' => false, |
|
100
|
|
|
'result' => $myTransactions, |
|
101
|
|
|
]); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
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.