Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace HiEvents\DomainObjects\Generated;

/**
* THIS FILE IS AUTOGENERATED - DO NOT EDIT IT DIRECTLY.
* @package HiEvents\DomainObjects\Generated
*/
abstract class OrderPaymentPlatformFeeDomainObjectAbstract extends \HiEvents\DomainObjects\AbstractDomainObject
{
final public const SINGULAR_NAME = 'order_payment_platform_fee';
final public const PLURAL_NAME = 'order_payment_platform_fees';
final public const ID = 'id';
final public const ORDER_ID = 'order_id';
final public const PAYMENT_PLATFORM = 'payment_platform';
final public const FEE_ROLLUP = 'fee_rollup';
final public const PAYMENT_PLATFORM_FEE_AMOUNT = 'payment_platform_fee_amount';
final public const APPLICATION_FEE_AMOUNT = 'application_fee_amount';
final public const CURRENCY = 'currency';
final public const TRANSACTION_ID = 'transaction_id';
final public const PAID_AT = 'paid_at';
final public const DELETED_AT = 'deleted_at';
final public const CREATED_AT = 'created_at';
final public const UPDATED_AT = 'updated_at';

protected int $id;
protected int $order_id;
protected string $payment_platform;
protected array|string|null $fee_rollup = null;
protected float $payment_platform_fee_amount;
protected float $application_fee_amount = 0.0;
protected string $currency = 'USD';
protected ?string $transaction_id = null;
protected ?string $paid_at = null;
protected ?string $deleted_at = null;
protected ?string $created_at = null;
protected ?string $updated_at = null;

public function toArray(): array
{
return [
'id' => $this->id ?? null,
'order_id' => $this->order_id ?? null,
'payment_platform' => $this->payment_platform ?? null,
'fee_rollup' => $this->fee_rollup ?? null,
'payment_platform_fee_amount' => $this->payment_platform_fee_amount ?? null,
'application_fee_amount' => $this->application_fee_amount ?? null,
'currency' => $this->currency ?? null,
'transaction_id' => $this->transaction_id ?? null,
'paid_at' => $this->paid_at ?? null,
'deleted_at' => $this->deleted_at ?? null,
'created_at' => $this->created_at ?? null,
'updated_at' => $this->updated_at ?? null,
];
}

public function setId(int $id): self
{
$this->id = $id;
return $this;
}

public function getId(): int
{
return $this->id;
}

public function setOrderId(int $order_id): self
{
$this->order_id = $order_id;
return $this;
}

public function getOrderId(): int
{
return $this->order_id;
}

public function setPaymentPlatform(string $payment_platform): self
{
$this->payment_platform = $payment_platform;
return $this;
}

public function getPaymentPlatform(): string
{
return $this->payment_platform;
}

public function setFeeRollup(array|string|null $fee_rollup): self
{
$this->fee_rollup = $fee_rollup;
return $this;
}

public function getFeeRollup(): array|string|null
{
return $this->fee_rollup;
}

public function setPaymentPlatformFeeAmount(float $payment_platform_fee_amount): self
{
$this->payment_platform_fee_amount = $payment_platform_fee_amount;
return $this;
}

public function getPaymentPlatformFeeAmount(): float
{
return $this->payment_platform_fee_amount;
}

public function setApplicationFeeAmount(float $application_fee_amount): self
{
$this->application_fee_amount = $application_fee_amount;
return $this;
}

public function getApplicationFeeAmount(): float
{
return $this->application_fee_amount;
}

public function setCurrency(string $currency): self
{
$this->currency = $currency;
return $this;
}

public function getCurrency(): string
{
return $this->currency;
}

public function setTransactionId(?string $transaction_id): self
{
$this->transaction_id = $transaction_id;
return $this;
}

public function getTransactionId(): ?string
{
return $this->transaction_id;
}

public function setPaidAt(?string $paid_at): self
{
$this->paid_at = $paid_at;
return $this;
}

public function getPaidAt(): ?string
{
return $this->paid_at;
}

public function setDeletedAt(?string $deleted_at): self
{
$this->deleted_at = $deleted_at;
return $this;
}

public function getDeletedAt(): ?string
{
return $this->deleted_at;
}

public function setCreatedAt(?string $created_at): self
{
$this->created_at = $created_at;
return $this;
}

public function getCreatedAt(): ?string
{
return $this->created_at;
}

public function setUpdatedAt(?string $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}

public function getUpdatedAt(): ?string
{
return $this->updated_at;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace HiEvents\DomainObjects;

class OrderPaymentPlatformFeeDomainObject extends Generated\OrderPaymentPlatformFeeDomainObjectAbstract
{
}
5 changes: 0 additions & 5 deletions backend/app/Models/OrderItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ protected function getCastMap(): array
];
}

