|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\App\Controllers\Donation; |
|
6
|
|
|
|
|
7
|
|
|
use Silex\Application; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use WMDE\Fundraising\DonationContext\UseCases\GetDonation\GetDonationRequest; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\App\AccessDeniedException; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\App\Routes; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @license GPL-2.0-or-later |
|
17
|
|
|
* @author Kai Nissen < [email protected] > |
|
18
|
|
|
*/ |
|
19
|
|
|
class ShowDonationConfirmationController { |
|
20
|
|
|
|
|
21
|
|
|
public const SUBMISSION_COOKIE_NAME = 'donation_timestamp'; |
|
22
|
|
|
public const TIMESTAMP_FORMAT = 'Y-m-d H:i:s'; |
|
23
|
|
|
|
|
24
|
|
|
public function index( Request $request, FunFunFactory $ffFactory ): Response { |
|
25
|
|
|
$useCase = $ffFactory->newGetDonationUseCase( $request->get( 'accessToken', '' ) ); |
|
26
|
|
|
|
|
27
|
|
|
$responseModel = $useCase->showConfirmation( new GetDonationRequest( |
|
28
|
|
|
(int)$request->get( 'id', '' ) |
|
29
|
|
|
) ); |
|
30
|
|
|
|
|
31
|
|
|
if ( !$responseModel->accessIsPermitted() ) { |
|
32
|
|
|
throw new AccessDeniedException( 'access_denied_donation_confirmation' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$ffFactory->getTranslationCollector()->addTranslationFile( $ffFactory->getI18nDirectory() . '/messages/paymentTypes.json' ); |
|
36
|
|
|
$httpResponse = new Response( |
|
37
|
|
|
$ffFactory->newDonationConfirmationPresenter()->present( |
|
38
|
|
|
$responseModel->getDonation(), |
|
39
|
|
|
$responseModel->getUpdateToken(), |
|
|
|
|
|
|
40
|
|
|
$request->get( 'accessToken', '' ), |
|
41
|
|
|
array_merge( |
|
42
|
|
|
Routes::getNamedRouteUrls( $ffFactory->getUrlGenerator() ), |
|
43
|
|
|
[ |
|
44
|
|
|
'updateDonor' => $ffFactory->getUrlGenerator()->generateAbsoluteUrl( |
|
45
|
|
|
Routes::UPDATE_DONOR, |
|
46
|
|
|
[ |
|
47
|
|
|
'accessToken' => $request->get( 'accessToken', '' ) |
|
48
|
|
|
] |
|
49
|
|
|
) |
|
50
|
|
|
] |
|
51
|
|
|
) |
|
52
|
|
|
) |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
if ( !$request->cookies->get( self::SUBMISSION_COOKIE_NAME ) ) { |
|
56
|
|
|
$cookie = $ffFactory->getCookieBuilder(); |
|
57
|
|
|
$httpResponse->headers->setCookie( |
|
58
|
|
|
$cookie->newCookie( self::SUBMISSION_COOKIE_NAME, date( self::TIMESTAMP_FORMAT ) ) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
return $httpResponse; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|