Skip to content

Commit 52a4cce

Browse files
authored
Merge pull request #1008 from HiEventsDev/develop
2 parents 06009b8 + d298145 commit 52a4cce

42 files changed

Lines changed: 14677 additions & 3418 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

backend/app/DomainObjects/OrderDomainObject.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace HiEvents\DomainObjects;
44

5+
use Exception;
6+
use HiEvents\DataTransferObjects\AddressDTO;
57
use HiEvents\DomainObjects\Enums\PaymentProviders;
68
use HiEvents\DomainObjects\Enums\ProductType;
79
use HiEvents\DomainObjects\Interfaces\IsFilterable;
@@ -286,4 +288,17 @@ public function isRefundable(): bool
286288
&& $this->getPaymentProvider() === PaymentProviders::STRIPE->name
287289
&& $this->getRefundStatus() !== OrderRefundStatus::REFUNDED->name;
288290
}
291+
292+
public function getAddressDTO(): ?AddressDTO
293+
{
294+
if ($this->getAddress() === null) {
295+
return null;
296+
}
297+
298+
try {
299+
return AddressDTO::from($this->getAddress());
300+
} catch (Exception) {
301+
return null;
302+
}
303+
}
289304
}

backend/app/Locale.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum Locale: string
1818
case PT = 'pt';
1919
case PT_BR = 'pt-br';
2020
case ZH_CN = 'zh-cn';
21+
case SE = 'se';
2122

2223
case ZH_HK = 'zh-hk';
2324
case VI = 'vi';

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
1010
use HiEvents\DomainObjects\AccountStripePlatformDomainObject;
1111
use HiEvents\DomainObjects\AccountVatSettingDomainObject;
12+
use HiEvents\DomainObjects\EventDomainObject;
1213
use HiEvents\DomainObjects\Generated\StripePaymentDomainObjectAbstract;
1314
use HiEvents\DomainObjects\OrderItemDomainObject;
1415
use HiEvents\DomainObjects\Status\OrderStatus;
@@ -27,6 +28,7 @@
2728
use HiEvents\Services\Infrastructure\Stripe\StripeClientFactory;
2829
use HiEvents\Services\Infrastructure\Stripe\StripeConfigurationService;
2930
use HiEvents\Values\MoneyValue;
31+
use Illuminate\Support\Str;
3032
use Stripe\Exception\ApiErrorException;
3133
use Throwable;
3234

@@ -60,6 +62,7 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
6062
$order = $this->orderRepository
6163
->loadRelation(new Relationship(OrderItemDomainObject::class))
6264
->loadRelation(new Relationship(StripePaymentDomainObject::class, name: 'stripe_payment'))
65+
->loadRelation(new Relationship(EventDomainObject::class, name: 'event'))
6366
->findByShortId($orderShortId);
6467

6568
if (!$order || !$this->sessionIdentifierService->verifySession($order->getSessionId())) {
@@ -110,6 +113,12 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
110113
);
111114
}
112115

116+
$description = __(':item_count item(s) for event: :event_name (Order :order_short_id)', [
117+
'event_name' => Str::limit($order->getEvent()?->getTitle() ?? __('Event'), 75),
118+
'order_short_id' => $orderShortId,
119+
'item_count' => $order->getOrderItems()->sum(fn(OrderItemDomainObject $item) => $item->getQuantity()),
120+
]);
121+
113122
$paymentIntent = $this->stripePaymentService->createPaymentIntentWithClient(
114123
$stripeClient,
115124
CreatePaymentIntentRequestDTO::fromArray([
@@ -119,6 +128,7 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
119128
'order' => $order,
120129
'stripeAccountId' => $stripeAccountId,
121130
'vatSettings' => $account->getAccountVatSetting(),
131+
'description' => Str::limit($description, 997),
122132
])
123133
);
124134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private function storeApplicationFeePayment(OrderDomainObject $updatedOrder): vo
182182
applicationFeeAmountMinorUnit: $this->orderApplicationFeeCalculationService->calculateApplicationFee(
183183
accountConfiguration: $config,
184184
order: $updatedOrder,
185-
)->netApplicationFee->toMinorUnit(),
185+
)?->netApplicationFee?->toMinorUnit() ?? 0,
186186
orderApplicationFeeStatus: OrderApplicationFeeStatus::AWAITING_PAYMENT,
187187
paymentMethod: PaymentProviders::OFFLINE,
188188
currency: $updatedOrder->getCurrency(),

backend/app/Services/Domain/Payment/Stripe/DTOs/CreatePaymentIntentRequestDTO.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function __construct(
1717
public readonly OrderDomainObject $order,
1818
public readonly ?string $stripeAccountId = null,
1919
public readonly ?AccountVatSettingDomainObject $vatSettings = null,
20+
public readonly ?string $description = null,
2021
)
2122
{
2223
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public function createPaymentIntentWithClient(
8383
'automatic_payment_methods' => [
8484
'enabled' => true,
8585
],
86+
...($paymentIntentDTO->description ? ['description' => $paymentIntentDTO->description] : []),
8687
...($applicationFee && !$bypassApplicationFees ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []),
8788
], $this->getStripeAccountData($paymentIntentDTO));
8889

@@ -157,11 +158,26 @@ private function upsertStripeCustomerWithClient(
157158
]);
158159

159160
if ($customer === null) {
161+
$order = $paymentIntentDTO->order;
162+
163+
$customerData = [
164+
'email' => $order->getEmail(),
165+
'name' => $order->getFullName(),
166+
];
167+
168+
if (($address = $order->getAddressDTO()) && $address->address_line_1 && $address->country) {
169+
$customerData['address'] = [
170+
'line1' => $address->address_line_1,
171+
'line2' => $address->address_line_2 ?? '',
172+
'city' => $address->city ?? '',
173+
'state' => $address->state_or_region ?? '',
174+
'postal_code' => $address->zip_or_postal_code ?? '',
175+
'country' => $address->country,
176+
];
177+
}
178+
160179
$stripeCustomer = $stripeClient->customers->create(
161-
params: [
162-
'email' => $paymentIntentDTO->order->getEmail(),
163-
'name' => $paymentIntentDTO->order->getFullName(),
164-
],
180+
params: $customerData,
165181
opts: $this->getStripeAccountData($paymentIntentDTO)
166182
);
167183

backend/composer.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)