protected function getFillableFields(): array
{
return [];
}

public function product_price(): HasOne
{
return $this->hasOne(ProductPrice::class);
Expand Down
23 changes: 23 additions & 0 deletions backend/app/Models/OrderPaymentPlatformFee.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace HiEvents\Models;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class OrderPaymentPlatformFee extends BaseModel
{
use SoftDeletes;

protected function getCastMap(): array
{
return [
'fee_rollup' => 'array',
];
}

public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
}
3 changes: 3 additions & 0 deletions backend/app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use HiEvents\Repository\Eloquent\MessageRepository;
use HiEvents\Repository\Eloquent\OrderApplicationFeeRepository;
use HiEvents\Repository\Eloquent\OrderItemRepository;
use HiEvents\Repository\Eloquent\OrderPaymentPlatformFeeRepository;
use HiEvents\Repository\Eloquent\OrderRefundRepository;
use HiEvents\Repository\Eloquent\OrderRepository;
use HiEvents\Repository\Eloquent\OrganizerRepository;
Expand Down Expand Up @@ -62,6 +63,7 @@
use HiEvents\Repository\Interfaces\MessageRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderApplicationFeeRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderItemRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderPaymentPlatformFeeRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRefundRepositoryInterface;
use HiEvents\Repository\Interfaces\OrderRepositoryInterface;
use HiEvents\Repository\Interfaces\OrganizerRepositoryInterface;
Expand Down Expand Up @@ -123,6 +125,7 @@ class RepositoryServiceProvider extends ServiceProvider
WebhookRepositoryInterface::class => WebhookRepository::class,
WebhookLogRepositoryInterface::class => WebhookLogRepository::class,
OrderApplicationFeeRepositoryInterface::class => OrderApplicationFeeRepository::class,
OrderPaymentPlatformFeeRepositoryInterface::class => OrderPaymentPlatformFeeRepository::class,
AccountConfigurationRepositoryInterface::class => AccountConfigurationRepository::class,
QuestionAndAnswerViewRepositoryInterface::class => QuestionAndAnswerViewRepository::class,
OutgoingMessageRepositoryInterface::class => OutgoingMessageRepository::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace HiEvents\Repository\Eloquent;

use HiEvents\DomainObjects\OrderPaymentPlatformFeeDomainObject;
use HiEvents\Models\OrderPaymentPlatformFee;
use HiEvents\Repository\Interfaces\OrderPaymentPlatformFeeRepositoryInterface;

class OrderPaymentPlatformFeeRepository extends BaseRepository implements OrderPaymentPlatformFeeRepositoryInterface
{
protected function getModel(): string
{
return OrderPaymentPlatformFee::class;
}

public function getDomainObject(): string
{
return OrderPaymentPlatformFeeDomainObject::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace HiEvents\Repository\Interfaces;

use HiEvents\DomainObjects\OrderPaymentPlatformFeeDomainObject;
use HiEvents\Repository\Eloquent\BaseRepository;

/**
* @extends BaseRepository<OrderPaymentPlatformFeeDomainObject>
*/
interface OrderPaymentPlatformFeeRepositoryInterface extends RepositoryInterface
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use HiEvents\Services\Application\Handlers\Order\Payment\Stripe\DTO\StripeWebhookDTO;
use HiEvents\Services\Domain\Payment\Stripe\EventHandlers\AccountUpdateHandler;
use HiEvents\Services\Domain\Payment\Stripe\EventHandlers\ChargeRefundUpdatedHandler;
use HiEvents\Services\Domain\Payment\Stripe\EventHandlers\ChargeSucceededHandler;
use HiEvents\Services\Domain\Payment\Stripe\EventHandlers\PaymentIntentFailedHandler;
use HiEvents\Services\Domain\Payment\Stripe\EventHandlers\PaymentIntentSucceededHandler;
use Illuminate\Cache\Repository;
Expand All @@ -25,10 +26,13 @@ class IncomingWebhookHandler
Event::PAYMENT_INTENT_PAYMENT_FAILED,
Event::ACCOUNT_UPDATED,
Event::REFUND_UPDATED,
Event::CHARGE_SUCCEEDED,
Event::CHARGE_UPDATED,
];

public function __construct(
private readonly ChargeRefundUpdatedHandler $refundEventHandlerService,
private readonly ChargeSucceededHandler $chargeSucceededHandler,
private readonly PaymentIntentSucceededHandler $paymentIntentSucceededHandler,
private readonly PaymentIntentFailedHandler $paymentIntentFailedHandler,
private readonly AccountUpdateHandler $accountUpdateHandler,
Expand Down Expand Up @@ -70,7 +74,7 @@ public function handle(StripeWebhookDTO $webhookDTO): void
return;
}

$this->logger->debug('Stripe event received', $event->data->object->toArray());
$this->logger->debug('Stripe event received: ' . $event->type, $event->data->object->toArray());

switch ($event->type) {
case Event::PAYMENT_INTENT_SUCCEEDED:
Expand All @@ -79,6 +83,10 @@ public function handle(StripeWebhookDTO $webhookDTO): void
case Event::PAYMENT_INTENT_PAYMENT_FAILED:
$this->paymentIntentFailedHandler->handleEvent($event->data->object);
break;
case Event::CHARGE_SUCCEEDED:
case Event::CHARGE_UPDATED:
$this->chargeSucceededHandler->handleEvent($event->data->object);
break;
case Event::REFUND_UPDATED:
$this->refundEventHandlerService->handleEvent($event->data->object);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public function incrementForOrder(OrderDomainObject $order): void
->findById($order->getId());

$this->retrier->retry(
callableAction: function (int $attempt) use ($order): void {
$this->databaseManager->transaction(function () use ($order, $attempt): void {
$this->incrementAggregateStatistics($order, $attempt);
$this->incrementDailyStatistics($order, $attempt);
callableAction: function () use ($order): void {
$this->databaseManager->transaction(function () use ($order): void {
$this->incrementAggregateStatistics($order);
$this->incrementDailyStatistics($order);
$this->incrementPromoCodeUsage($order);
$this->incrementProductStatistics($order);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace HiEvents\Services\Domain\Order;

use HiEvents\DomainObjects\Generated\OrderPaymentPlatformFeeDomainObjectAbstract;
use HiEvents\Helper\Currency;
use HiEvents\Repository\Interfaces\OrderPaymentPlatformFeeRepositoryInterface;

class OrderPaymentPlatformFeeService
{
public function __construct(
private readonly OrderPaymentPlatformFeeRepositoryInterface $orderPaymentPlatformFeeRepository,
)
{
}

public function createOrderPaymentPlatformFee(
int $orderId,
string $paymentPlatform,
?array $feeRollup,
int $paymentPlatformFeeAmountMinorUnit,
int $applicationFeeAmountMinorUnit,
string $currency,
?string $transactionId = null,
): void
{
$isZeroDecimalCurrency = Currency::isZeroDecimalCurrency($currency);

$paymentPlatformFeeAmount = $isZeroDecimalCurrency
? $paymentPlatformFeeAmountMinorUnit
: $paymentPlatformFeeAmountMinorUnit / 100;

$applicationFeeAmount = $isZeroDecimalCurrency
? $applicationFeeAmountMinorUnit
: $applicationFeeAmountMinorUnit / 100;

$this->orderPaymentPlatformFeeRepository->create([
OrderPaymentPlatformFeeDomainObjectAbstract::ORDER_ID => $orderId,
OrderPaymentPlatformFeeDomainObjectAbstract::PAYMENT_PLATFORM => $paymentPlatform,
OrderPaymentPlatformFeeDomainObjectAbstract::FEE_ROLLUP => $feeRollup,
OrderPaymentPlatformFeeDomainObjectAbstract::PAYMENT_PLATFORM_FEE_AMOUNT => $paymentPlatformFeeAmount,
OrderPaymentPlatformFeeDomainObjectAbstract::APPLICATION_FEE_AMOUNT => $applicationFeeAmount,
OrderPaymentPlatformFeeDomainObjectAbstract::CURRENCY => strtoupper($currency),
OrderPaymentPlatformFeeDomainObjectAbstract::TRANSACTION_ID => $transactionId,
OrderPaymentPlatformFeeDomainObjectAbstract::PAID_AT => now()->toDateTimeString(),
]);
}
}
Loading
Loading