-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPaymentProcessingService.php
More file actions
54 lines (42 loc) · 1.78 KB
/
Copy pathPaymentProcessingService.php
File metadata and controls
54 lines (42 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace SwagUcp\Service;
use Shopware\Core\Checkout\Cart\Cart;
use Shopware\Core\Checkout\Payment\PaymentProcessor;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
class PaymentProcessingService
{
public function __construct(
private readonly PaymentProcessor $paymentProcessor,
) {
}
public function processPayment(Cart $cart, array $paymentData, SalesChannelContext $context): void
{
// Extract payment method from handler_id
$handlerId = $paymentData['handler_id'] ?? null;
if (!$handlerId) {
throw new \InvalidArgumentException('Payment handler_id is required');
}
// Map UCP payment handler to Shopware payment method
$paymentMethodId = $this->mapHandlerToPaymentMethod($handlerId, $context);
if (!$paymentMethodId) {
throw new \InvalidArgumentException("Payment handler not found: {$handlerId}");
}
// Set payment method on cart
$cart->setPaymentMethodId($paymentMethodId);
// Store payment credential for later processing
// In production, this would be stored securely and processed during order creation
$cart->addExtension('ucp_payment_data', $paymentData);
}
private function mapHandlerToPaymentMethod(string $handlerId, SalesChannelContext $context): ?string
{
// In a real implementation, this would query payment methods
// and match them to UCP handlers based on configuration
// For now, return first available payment method
$paymentMethods = $context->getSalesChannel()->getPaymentMethods();
if ($paymentMethods && $paymentMethods->count() > 0) {
return $paymentMethods->first()->getId();
}
return null;
}
}