src/Domain/Entity/Payment.php line 91

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\Entity;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Post;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Application\ApiResources\State\Provider\PaymentExportListProvider;
  10. use App\Application\ApiResources\State\Provider\PaymentGetListProvider;
  11. use App\Application\ApiResources\State\Provider\PaymentSucceededSumProvider;
  12. use App\Application\Controller\Api\Payment\GeneratePromotionalOfferAction;
  13. use App\Application\Controller\Api\Payment\GetPdfAction;
  14. use App\Application\Controller\Api\Payment\PremiumApplePayPaymentAction;
  15. use App\Application\Controller\Api\Payment\PremiumGooglePayPaymentAction;
  16. use App\Application\Controller\Api\Payment\RefundKeepPremiumAction;
  17. use App\Application\Controller\Api\Payment\RefundRemovePremiumAction;
  18. use App\Application\Dto\Payment\SumOutput;
  19. use App\Domain\Entity\Behavior\Identifiable;
  20. use DateTime;
  21. /**
  22.  * Class Payment
  23.  *
  24.  * @package App\Domain\Entity
  25.  */
  26. #[ApiResource(
  27.     operations: [
  28.         new GetCollection(
  29.             uriTemplate'/payments/export',
  30.             formats: ['csv' => ['text/csv']],
  31.             security"is_granted('ROLE_ADMIN')",
  32.             providerPaymentExportListProvider::class
  33.         ),
  34.         new GetCollection(security"is_granted('ROLE_ADMIN')"providerPaymentGetListProvider::class),
  35.         new Get(
  36.             uriTemplate"/payments/succeeded-sum",
  37.             security"is_granted('ROLE_ADMIN')",
  38.             outputSumOutput::class,
  39.             providerPaymentSucceededSumProvider::class,
  40.         ),
  41.         new Get(
  42.             uriTemplate"/payments/{uuid}/refund-remove",
  43.             controllerRefundRemovePremiumAction::class,
  44.             security"is_granted('ROLE_ADMIN')",
  45.             deserializetrue,
  46.             name'payment_refund_remove',
  47.         ),
  48.         new Get(
  49.             uriTemplate'/payments/{uuid}/pdf',
  50.             formats: ['pdf' => ['application/pdf']],
  51.             controllerGetPdfAction::class,
  52.         ),
  53.         new Get(
  54.             uriTemplate'/payments/{uuid}',
  55.             security"is_granted('ROLE_ADMIN')",
  56.         ),
  57.         new Get(
  58.             uriTemplate"/payments/{uuid}/refund-keep",
  59.             controllerRefundKeepPremiumAction::class,
  60.             security"is_granted('ROLE_ADMIN')",
  61.             deserializetrue,
  62.             name'payment_refund_keep',
  63.         ),
  64.         new Put(security"is_granted('ROLE_ADMIN')"),
  65.         new Post(
  66.             uriTemplate'/payments/account_premium/apple_pay',
  67.             controllerPremiumApplePayPaymentAction::class,
  68.             deserializefalse,
  69.         ),
  70.         new Post(
  71.             uriTemplate'/payments/account_premium/google_pay',
  72.             controllerPremiumGooglePayPaymentAction::class,
  73.             deserializefalse,
  74.         ),
  75.         new Post(
  76.             uriTemplate'/payments/apple/generate-promotional-offer',
  77.             controllerGeneratePromotionalOfferAction::class,
  78.             deserializetrue,
  79.             security"is_granted('ROLE_USER')",
  80.             name'payment_apple_generate_promotional_offer',
  81.             input: ['class' => 'App\\Application\\Dto\\Payment\\PromotionalOfferInput'],
  82.         ),
  83.     ],
  84.     normalizationContext: ['groups' => ['payment_read']],
  85.     denormalizationContext: ['groups' => ['payment_write']],
  86. )]
  87. class Payment
  88. {
  89.     use Identifiable;
  90.     public const ACTION_REFUND_KEEP_PREMIUM   'action_refund_keep_premium';
  91.     public const ACTION_REFUND_REMOVE_PREMIUM 'action_refund_remove_premium';
  92.     public const PAYMENT_APPLE_PAY  'apple';
  93.     public const PAYMENT_GOOGLE_PAY 'google';
  94.     public const PAYMENT_WEB        'web';
  95.     public const PAYMENT_PROMO_CODE 'promo';
  96.     public const PAYMENT_CANCELED 'canceled';
  97.     public const PAYMENT_EXPIRED 'expired';
  98.     public const PAYMENT_RENEWED 'renewed';
  99.     public const PAYMENT_REFUNDED 'refunded';
  100.     public const PAYMENT_REPLACED 'replaced';
  101.     public const PREMIUM_CHANGED 'premium_changed';
  102.     public const TYPE_ACCOUNT_PREMIUM 'account_premium';
  103.     public const TYPE_ACTIVITY_PRO    'activity_pro';
  104.     public const TYPE_POI_DISCOVERY 'poi_discovery';
  105.     public const GOOGLE_PAY_UNSPECIFIED_STATE 0;
  106.     public const GOOGLE_PAY_SUCCESS_STATE     1;
  107.     public const GOOGLE_PAY_FREE_TRIAL_STATE     2;
  108.     public const GOOGLE_PAY_NOT_CONSUMED_STATE 0;
  109.     public const GOOGLE_PAY_CONSUMED_STATE     1;
  110.     public const PREMIUM_ANNUAL_PRICE 17.99;
  111.     public const PREMIUM_ANNUAL_PRICE_PROMO 14.99;
  112.     public const PREMIUM_MONTHLY_PRICE 4.99;
  113.     public function __construct(
  114.         public string $type,
  115.         public int $amount,
  116.         public string $currency,
  117.         public string $eventType,
  118.         public Person $person,
  119.         public string $locale,
  120.         public string $device self::PAYMENT_WEB,
  121.         public ?string $invoiceId null,
  122.         public ?string $intentId null,
  123.         public ?string $chargeId null,
  124.         public ?string $status null,
  125.         public ?string $message null,
  126.         public ?string $object null,
  127.         public ?string $data null,
  128.         public ?int $duration null,
  129.         public ?DateTime $createdAt null,
  130.         public ?DateTime $updatedAt null,
  131.         public ?DateTime $canceledAt null,
  132.         public ?DateTime $startAt null,
  133.         public ?DateTime $endAt null,
  134.         public ?Activity $activity null,
  135.         public ?PointOfInterest $pointOfInterest null,
  136.         public ?PromoCode $promoCode null,
  137.         public ?bool $removedPremium null,
  138.         public ?string $purchaseToken null,
  139.         public ?string $productId null,
  140.         public ?string $subscriptionType null,
  141.         public ?int $paywallId null,
  142.     ) {}
  143.     /**
  144.      * @return string
  145.      */
  146.     public function getData(): string
  147.     {
  148.         return json_encode($this->data);
  149.     }
  150.     public function getEuros(): float
  151.     {
  152.         return $this->amount 100.0;
  153.     }
  154.     public function getPurchaseToken(): ?string
  155.     {
  156.         return $this->purchaseToken;
  157.     }
  158. }