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