Skip to content
Open
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
36 changes: 36 additions & 0 deletions backend/app/DomainObjects/OrderDomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,40 @@ public function isRefundable(): bool
&& $this->getPaymentProvider() === PaymentProviders::STRIPE->name
&& $this->getRefundStatus() !== OrderRefundStatus::REFUNDED->name;
}

public function getAddressLine1(): ?string
{
$address = $this->getAddress();
return $address['address_line_1'] ?? null;
}

public function getAddressLine2(): ?string
{
$address = $this->getAddress();
return $address['address_line_2'] ?? null;
}

public function getCity(): ?string
{
$address = $this->getAddress();
return $address['city'] ?? null;
}

public function getState(): ?string
{
$address = $this->getAddress();
return $address['state_or_region'] ?? $address['state'] ?? null;
}

public function getPostalCode(): ?string
{
$address = $this->getAddress();
return $address['zip_or_postal_code'] ?? $address['postal_code'] ?? null;
}

public function getCountryCode(): ?string
{
$address = $this->getAddress();
return $address['country'] ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public function handle(string $orderShortId): CreatePaymentIntentResponseDTO
);
}

$description = sprintf(
'Event tickets - Order %s - %s ticket(s) - %s',
$orderShortId,
count($order->getOrderItems()),
$account->getName() ?? 'Event Registration'
);

if (strlen($description) > 1000) {
$description = substr($description, 0, 997) . '...';
}

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

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 @@ -80,6 +80,7 @@ public function createPaymentIntentWithClient(
'automatic_payment_methods' => [
'enabled' => true,
],
...($paymentIntentDTO->description ? ['description' => $paymentIntentDTO->description] : []),
...($applicationFee ? ['application_fee_amount' => $applicationFee->grossApplicationFee->toMinorUnit()] : []),
], $this->getStripeAccountData($paymentIntentDTO));

Expand Down Expand Up @@ -154,11 +155,25 @@ private function upsertStripeCustomerWithClient(
]);

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

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

if ($order->getAddressLine1() && $order->getCountryCode()) {
$customerData['address'] = [
'line1' => $order->getAddressLine1(),
'line2' => $order->getAddressLine2() ?? '',
'city' => $order->getCity() ?? '',
'state' => $order->getState() ?? '',
'postal_code' => $order->getPostalCode() ?? '',
'country' => $order->getCountryCode(),
];
}
$stripeCustomer = $stripeClient->customers->create(
params: [
'email' => $paymentIntentDTO->order->getEmail(),
'name' => $paymentIntentDTO->order->getFullName(),
],
params: $customerData,
opts: $this->getStripeAccountData($paymentIntentDTO)
);

Expand Down