Skip to content

Commit 1d99379

Browse files
authored
Fix Checkout Bugs (#403)
1 parent 5813d07 commit 1d99379

File tree

8 files changed

+37
-14
lines changed

8 files changed

+37
-14
lines changed

backend/app/Services/Application/Handlers/Order/Payment/Stripe/CreatePaymentIntentHandler.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
1111
use HiEvents\DomainObjects\Generated\StripePaymentDomainObjectAbstract;
1212
use HiEvents\DomainObjects\OrderItemDomainObject;
13+
use HiEvents\DomainObjects\Status\OrderStatus;
1314
use HiEvents\DomainObjects\StripePaymentDomainObject;
15+
use HiEvents\Exceptions\ResourceConflictException;
1416
use HiEvents\Exceptions\Stripe\CreatePaymentIntentFailedException;
1517
use HiEvents\Exceptions\UnauthorizedException;
1618
use HiEvents\Repository\Eloquent\Value\Relationship;
@@ -58,6 +60,10 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
5860
throw new UnauthorizedException(__('Sorry, we could not verify your session. Please create a new order.'));
5961
}
6062

63+
if ($order->getStatus() !== OrderStatus::RESERVED->name || $order->isReservedOrderExpired()) {
64+
throw new ResourceConflictException(__('Sorry, is expired or not in a valid state.'));
65+
}
66+
6167
$account = $this->accountRepository
6268
->loadRelation(new Relationship(
6369
domainObject: AccountConfigurationDomainObject::class,

backend/app/Services/Domain/Order/MarkOrderAsPaidService.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use HiEvents\DomainObjects\AccountDomainObject;
77
use HiEvents\DomainObjects\Enums\PaymentProviders;
88
use HiEvents\DomainObjects\Enums\WebhookEventType;
9+
use HiEvents\DomainObjects\EventDomainObject;
910
use HiEvents\DomainObjects\Generated\OrderDomainObjectAbstract;
1011
use HiEvents\DomainObjects\OrderDomainObject;
1112
use HiEvents\DomainObjects\Status\AttendeeStatus;
@@ -116,8 +117,8 @@ private function updateAttendeeStatuses(OrderDomainObject $updatedOrder): void
116117

117118
private function storeApplicationFeePayment(OrderDomainObject $updatedOrder): void
118119
{
119-
/** @var AccountConfigurationDomainObject $config */
120-
$config = $this->eventRepository
120+
/** @var EventDomainObject $event */
121+
$event = $this->eventRepository
121122
->loadRelation(new Relationship(
122123
domainObject: AccountDomainObject::class,
123124
nested: [
@@ -128,16 +129,18 @@ private function storeApplicationFeePayment(OrderDomainObject $updatedOrder): vo
128129
],
129130
name: 'account'
130131
))
131-
->findById($updatedOrder->getEventId())
132-
->getAccount()
133-
->getConfiguration();
132+
->findById($updatedOrder->getEventId());
133+
134+
/** @var AccountConfigurationDomainObject $config */
135+
$config = $event->getAccount()->getConfiguration();
134136

135137
$this->orderApplicationFeeService->createOrderApplicationFee(
136138
orderId: $updatedOrder->getId(),
137139
applicationFeeAmount: $this->orderApplicationFeeCalculationService->calculateApplicationFee(
138140
$config,
139141
$updatedOrder->getTotalGross(),
140-
),
142+
$event->getCurrency(),
143+
)->toFloat(),
141144
orderApplicationFeeStatus: OrderApplicationFeeStatus::AWAITING_PAYMENT,
142145
paymentMethod: PaymentProviders::OFFLINE,
143146
);

backend/app/Services/Domain/Order/OrderApplicationFeeCalculationService.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace HiEvents\Services\Domain\Order;
44

55
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
6+
use HiEvents\Values\MoneyValue;
67
use Illuminate\Config\Repository;
78

89
class OrderApplicationFeeCalculationService
@@ -15,16 +16,20 @@ public function __construct(
1516

1617
public function calculateApplicationFee(
1718
AccountConfigurationDomainObject $accountConfiguration,
18-
float $orderTotal
19-
): float
19+
float $orderTotal,
20+
string $currency
21+
): MoneyValue
2022
{
2123
if (!$this->config->get('app.saas_mode_enabled')) {
22-
return 0;
24+
return MoneyValue::zero($currency);
2325
}
2426

2527
$fixedFee = $accountConfiguration->getFixedApplicationFee();
2628
$percentageFee = $accountConfiguration->getPercentageApplicationFee();
2729

28-
return ($fixedFee) + ($orderTotal * ($percentageFee / 100));
30+
return MoneyValue::fromFloat(
31+
amount: $fixedFee + ($orderTotal * $percentageFee / 100),
32+
currency: $currency
33+
);
2934
}
3035
}

backend/app/Services/Domain/Order/OrderApplicationFeeService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function createOrderApplicationFee(
2828
OrderApplicationFeeDomainObjectAbstract::STATUS => $orderApplicationFeeStatus->value,
2929
OrderApplicationFeeDomainObjectAbstract::PAYMENT_METHOD => $paymentMethod->value,
3030
OrderApplicationFeeDomainObjectAbstract::PAID_AT => $orderApplicationFeeStatus->value === OrderApplicationFeeStatus::PAID->value
31-
? now()
31+
? now()->toDateTimeString()
3232
: null,
3333
]);
3434
}

backend/app/Services/Domain/Payment/Stripe/StripePaymentIntentCreationService.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public function createPaymentIntent(CreatePaymentIntentRequestDTO $paymentIntent
6464

6565
$applicationFee = $this->orderApplicationFeeCalculationService->calculateApplicationFee(
6666
accountConfiguration: $paymentIntentDTO->account->getConfiguration(),
67-
orderTotal: $paymentIntentDTO->amount / 100
68-
);
67+
orderTotal: $paymentIntentDTO->amount / 100,
68+
currency: $paymentIntentDTO->currencyCode,
69+
)->toMinorUnit();
6970

7071
$paymentIntent = $this->stripeClient->paymentIntents->create([
7172
'amount' => $paymentIntentDTO->amount,

backend/app/Values/MoneyValue.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function add(MoneyValue $other): MoneyValue
4646
return new self($this->money->plus($other->getMoney()));
4747
}
4848

49+
public static function zero(string $currency): MoneyValue
50+
{
51+
return new self(Money::zero($currency));
52+
}
53+
4954
/**
5055
* @throws UnknownCurrencyException
5156
* @throws NumberFormatException

backend/config/app.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,6 @@
221221
// 'Example' => App\Facades\Example::class,
222222
])->toArray(),
223223

224+
225+
'is_hi_events' => env('APP_IS_HI_EVENTS', false),
224226
];

backend/vapor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ environments:
66
domain: api.hi.events
77
memory: 2048
88
cli-memory: 512
9+
storage: hievents-assets-prod
910
runtime: 'php-8.3:al2'
1011
warm: 3
1112
cache: hievents-redis
@@ -31,7 +32,7 @@ environments:
3132
cache: hievents-redis
3233
database: hievents-postgres
3334
queue:
34-
- hievents-queue-prod
35+
- hievents-queue-staging
3536
- hievents-webhook-queue-staging
3637
queue-memory: 1024
3738
queue-concurrency: 2

0 commit comments

Comments
 (0)