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
15 changes: 15 additions & 0 deletions backend/app/DomainObjects/OrderDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace HiEvents\DomainObjects;

use Exception;
use HiEvents\DataTransferObjects\AddressDTO;
use HiEvents\DomainObjects\Enums\PaymentProviders;
use HiEvents\DomainObjects\Enums\ProductType;
use HiEvents\DomainObjects\Interfaces\IsFilterable;
Expand Down Expand Up @@ -286,4 +288,17 @@ public function isRefundable(): bool
&& $this->getPaymentProvider() === PaymentProviders::STRIPE->name
&& $this->getRefundStatus() !== OrderRefundStatus::REFUNDED->name;
}

public function getAddressDTO(): ?AddressDTO
{
if ($this->getAddress() === null) {
return null;
}

try {
return AddressDTO::from($this->getAddress());
} catch (Exception) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use HiEvents\DomainObjects\AccountConfigurationDomainObject;
use HiEvents\DomainObjects\AccountStripePlatformDomainObject;
use HiEvents\DomainObjects\AccountVatSettingDomainObject;
use HiEvents\DomainObjects\EventDomainObject;
use HiEvents\DomainObjects\Generated\StripePaymentDomainObjectAbstract;
use HiEvents\DomainObjects\OrderItemDomainObject;
use HiEvents\DomainObjects\Status\OrderStatus;
Expand All @@ -27,6 +28,7 @@
use HiEvents\Services\Infrastructure\Stripe\StripeClientFactory;
use HiEvents\Services\Infrastructure\Stripe\StripeConfigurationService;
use HiEvents\Values\MoneyValue;
use Illuminate\Support\Str;
use Stripe\Exception\ApiErrorException;
use Throwable;

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

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

$description = __(':item_count item(s) for event: :event_name (Order :order_short_id)', [
'event_name' => Str::limit($order->getEvent()?->getTitle() ?? __('Event'), 75),
'order_short_id' => $orderShortId,
'item_count' => $order->getOrderItems()->sum(fn(OrderItemDomainObject $item) => $item->getQuantity()),
]);

$paymentIntent = $this->stripePaymentService->createPaymentIntentWithClient(
$stripeClient,
CreatePaymentIntentRequestDTO::fromArray([
Expand All @@ -119,6 +128,7 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
'order' => $order,
'stripeAccountId' => $stripeAccountId,
'vatSettings' => $account->getAccountVatSetting(),
'description' => Str::limit($description, 997),
])
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __construct(
public readonly OrderDomainObject $order,
public readonly ?string $stripeAccountId = null,
public readonly ?AccountVatSettingDomainObject $vatSettings = null,
public readonly ?string $description = null,
)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public function createPaymentIntentWithClient(
'automatic_payment_methods' => [
'enabled' => true,
],
...($paymentIntentDTO->description ? ['description' => $paymentIntentDTO->description] : []),
...($applicationFee && !$bypassApplicationFees ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []),
], $this->getStripeAccountData($paymentIntentDTO));

Expand Down Expand Up @@ -157,11 +158,26 @@ private function upsertStripeCustomerWithClient(
]);

if ($customer === null) {
$order = $paymentIntentDTO->order;

$customerData = [
'email' => $order->getEmail(),
'name' => $order->getFullName(),
];

if (($address = $order->getAddressDTO()) && $address->address_line_1 && $address->country) {
$customerData['address'] = [
'line1' => $address->address_line_1,
'line2' => $address->address_line_2 ?? '',
'city' => $address->city ?? '',
'state' => $address->state_or_region ?? '',
'postal_code' => $address->zip_or_postal_code ?? '',
'country' => $address->country,
];
}

$stripeCustomer = $stripeClient->customers->create(
params: [
'email' => $paymentIntentDTO->order->getEmail(),
'name' => $paymentIntentDTO->order->getFullName(),
],
params: $customerData,
opts: $this->getStripeAccountData($paymentIntentDTO)
);

Expand Down
Loading