Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Main <- develop (#404)

Dave Earley880d38bf6a4a
diff --git a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
index f83dccee1..f133c3f0d 100644
--- a/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
+++ b/backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php
@@ -10,7 +10,9 @@ use Brick\Money\Money;
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
use HiEvents\DomainObjects\Generated\StripePaymentDomainObjectAbstract;
use HiEvents\DomainObjects\OrderItemDomainObject;
+use HiEvents\DomainObjects\Status\OrderStatus;
use HiEvents\DomainObjects\StripePaymentDomainObject;
+use HiEvents\Exceptions\ResourceConflictException;
use HiEvents\Exceptions\Stripe\CreatePaymentIntentFailedException;
use HiEvents\Exceptions\UnauthorizedException;
use HiEvents\Repository\Eloquent\Value\Relationship;
@@ -58,6 +60,10 @@ readonly class CreatePaymentIntentHandler
throw new UnauthorizedException(__('Sorry, we could not verify your session. Please create a new order.'));
}
+ if ($order->getStatus() !== OrderStatus::RESERVED->name || $order->isReservedOrderExpired()) {
+ throw new ResourceConflictException(__('Sorry, is expired or not in a valid state.'));
+ }
+
$account = $this->accountRepository
->loadRelation(new Relationship(
domainObject: AccountConfigurationDomainObject::class,
diff --git a/backend/app/Services/Domain/Order/MarkOrderAsPaidService.php b/backend/app/Services/Domain/Order/MarkOrderAsPaidService.php
index e9dfd36f4..15a3e3e98 100644
--- a/backend/app/Services/Domain/Order/MarkOrderAsPaidService.php
+++ b/backend/app/Services/Domain/Order/MarkOrderAsPaidService.php
@@ -6,6 +6,7 @@ use HiEvents\DomainObjects\AccountConfigurationDomainObject;
use HiEvents\DomainObjects\AccountDomainObject;
use HiEvents\DomainObjects\Enums\PaymentProviders;
use HiEvents\DomainObjects\Enums\WebhookEventType;
+use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
use HiEvents\DomainObjects\OrderDomainObject;
use HiEvents\DomainObjects\Status\AttendeeStatus;
@@ -116,8 +117,8 @@ class MarkOrderAsPaidService
private function storeApplicationFeePayment(OrderDomainObject $updatedOrder): void
{
- /** @var AccountConfigurationDomainObject $config */
- $config = $this->eventRepository
+ /** @var EventDomainObject $event */
+ $event = $this->eventRepository
->loadRelation(new Relationship(
domainObject: AccountDomainObject::class,
nested: [
@@ -128,16 +129,18 @@ class MarkOrderAsPaidService
],
name: 'account'
))
- ->findById($updatedOrder->getEventId())
- ->getAccount()
- ->getConfiguration();
+ ->findById($updatedOrder->getEventId());
+
+ /** @var AccountConfigurationDomainObject $config */
+ $config = $event->getAccount()->getConfiguration();
$this->orderApplicationFeeService->createOrderApplicationFee(
orderId: $updatedOrder->getId(),
applicationFeeAmount: $this->orderApplicationFeeCalculationService->calculateApplicationFee(
$config,
$updatedOrder->getTotalGross(),
- ),
+ $event->getCurrency(),
+ )->toFloat(),
orderApplicationFeeStatus: OrderApplicationFeeStatus::AWAITING_PAYMENT,
paymentMethod: PaymentProviders::OFFLINE,
);
diff --git a/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php b/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
index 1bb69c18f..b8ee73a4b 100644
--- a/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
+++ b/backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php
@@ -3,6 +3,7 @@
namespace HiEvents\Services\Domain\Order;
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
+use HiEvents\Values\MoneyValue;
use Illuminate\Config\Repository;
class OrderApplicationFeeCalculationService
@@ -15,16 +16,20 @@ class OrderApplicationFeeCalculationService
public function calculateApplicationFee(
AccountConfigurationDomainObject $accountConfiguration,
- float $orderTotal
- ): float
+ float $orderTotal,
+ string $currency
+ ): MoneyValue
{
if (!$this->config->get('app.saas_mode_enabled')) {
- return 0;
+ return MoneyValue::zero($currency);
}
$fixedFee = $accountConfiguration->getFixedApplicationFee();
$percentageFee = $accountConfiguration->getPercentageApplicationFee();
- return ($fixedFee) + ($orderTotal * ($percentageFee / 100));
+ return MoneyValue::fromFloat(
+ amount: $fixedFee + ($orderTotal * $percentageFee / 100),
+ currency: $currency
+ );
}
}
diff --git a/backend/app/Services/Domain/Order/OrderApplicationFeeService.php b/backend/app/Services/Domain/Order/OrderApplicationFeeService.php
index 889bff250..12904baac 100644
--- a/backend/app/Services/Domain/Order/OrderApplicationFeeService.php
+++ b/backend/app/Services/Domain/Order/OrderApplicationFeeService.php
@@ -28,7 +28,7 @@ class OrderApplicationFeeService
OrderApplicationFeeDomainObjectAbstract::STATUS => $orderApplicationFeeStatus->value,
OrderApplicationFeeDomainObjectAbstract::PAYMENT_METHOD => $paymentMethod->value,
OrderApplicationFeeDomainObjectAbstract::PAID_AT => $orderApplicationFeeStatus->value === OrderApplicationFeeStatus::PAID->value
- ? now()
+ ? now()->toDateTimeString()
: null,
]);
}
diff --git a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php
index 090633587..8a9c38d7d 100644
--- a/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php
+++ b/backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php
@@ -64,8 +64,9 @@ class StripePaymentIntentCreationService
$applicationFee = $this->orderApplicationFeeCalculationService->calculateApplicationFee(
accountConfiguration: $paymentIntentDTO->account->getConfiguration(),
- orderTotal: $paymentIntentDTO->amount / 100
- );
+ orderTotal: $paymentIntentDTO->amount / 100,
+ currency: $paymentIntentDTO->currencyCode,
+ )->toMinorUnit();
$paymentIntent = $this->stripeClient->paymentIntents->create([
'amount' => $paymentIntentDTO->amount,
diff --git a/backend/app/Values/MoneyValue.php b/backend/app/Values/MoneyValue.php
index 81e03ee09..d3194e356 100644
--- a/backend/app/Values/MoneyValue.php
+++ b/backend/app/Values/MoneyValue.php
@@ -46,6 +46,11 @@ class MoneyValue
return new self($this->money->plus($other->getMoney()));
}
+ public static function zero(string $currency): MoneyValue
+ {
+ return new self(Money::zero($currency));
+ }
+
/**
* @throws UnknownCurrencyException
* @throws NumberFormatException
diff --git a/backend/config/app.php b/backend/config/app.php
index 036c59e03..aca587999 100644
--- a/backend/config/app.php
+++ b/backend/config/app.php
@@ -221,4 +221,6 @@ return [
// 'Example' => App\Facades\Example::class,
])->toArray(),
+
+ 'is_hi_events' => env('APP_IS_HI_EVENTS', false),
];
diff --git a/backend/vapor.yml b/backend/vapor.yml
index 4f9f176f5..9684f00ae 100644
--- a/backend/vapor.yml
+++ b/backend/vapor.yml
@@ -6,6 +6,7 @@ environments:
domain: api.hi.events
memory: 2048
cli-memory: 512
+ storage: hievents-assets-prod
runtime: 'php-8.3:al2'
warm: 3
cache: hievents-redis
@@ -31,7 +32,7 @@ environments:
cache: hievents-redis
database: hievents-postgres
queue:
- - hievents-queue-prod
+ - hievents-queue-staging
- hievents-webhook-queue-staging
queue-memory: 1024
queue-concurrency: 2