* list only user groups with enabled services in create and edit service forms * feat: add platform membership payment (wip) * WIP * revert mollie api key * remove all option for visibility in services forms * add quit platform membership * remove quit platform feature * fix good route name for payment * fix review * fix review 2
65 lines
2.1 KiB
PHP
Executable file
65 lines
2.1 KiB
PHP
Executable file
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Payment\Group;
|
|
|
|
use App\Controller\User\MyAccountAction;
|
|
use App\Entity\User;
|
|
use App\Payment\PayumManager;
|
|
use App\Repository\GroupOfferRepository;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Routing\Requirement\Requirement;
|
|
use Symfony\Component\Security\Http\Attribute\CurrentUser;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
|
|
/**
|
|
* @see PrepareActionTest
|
|
*/
|
|
#[IsGranted(User::ROLE_USER)]
|
|
final class PrepareAction extends AbstractController
|
|
{
|
|
use GroupOfferTrait;
|
|
|
|
public const ROUTE_NAME = 'app_payment_prepare';
|
|
|
|
public function __construct(
|
|
private readonly GroupOfferRepository $groupOfferRepository,
|
|
private readonly PayumManager $payumManager,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @see https://github.com/Payum/Payum/blob/master/docs/symfony/get-it-started.md#prepare-order)
|
|
*/
|
|
#[Route(
|
|
path: MyAccountAction::BASE_URL_EN.'/payment/{id}/prepare',
|
|
name: self::ROUTE_NAME,
|
|
requirements: ['id' => Requirement::UUID_V6],
|
|
methods: ['POST'],
|
|
)]
|
|
public function __invoke(Request $request, string $id, #[CurrentUser] User $user): Response
|
|
{
|
|
$groupOffer = $this->getGroupOffer($id);
|
|
|
|
/** @var ?string $token */
|
|
$token = $request->request->get('token');
|
|
if (!$this->isCsrfTokenValid('payment_prepare', $token)) {
|
|
throw new UnprocessableEntityHttpException('Invalid CSRF token');
|
|
}
|
|
|
|
// create and save the payment main reference
|
|
$payment = $this->payumManager->getPayment($groupOffer, $user);
|
|
|
|
// create the capture token and redirect to the capture action
|
|
$captureToken = $this->payumManager->getCaptureToken($payment, DoneAction::ROUTE_NAME, [
|
|
'id' => $id,
|
|
]);
|
|
|
|
return $this->redirect($captureToken->getTargetUrl());
|
|
}
|
|
}
|