|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\App\Controllers; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use WMDE\Euro\Euro; |
|
10
|
|
|
use WMDE\Fundraising\DonationContext\UseCases\CreditCardPaymentNotification\CreditCardPaymentNotificationRequest; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\Factories\FunFunFactory; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @license GNU GPL v2+ |
|
15
|
|
|
*/ |
|
16
|
|
|
class CreditCardPaymentNotificationController { |
|
17
|
|
|
|
|
18
|
2 |
|
public function handleNotification( FunFunFactory $ffFactory, Request $request ): Response { |
|
19
|
2 |
|
$donationId = $request->query->get( 'donation_id', '' ); |
|
20
|
|
|
|
|
21
|
2 |
|
$response = $ffFactory->newCreditCardNotificationUseCase( $request->query->get( 'utoken', '' ) ) |
|
22
|
2 |
|
->handleNotification( |
|
23
|
2 |
|
( new CreditCardPaymentNotificationRequest() ) |
|
24
|
2 |
|
->setTransactionId( $request->query->get( 'transactionId', '' ) ) |
|
25
|
2 |
|
->setDonationId( (int)$donationId ) |
|
26
|
2 |
|
->setAmount( Euro::newFromCents( (int)$request->query->get( 'amount' ) ) ) |
|
27
|
2 |
|
->setCustomerId( $request->query->get( 'customerId', '' ) ) |
|
28
|
2 |
|
->setSessionId( $request->query->get( 'sessionId', '' ) ) |
|
29
|
2 |
|
->setAuthId( $request->query->get( 'auth', '' ) ) |
|
30
|
2 |
|
->setTitle( $request->query->get( 'title', '' ) ) |
|
31
|
2 |
|
->setCountry( $request->query->get( 'country', '' ) ) |
|
32
|
2 |
|
->setCurrency( $request->query->get( 'currency', '' ) ) |
|
33
|
|
|
); |
|
34
|
|
|
|
|
35
|
2 |
|
$loggingContext = $response->getLowLevelError() === null ? [] : [ 'exception' => $response->getLowLevelError() ]; |
|
36
|
2 |
|
if ( !$response->isSuccessful() ) { |
|
37
|
1 |
|
$ffFactory->getLogger()->error( 'Credit Card Notification Error: ' . $response->getErrorMessage(), $loggingContext ); |
|
38
|
1 |
|
} elseif ( $loggingContext !== [] ) { |
|
39
|
|
|
$ffFactory->getLogger()->warning( 'Failed to send conformation email for credit card notification', $loggingContext ); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
return new Response( $ffFactory->newCreditCardNotificationPresenter()->present( |
|
43
|
2 |
|
$response, |
|
44
|
2 |
|
$donationId, |
|
45
|
2 |
|
$request->query->get( 'token', '' ) |
|
46
|
|
|
) ); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
} |