|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\App\Controllers\Donation; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use WMDE\Euro\Euro; |
|
10
|
|
|
use WMDE\Fundraising\DonationContext\Domain\Model\DonationTrackingInfo; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\App\Routes; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\Validation\FallbackRequestValueReader; |
|
14
|
|
|
|
|
15
|
|
|
class NewDonationController { |
|
16
|
|
|
|
|
17
|
|
|
public function index( FunFunFactory $ffFactory, Request $request ): Response { |
|
18
|
|
|
$ffFactory->getTranslationCollector()->addTranslationFile( |
|
19
|
|
|
$ffFactory->getI18nDirectory() . '/messages/paymentTypes.json' |
|
20
|
|
|
); |
|
21
|
|
|
|
|
22
|
|
|
// TODO Remove LegacyValueReader after January 2021 |
|
23
|
|
|
$legacyValueReader = new FallbackRequestValueReader( $ffFactory->getLogger(), $request ); |
|
24
|
|
|
try { |
|
25
|
|
|
$amount = Euro::newFromCents( intval( $request->get( 'amount', $legacyValueReader->getAmount() ) ) ); |
|
26
|
|
|
} |
|
27
|
|
|
catch ( \InvalidArgumentException $ex ) { |
|
28
|
|
|
$amount = Euro::newFromCents( 0 ); |
|
29
|
|
|
} |
|
30
|
|
|
$paymentType = (string)$request->get( 'paymentType', $legacyValueReader->getPaymentType() ); |
|
31
|
|
|
$interval = $request->get( 'interval', $legacyValueReader->getInterval() ); |
|
32
|
|
|
if ( $interval !== null ) { |
|
33
|
|
|
$interval = intval( $interval ); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$validationResult = $ffFactory->newPaymentDataValidator()->validate( $amount, $paymentType ); |
|
37
|
|
|
|
|
38
|
|
|
$trackingInfo = new DonationTrackingInfo(); |
|
39
|
|
|
$trackingInfo->setTotalImpressionCount( intval( $request->get( 'impCount' ) ) ); |
|
40
|
|
|
$trackingInfo->setSingleBannerImpressionCount( intval( $request->get( 'bImpCount' ) ) ); |
|
41
|
|
|
|
|
42
|
|
|
return new Response( |
|
43
|
|
|
$ffFactory->newDonationFormPresenter()->present( |
|
44
|
|
|
$amount, |
|
45
|
|
|
$paymentType, |
|
46
|
|
|
$interval, |
|
47
|
|
|
$validationResult->isSuccessful(), |
|
48
|
|
|
$trackingInfo, |
|
49
|
|
|
$request->get( 'addressType', $ffFactory->getAddressType() ), |
|
50
|
|
|
Routes::getNamedRouteUrls( $ffFactory->getUrlGenerator() ) |
|
51
|
|
|
) |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|