<?php
declare(strict_types=1);
namespace App\Domain\Entity;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Application\ApiResources\State\Provider\PaymentExportListProvider;
use App\Application\ApiResources\State\Provider\PaymentGetListProvider;
use App\Application\ApiResources\State\Provider\PaymentSucceededSumProvider;
use App\Application\Controller\Api\Payment\GeneratePromotionalOfferAction;
use App\Application\Controller\Api\Payment\GetPdfAction;
use App\Application\Controller\Api\Payment\PremiumApplePayPaymentAction;
use App\Application\Controller\Api\Payment\PremiumGooglePayPaymentAction;
use App\Application\Controller\Api\Payment\RefundKeepPremiumAction;
use App\Application\Controller\Api\Payment\RefundRemovePremiumAction;
use App\Application\Dto\Payment\SumOutput;
use App\Domain\Entity\Behavior\Identifiable;
use DateTime;
/**
* Class Payment
*
* @package App\Domain\Entity
*/
#[ApiResource(
operations: [
new GetCollection(
uriTemplate: '/payments/export',
formats: ['csv' => ['text/csv']],
security: "is_granted('ROLE_ADMIN')",
provider: PaymentExportListProvider::class
),
new GetCollection(security: "is_granted('ROLE_ADMIN')", provider: PaymentGetListProvider::class),
new Get(
uriTemplate: "/payments/succeeded-sum",
security: "is_granted('ROLE_ADMIN')",
output: SumOutput::class,
provider: PaymentSucceededSumProvider::class,
),
new Get(
uriTemplate: "/payments/{uuid}/refund-remove",
controller: RefundRemovePremiumAction::class,
security: "is_granted('ROLE_ADMIN')",
deserialize: true,
name: 'payment_refund_remove',
),
new Get(
uriTemplate: '/payments/{uuid}/pdf',
formats: ['pdf' => ['application/pdf']],
controller: GetPdfAction::class,
),
new Get(
uriTemplate: '/payments/{uuid}',
security: "is_granted('ROLE_ADMIN')",
),
new Get(
uriTemplate: "/payments/{uuid}/refund-keep",
controller: RefundKeepPremiumAction::class,
security: "is_granted('ROLE_ADMIN')",
deserialize: true,
name: 'payment_refund_keep',
),
new Put(security: "is_granted('ROLE_ADMIN')"),
new Post(
uriTemplate: '/payments/account_premium/apple_pay',
controller: PremiumApplePayPaymentAction::class,
deserialize: false,
),
new Post(
uriTemplate: '/payments/account_premium/google_pay',
controller: PremiumGooglePayPaymentAction::class,
deserialize: false,
),
new Post(
uriTemplate: '/payments/apple/generate-promotional-offer',
controller: GeneratePromotionalOfferAction::class,
deserialize: true,
security: "is_granted('ROLE_USER')",
name: 'payment_apple_generate_promotional_offer',
input: ['class' => 'App\\Application\\Dto\\Payment\\PromotionalOfferInput'],
),
],
normalizationContext: ['groups' => ['payment_read']],
denormalizationContext: ['groups' => ['payment_write']],
)]
class Payment
{
use Identifiable;
public const ACTION_REFUND_KEEP_PREMIUM = 'action_refund_keep_premium';
public const ACTION_REFUND_REMOVE_PREMIUM = 'action_refund_remove_premium';
public const PAYMENT_APPLE_PAY = 'apple';
public const PAYMENT_GOOGLE_PAY = 'google';
public const PAYMENT_WEB = 'web';
public const PAYMENT_PROMO_CODE = 'promo';
public const PAYMENT_CANCELED = 'canceled';
public const PAYMENT_EXPIRED = 'expired';
public const PAYMENT_RENEWED = 'renewed';
public const PAYMENT_REFUNDED = 'refunded';
public const PAYMENT_REPLACED = 'replaced';
public const PREMIUM_CHANGED = 'premium_changed';
public const TYPE_ACCOUNT_PREMIUM = 'account_premium';
public const TYPE_ACTIVITY_PRO = 'activity_pro';
public const TYPE_POI_DISCOVERY = 'poi_discovery';
public const GOOGLE_PAY_UNSPECIFIED_STATE = 0;
public const GOOGLE_PAY_SUCCESS_STATE = 1;
public const GOOGLE_PAY_FREE_TRIAL_STATE = 2;
public const GOOGLE_PAY_NOT_CONSUMED_STATE = 0;
public const GOOGLE_PAY_CONSUMED_STATE = 1;
public const PREMIUM_ANNUAL_PRICE = 17.99;
public const PREMIUM_ANNUAL_PRICE_PROMO = 14.99;
public const PREMIUM_MONTHLY_PRICE = 4.99;
public function __construct(
public string $type,
public int $amount,
public string $currency,
public string $eventType,
public Person $person,
public string $locale,
public string $device = self::PAYMENT_WEB,
public ?string $invoiceId = null,
public ?string $intentId = null,
public ?string $chargeId = null,
public ?string $status = null,
public ?string $message = null,
public ?string $object = null,
public ?string $data = null,
public ?int $duration = null,
public ?DateTime $createdAt = null,
public ?DateTime $updatedAt = null,
public ?DateTime $canceledAt = null,
public ?DateTime $startAt = null,
public ?DateTime $endAt = null,
public ?Activity $activity = null,
public ?PointOfInterest $pointOfInterest = null,
public ?PromoCode $promoCode = null,
public ?bool $removedPremium = null,
public ?string $purchaseToken = null,
public ?string $productId = null,
public ?string $subscriptionType = null,
public ?int $paywallId = null,
) {}
/**
* @return string
*/
public function getData(): string
{
return json_encode($this->data);
}
public function getEuros(): float
{
return $this->amount / 100.0;
}
public function getPurchaseToken(): ?string
{
return $this->purchaseToken;
}
}