stuff (#37)
Co-authored-by: Jan Klattenhoff <jan@kjan.email> Reviewed-on: #37
This commit is contained in:
@ -4,19 +4,16 @@ namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\Payment;
|
||||
use App\Enum\TicketData;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use App\Form\TicketType;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TelephoneField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
use App\Form\TicketType;
|
||||
|
||||
class CustomerCrudController extends AbstractCrudController
|
||||
{
|
||||
|
@ -9,6 +9,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
|
||||
|
||||
class PaymentCrudController extends AbstractCrudController
|
||||
{
|
||||
@ -23,6 +24,8 @@ class PaymentCrudController extends AbstractCrudController
|
||||
->setCrudController(CustomerCrudController::class)
|
||||
->formatValue(fn($value, $payment) => $payment->getCustomer()->getEmail());
|
||||
yield BooleanField::new('completed', 'Bezahlt')->renderAsSwitch(false);
|
||||
yield NumberField::new('donation', 'Spende')
|
||||
->formatValue(fn (?float $donation) => ($donation??'0').'€');
|
||||
}
|
||||
|
||||
public function configureActions(Actions $actions): Actions
|
||||
|
@ -9,6 +9,7 @@ class PersonalData
|
||||
public string $lastname,
|
||||
public string $email,
|
||||
public string $phone,
|
||||
public ?float $donation,
|
||||
) {
|
||||
}
|
||||
}
|
@ -24,6 +24,9 @@ class Payment
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Customer $customer = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?float $donation = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@ -71,4 +74,16 @@ class Payment
|
||||
return $total + TicketData::TICKET_DATA[$ticket->getType()]['price'];
|
||||
}, 0);
|
||||
}
|
||||
|
||||
public function getDonation(): ?float
|
||||
{
|
||||
return $this->donation;
|
||||
}
|
||||
|
||||
public function setDonation(?float $donation): static
|
||||
{
|
||||
$this->donation = $donation;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ class TicketService
|
||||
|
||||
public function handleTicketData(TicketFormData $data): Session
|
||||
{
|
||||
$session = $this->createSession($this->getLineItems($data->tickets), $data->personal->email);
|
||||
$session = $this->createSession($this->getLineItems($data->tickets, $data->personal->donation), $data->personal->email);
|
||||
|
||||
$this->saveTicketData($data, $session->id);
|
||||
|
||||
@ -57,16 +57,30 @@ class TicketService
|
||||
$payment = (new Payment())
|
||||
->setSessionId($sessionId)
|
||||
->setCompleted(false)
|
||||
->setCustomer($this->createEntityFromData($data));
|
||||
->setCustomer($this->createEntityFromData($data))
|
||||
->setDonation($data->personal->donation);
|
||||
|
||||
$this->em->persist($payment);
|
||||
$this->em->flush();
|
||||
}
|
||||
|
||||
private function getLineItems(array $tickets): array
|
||||
private function getLineItems(array $tickets, float $donation = null): array
|
||||
{
|
||||
$lineItems = [];
|
||||
|
||||
if ($donation) {
|
||||
$lineItems[] = [
|
||||
'price_data' => [
|
||||
'currency' => 'eur',
|
||||
'product_data' => [
|
||||
'name' => 'Spende',
|
||||
],
|
||||
'unit_amount' => $donation * 100,
|
||||
],
|
||||
'quantity' => 1,
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($tickets as $ticket) {
|
||||
$ticketData = TicketEnum::TICKET_DATA[$ticket->ticketType];
|
||||
$lineItems[] = [
|
||||
|
Reference in New Issue
Block a user