Files
fotospiel-app/app/Services/Checkout/CheckoutPaymentService.php
2025-10-07 11:52:03 +02:00

88 lines
2.9 KiB
PHP

<?php
namespace App\Services\Checkout;
use App\Models\CheckoutSession;
use App\Models\Tenant;
use LogicException;
class CheckoutPaymentService
{
public function __construct(
private readonly CheckoutSessionService $sessions,
private readonly CheckoutAssignmentService $assignment,
) {
}
public function initialiseStripe(CheckoutSession $session, array $payload = []): array
{
if ($session->provider !== CheckoutSession::PROVIDER_STRIPE) {
$this->sessions->selectProvider($session, CheckoutSession::PROVIDER_STRIPE);
}
// TODO: integrate Stripe PaymentIntent creation and return client_secret + publishable key
return [
'session_id' => $session->id,
'status' => $session->status,
'message' => 'Stripe integration pending implementation.',
];
}
public function confirmStripe(CheckoutSession $session, array $payload = []): CheckoutSession
{
if ($session->provider !== CheckoutSession::PROVIDER_STRIPE) {
throw new LogicException('Cannot confirm Stripe payment on a non-Stripe session.');
}
// TODO: verify PaymentIntent status with Stripe SDK and update session metadata
$this->sessions->markProcessing($session);
return $session;
}
public function initialisePayPal(CheckoutSession $session, array $payload = []): array
{
if ($session->provider !== CheckoutSession::PROVIDER_PAYPAL) {
$this->sessions->selectProvider($session, CheckoutSession::PROVIDER_PAYPAL);
}
// TODO: integrate PayPal Orders API and return order id + approval link
return [
'session_id' => $session->id,
'status' => $session->status,
'message' => 'PayPal integration pending implementation.',
];
}
public function capturePayPal(CheckoutSession $session, array $payload = []): CheckoutSession
{
if ($session->provider !== CheckoutSession::PROVIDER_PAYPAL) {
throw new LogicException('Cannot capture PayPal payment on a non-PayPal session.');
}
// TODO: call PayPal capture endpoint and persist order/subscription identifiers
$this->sessions->markProcessing($session);
return $session;
}
public function finaliseFree(CheckoutSession $session): CheckoutSession
{
if ($session->provider !== CheckoutSession::PROVIDER_FREE) {
$this->sessions->selectProvider($session, CheckoutSession::PROVIDER_FREE);
}
$this->sessions->markProcessing($session);
$this->assignment->finalise($session, ['source' => 'free']);
return $this->sessions->markCompleted($session);
}
public function attachTenantAndResume(CheckoutSession $session, Tenant $tenant): CheckoutSession
{
$this->sessions->attachTenant($session, $tenant);
$this->sessions->refreshExpiration($session);
return $session;
}
}