Skip to content

Commit 925c5f0

Browse files
committed
Merge remote-tracking branch 'origin/ECP-9757' into ECP-9757
2 parents deb952d + 81cc2cf commit 925c5f0

File tree

64 files changed

+5800
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+5800
-57
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace Adyen\Payment\Api;
3+
4+
use Adyen\Payment\Api\Data\AnalyticsEventInterface;
5+
6+
interface AnalyticsEventRepositoryInterface
7+
{
8+
public function save(AnalyticsEventInterface $analyticsEvent): AnalyticsEventInterface;
9+
10+
public function getById(int $id): AnalyticsEventInterface;
11+
12+
public function delete(AnalyticsEventInterface $analyticsEvent): void;
13+
14+
public function deleteById(int $id): void;
15+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Api\Data;
14+
15+
use DateTime;
16+
17+
interface AnalyticsEventInterface
18+
{
19+
const ADYEN_ANALYTICS_EVENT = 'adyen_analytics_event';
20+
const TABLE_NAME_ALIAS = 'analytics_event';
21+
const ENTITY_ID = 'entity_id';
22+
const UUID = 'uuid';
23+
const RELATION_ID = 'relation_id';
24+
const TYPE = 'type';
25+
const TOPIC = 'topic';
26+
const MESSAGE = 'message';
27+
const VERSION = 'version';
28+
const ERROR_TYPE = 'error_type';
29+
const ERROR_CODE = 'error_code';
30+
const ERROR_COUNT = 'error_count';
31+
const STATUS = 'status';
32+
const CREATED_AT = 'created_at';
33+
const UPDATED_AT = 'updated_at';
34+
const SCHEDULED_PROCESSING_TIME = 'scheduled_processing_time';
35+
const MAX_ERROR_COUNT = 5;
36+
37+
public function getEntityId();
38+
39+
public function setEntityId($entityId);
40+
41+
public function getRelationId(): string;
42+
43+
public function setRelationId(string $relationId): AnalyticsEventInterface;
44+
45+
public function getUuid(): string;
46+
47+
public function setUuid(string $uuid): AnalyticsEventInterface;
48+
49+
public function getType(): string;
50+
51+
public function setType(string $type): AnalyticsEventInterface;
52+
53+
public function getTopic(): string;
54+
55+
public function setTopic(string $topic): AnalyticsEventInterface;
56+
57+
public function getMessage(): ?string;
58+
59+
public function setMessage(?string $message = null): AnalyticsEventInterface;
60+
61+
public function getVersion(): string;
62+
63+
public function setVersion(string $version): AnalyticsEventInterface;
64+
65+
public function getErrorType(): ?string;
66+
67+
public function setErrorType(?string $errorType = null): AnalyticsEventInterface;
68+
69+
public function getErrorCode(): ?string;
70+
71+
public function setErrorCode(?string $errorCode = null): AnalyticsEventInterface;
72+
73+
public function getErrorCount(): int;
74+
75+
public function setErrorCount(int $errorCount): AnalyticsEventInterface;
76+
77+
public function getStatus(): string;
78+
79+
public function setStatus(string $status): AnalyticsEventInterface;
80+
81+
public function getCreatedAt(): string;
82+
83+
public function setCreatedAt(string $createdAt): AnalyticsEventInterface;
84+
85+
public function getCreatedAtTimestamp(): int;
86+
87+
public function getUpdatedAt(): ?string;
88+
89+
public function setUpdatedAt(?string $updatedAt = null): AnalyticsEventInterface;
90+
91+
public function getScheduledProcessingTime(): ?string;
92+
93+
public function setScheduledProcessingTime(?string $scheduledProcessingTime = null): AnalyticsEventInterface;
94+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Api\Data;
14+
15+
enum AnalyticsEventStatusEnum: int
16+
{
17+
case PENDING = 0;
18+
case PROCESSING = 1;
19+
case DONE = 2;
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Api\Data;
14+
15+
enum AnalyticsEventTypeEnum: string
16+
{
17+
case EXPECTED_START = 'expectedStart';
18+
case EXPECTED_END = 'expectedEnd';
19+
case UNEXPECTED_END = 'unexpectedEnd';
20+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment Module
5+
*
6+
* Copyright (c) 2025 Adyen N.V.
7+
* This file is open source and available under the MIT license.
8+
* See the LICENSE file for more info.
9+
*
10+
* Author: Adyen <magento@adyen.com>
11+
*/
12+
13+
namespace Adyen\Payment\Api\Data;
14+
15+
enum ConfigurationEventType: string
16+
{
17+
case PLUGIN_INSTALLATION = 'plugin_installation';
18+
}

Block/Checkout/Success.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,13 @@ public function __construct(
7979
* PresentToShopper e.g. Multibanco
8080
* Received e.g. Bank Transfer IBAN
8181
* @return bool
82+
* @throws LocalizedException
8283
*/
8384
public function renderAction(): bool
8485
{
86+
$code = $this->getResultCode();
8587
if (
86-
!empty($this->getOrder()->getPayment()->getAdditionalInformation('resultCode')) &&
88+
!empty($code) &&
8789
!empty($this->getOrder()->getPayment()->getAdditionalInformation('action')) &&
8890
(
8991
in_array($this->getOrder()->getPayment()->getAdditionalInformation('resultCode'),
@@ -187,4 +189,52 @@ public function getIsCustomerLoggedIn(): bool
187189
{
188190
return $this->customerSession->isLoggedIn();
189191
}
192+
193+
public function getResultCode()
194+
{
195+
try {
196+
return $this->getOrder()->getPayment()->getAdditionalInformation('resultCode');
197+
} catch (\Throwable $e) {
198+
return null;
199+
}
200+
}
201+
202+
/**
203+
* Checks if the result code is an intermediate result.
204+
*
205+
* @return bool
206+
*/
207+
public function isIntermediateResult(): bool
208+
{
209+
$code = $this->getResultCode();
210+
if (empty($code)) {
211+
return false;
212+
}
213+
214+
return in_array(
215+
$code,
216+
[
217+
PaymentResponseHandler::PENDING,
218+
PaymentResponseHandler::RECEIVED
219+
],
220+
true
221+
);
222+
}
223+
224+
/**
225+
* Return a pending message that will be displayed to the customer.
226+
*
227+
* This message will be displayed when the payment is still being processed.
228+
* The message will contain the order increment id if available.
229+
*
230+
* @throws LocalizedException
231+
*/
232+
public function getPendingMessage()
233+
{
234+
return __(
235+
'We’ve received your order %1, but your payment is still being processed. You’ll get an email once it’s confirmed. If the payment isn’t completed, your order may be cancelled automatically.',
236+
$this->getOrder()->getIncrementId()
237+
);
238+
}
239+
190240
}

Cron/AnalyticsEventsCleanUp.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment module (https://www.adyen.com/)
5+
*
6+
* Copyright (c) 2026 Adyen NV (https://www.adyen.com/)
7+
* See LICENSE.txt for license details.
8+
*
9+
* Author: Adyen <magento@adyen.com>
10+
*/
11+
12+
namespace Adyen\Payment\Cron;
13+
14+
use Adyen\Payment\Api\Data\AnalyticsEventInterface;
15+
use Adyen\Payment\Logger\AdyenLogger;
16+
use Adyen\Payment\Model\ResourceModel\AnalyticsEvent;
17+
use Adyen\Payment\Model\ResourceModel\AnalyticsEvent\CollectionFactory;
18+
use Exception;
19+
20+
class AnalyticsEventsCleanUp
21+
{
22+
/**
23+
* @param CollectionFactory $analyticsEventCollectionFactory
24+
* @param AnalyticsEvent $analyticsEventResourceModel
25+
* @param AdyenLogger $adyenLogger
26+
*/
27+
public function __construct(
28+
private readonly CollectionFactory $analyticsEventCollectionFactory,
29+
private readonly AnalyticsEvent $analyticsEventResourceModel,
30+
private readonly AdyenLogger $adyenLogger
31+
) {}
32+
33+
/**
34+
* This method is executed by the cron job `adyen_payment_clean_up_analytics_events` and deletes
35+
* the analytics events that are older than 45 days OR are in the done state.
36+
*
37+
* @return void
38+
*/
39+
public function execute(): void
40+
{
41+
try {
42+
$collection = $this->analyticsEventCollectionFactory->create()->analyticsEventsToCleanUp();
43+
44+
$ids = $collection->getColumnValues(AnalyticsEventInterface::ENTITY_ID);
45+
if (!empty($ids)) {
46+
$this->analyticsEventResourceModel->deleteByIds($ids);
47+
}
48+
} catch (Exception $e) {
49+
$this->adyenLogger->error(
50+
sprintf("An error occurred while cleaning up the analytics events: %s", $e->getMessage())
51+
);
52+
}
53+
}
54+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment module (https://www.adyen.com/)
5+
*
6+
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
7+
* See LICENSE.txt for license details.
8+
*
9+
* Author: Adyen <magento@adyen.com>
10+
*/
11+
12+
namespace Adyen\Payment\Cron\Providers;
13+
14+
use Adyen\Payment\Api\Data\AnalyticsEventInterface;
15+
16+
interface AnalyticsEventProviderInterface
17+
{
18+
const BATCH_SIZE = 1000;
19+
const CLEAN_UP_BATCH_SIZE = 5000;
20+
21+
/**
22+
* @return AnalyticsEventInterface[]
23+
*/
24+
public function provide(): array;
25+
26+
/**
27+
* @return string
28+
*/
29+
public function getAnalyticsContext(): string;
30+
31+
/**
32+
* @return string
33+
*/
34+
public function getProviderName(): string;
35+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
*
4+
* Adyen Payment module (https://www.adyen.com/)
5+
*
6+
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
7+
* See LICENSE.txt for license details.
8+
*
9+
* Author: Adyen <magento@adyen.com>
10+
*/
11+
12+
namespace Adyen\Payment\Cron\Providers;
13+
14+
use Adyen\AdyenException;
15+
use Adyen\Payment\Api\Data\AnalyticsEventInterface;
16+
use Adyen\Payment\Api\Data\AnalyticsEventTypeEnum;
17+
use Adyen\Payment\Helper\CheckoutAnalytics;
18+
use Adyen\Payment\Model\ResourceModel\AnalyticsEvent\Collection as AnalyticsEventCollection;
19+
use Adyen\Payment\Model\ResourceModel\AnalyticsEvent\CollectionFactory as AnalyticsEventCollectionFactory;
20+
21+
class PendingErrorsAnalyticsEventsProvider implements AnalyticsEventProviderInterface
22+
{
23+
const PROVIDER_NAME = 'Pending analytics events for `errors` context';
24+
25+
public function __construct(
26+
private readonly AnalyticsEventCollectionFactory $analyticsEventCollectionFactory
27+
) {}
28+
29+
/**
30+
* @return AnalyticsEventInterface[]
31+
* @throws AdyenException
32+
*/
33+
public function provide(): array
34+
{
35+
$analyticsEventCollection = $this->analyticsEventCollectionFactory->create();
36+
37+
/** @var AnalyticsEventCollection $analyticsEventCollection */
38+
$analyticsEventCollection = $analyticsEventCollection->pendingAnalyticsEvents([
39+
AnalyticsEventTypeEnum::UNEXPECTED_END
40+
]);
41+
42+
return $analyticsEventCollection->getItems();
43+
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getProviderName(): string
49+
{
50+
return self::PROVIDER_NAME;
51+
}
52+
53+
/**
54+
* @return string
55+
*/
56+
public function getAnalyticsContext(): string
57+
{
58+
return CheckoutAnalytics::CONTEXT_TYPE_ERRORS;
59+
}
60+
}

0 commit comments

Comments
 (0)