Skip to content

Commit 7524f88

Browse files
PT-3568 v.6.6 (#86)
1 parent b774346 commit 7524f88

27 files changed

+439
-182
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "mondu/shopware6-payment",
33
"description": "Mondu payment for Shopware 6",
4-
"version": "1.6.0",
4+
"version": "1.6.1",
55
"type": "shopware-platform-plugin",
66
"license": "proprietary",
77
"authors": [

src/Bootstrap/MediaProvider.php

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,24 @@
1515
*/
1616
class MediaProvider
1717
{
18+
private readonly string $resourcesPath;
19+
private readonly string $paymentLogosPath;
20+
1821
/**
1922
* Constructs a `MediaProvider`
2023
*
2124
* @param MediaService $mediaService
2225
* @param EntityRepository $mediaRepository
26+
* @param string $pluginPath
2327
*/
2428
public function __construct(
2529
private readonly MediaService $mediaService,
26-
private readonly EntityRepository $mediaRepository
27-
) {}
30+
private readonly EntityRepository $mediaRepository,
31+
string $pluginPath
32+
) {
33+
$this->resourcesPath = $pluginPath . '/src/Resources/public';
34+
$this->paymentLogosPath = $this->resourcesPath . '/images/de';
35+
}
2836

2937
/**
3038
* @param Context $context
@@ -39,7 +47,7 @@ public function getLogoMediaId(Context $context): string
3947
return $existingMedia->getId();
4048
}
4149

42-
$file = file_get_contents(dirname(__DIR__, 1).'/Resources/public/plugin.png');
50+
$file = file_get_contents($this->resourcesPath . '/plugin.png');
4351
$mediaId = '';
4452

4553
if ($file) {
@@ -49,6 +57,40 @@ public function getLogoMediaId(Context $context): string
4957
return $mediaId;
5058
}
5159

60+
/**
61+
* Get media ID for specific payment method logo
62+
*
63+
* @param string $logoFileName
64+
* @param Context $context
65+
*
66+
* @return string
67+
*/
68+
public function getPaymentMethodLogoMediaId(string $logoFileName, Context $context): string
69+
{
70+
$mediaName = 'mondu-' . pathinfo($logoFileName, PATHINFO_FILENAME);
71+
$existingMedia = $this->hasMediaAlreadyInstalledByName($context, $mediaName);
72+
73+
if ($existingMedia) {
74+
return $existingMedia->getId();
75+
}
76+
77+
$logoPath = $this->paymentLogosPath . '/' . $logoFileName;
78+
79+
if (!file_exists($logoPath)) {
80+
// Fallback to default logo if specific logo not found
81+
return $this->getLogoMediaId($context);
82+
}
83+
84+
$file = file_get_contents($logoPath);
85+
$mediaId = '';
86+
87+
if ($file) {
88+
$mediaId = $this->mediaService->saveFile($file, 'png', 'image/png', $mediaName, $context, 'payment_method', null, false);
89+
}
90+
91+
return $mediaId;
92+
}
93+
5294
/**
5395
* @param Context $context
5496
*
@@ -79,4 +121,24 @@ protected function hasMediaAlreadyInstalled(Context $context)
79121

80122
return $this->mediaRepository->search($criteria, $context)->first();
81123
}
124+
125+
/**
126+
* Check if media already installed by custom name
127+
*
128+
* @param Context $context
129+
* @param string $mediaName
130+
*
131+
* @return \Shopware\Core\Framework\DataAbstractionLayer\Entity|null
132+
*/
133+
protected function hasMediaAlreadyInstalledByName(Context $context, string $mediaName)
134+
{
135+
$criteria = (new Criteria())->addFilter(
136+
new EqualsFilter(
137+
'fileName',
138+
$mediaName
139+
)
140+
);
141+
142+
return $this->mediaRepository->search($criteria, $context)->first();
143+
}
82144
}

src/Bootstrap/PaymentMethods.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@
1616

1717
class PaymentMethods extends AbstractBootstrap
1818
{
19+
public const PAYMENT_METHOD_LOGOS = [
20+
MonduHandler::class => 'invoice_white_rectangle.png',
21+
MonduSepaHandler::class => 'sepa_white_rectangle.png',
22+
MonduInstallmentHandler::class => 'installments_white_rectangle.png',
23+
MonduInstallmentByInvoiceHandler::class => 'installments_white_rectangle.png',
24+
MonduPayNowHandler::class => 'instant_pay_white_rectangle.png',
25+
];
26+
1927
public const PAYMENT_METHODS = [
2028
MonduHandler::class => [
2129
'handlerIdentifier' => MonduHandler::class,
@@ -235,8 +243,16 @@ protected function updatePaymentMethodImage(): void
235243
{
236244
$mediaProvider = $this->container->get(MediaProvider::class);
237245

238-
foreach (self::PAYMENT_METHODS as $paymentMethod) {
239-
$mediaId = $mediaProvider->getLogoMediaId($this->context);
246+
foreach (self::PAYMENT_METHODS as $handlerClass => $paymentMethod) {
247+
// Get specific logo for this payment method
248+
$logoFileName = self::PAYMENT_METHOD_LOGOS[$handlerClass] ?? null;
249+
250+
if ($logoFileName) {
251+
$mediaId = $mediaProvider->getPaymentMethodLogoMediaId($logoFileName, $this->context);
252+
} else {
253+
// Fallback to default logo
254+
$mediaId = $mediaProvider->getLogoMediaId($this->context);
255+
}
240256

241257
$paymentSearchResult = $this->paymentRepository->search(
242258
(
@@ -247,11 +263,13 @@ protected function updatePaymentMethodImage(): void
247263
$this->context
248264
);
249265

250-
$paymentMethodData = [
251-
'id' => $paymentSearchResult->first()->getId(),
252-
'mediaId' => $mediaId
253-
];
254-
$this->paymentRepository->update([$paymentMethodData], $this->context);
266+
if ($paymentSearchResult->first()) {
267+
$paymentMethodData = [
268+
'id' => $paymentSearchResult->first()->getId(),
269+
'mediaId' => $mediaId
270+
];
271+
$this->paymentRepository->update([$paymentMethodData], $this->context);
272+
}
255273
}
256274
}
257275
}

src/Components/Events/DependencyInjection/subscriber.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,5 @@
1212
<!-- No constructor arguments needed -->
1313
</service>
1414

15-
<service id="Mondu\MonduPayment\Components\Events\Subscriber\TestMonduEventsSubscriber">
16-
<argument key="$logger" type="service" id="monolog.logger.mondu"/>
17-
<argument key="$configService" type="service" id="mondu.mondu_config"/>
18-
</service>
19-
2015
</services>
2116
</container>
22-
23-

src/Components/Events/Subscriber/TestMonduEventsSubscriber.php

Lines changed: 0 additions & 94 deletions
This file was deleted.

src/Components/MonduApi/Service/MonduClient.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class MonduClient
1818
private Client $restClient;
1919

2020
/**
21-
* @var string
21+
* @var string|null
2222
*/
23-
private string $key;
23+
private ?string $key = null;
2424

2525
/**
2626
* @var string|null
@@ -84,8 +84,21 @@ public function cancelOrder($orderUid): ?string
8484
public function confirmOrder($orderUuid, $data): ?string
8585
{
8686
$response = $this->sendRequest('orders/'. $orderUuid .'/confirm', 'POST', $data);
87+
88+
$state = $response['state'] ?? $response['order']['state'] ?? null;
89+
90+
if ($this->configService->isExtendedLogsEnabled()) {
91+
$this->logger->info('mondu.INFO: confirmOrder full API response', [
92+
'order_uuid' => $orderUuid,
93+
'request_data' => $data,
94+
'response' => $response,
95+
'state_from_root' => $response['state'] ?? null,
96+
'state_from_order' => $response['order']['state'] ?? null,
97+
'final_state' => $state
98+
]);
99+
}
87100

88-
return $response['order']['state'] ?? null;
101+
return $state;
89102
}
90103

91104
public function adjustOrder($orderUuid, $body = []): ?array
@@ -154,11 +167,9 @@ public function sendRequest($url, $method = 'GET', $body = [], $allowAlreadySubs
154167
} catch (GuzzleException $e) {
155168
$responseBody = null;
156169

157-
// Check if this is a 422 error with special handling
158170
if (method_exists($e, 'getResponse') && $e->getResponse()) {
159171
$responseBody = json_decode($e->getResponse()->getBody()->getContents(), true);
160172

161-
// If webhook already subscribed and allowed - treat as success
162173
if ($allowAlreadySubscribed &&
163174
$e->getCode() == 422 &&
164175
isset($responseBody['errors'][0]['details']) &&
@@ -167,19 +178,15 @@ public function sendRequest($url, $method = 'GET', $body = [], $allowAlreadySubs
167178
if ($this->configService->isExtendedLogsEnabled()) {
168179
$this->logger->info("mondu.INFO: MonduClient [{$method} {$url}]: Webhook already registered - " . $responseBody['errors'][0]['details']);
169180
}
170-
// Return success array to indicate webhook is registered
171181
return ['status' => 'already_registered', 'message' => $responseBody['errors'][0]['details']];
172182
}
173183

174-
// If invoice already exists (duplicate external_reference_id) - return special status
175184
if ($e->getCode() == 422 &&
176185
isset($responseBody['errors'][0]['details']) &&
177186
strpos($responseBody['errors'][0]['details'], 'must be unique') !== false) {
178187

179-
// Always log this to understand what's happening
180188
$this->logger->warning("mondu.WARNING: MonduClient [{$method} {$url}]: Invoice already exists, returning special status - " . $responseBody['errors'][0]['details']);
181189

182-
// Return special status to indicate invoice already exists
183190
return ['status' => 'already_exists', 'message' => $responseBody['errors'][0]['details']];
184191
}
185192
}

0 commit comments

Comments
 (0)