- Implemented ShopproPaymentStatusSyncService to handle payment status synchronization between Shoppro and Orderpro. - Added methods for resolving watched status codes, finding candidate orders, and syncing individual order payments. - Introduced ShopproStatusMappingRepository for managing status mappings between Shoppro and Orderpro. - Created ShopproStatusSyncService to facilitate synchronization of order statuses from Shoppro to Orderpro.
65 lines
1.7 KiB
PHP
65 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Settings;
|
|
|
|
use PDO;
|
|
|
|
final class ApaczkaIntegrationRepository
|
|
{
|
|
private const INTEGRATION_TYPE = 'apaczka';
|
|
private const INTEGRATION_NAME = 'Apaczka';
|
|
private const INTEGRATION_BASE_URL = 'https://www.apaczka.pl';
|
|
|
|
private readonly IntegrationsRepository $integrations;
|
|
private readonly IntegrationSecretCipher $cipher;
|
|
|
|
public function __construct(
|
|
private readonly PDO $pdo,
|
|
private readonly string $secret
|
|
) {
|
|
$this->integrations = new IntegrationsRepository($this->pdo);
|
|
$this->cipher = new IntegrationSecretCipher($this->secret);
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function getSettings(): array
|
|
{
|
|
$integrationId = $this->ensureBaseIntegration();
|
|
$integration = $this->integrations->findById($integrationId);
|
|
|
|
return [
|
|
'has_api_key' => trim((string) ($integration['api_key_encrypted'] ?? '')) !== '',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, mixed> $payload
|
|
*/
|
|
public function saveSettings(array $payload): void
|
|
{
|
|
$integrationId = $this->ensureBaseIntegration();
|
|
|
|
$apiKey = trim((string) ($payload['api_key'] ?? ''));
|
|
if ($apiKey === '') {
|
|
return;
|
|
}
|
|
|
|
$encrypted = $this->cipher->encrypt($apiKey);
|
|
$this->integrations->updateApiKeyEncrypted($integrationId, $encrypted);
|
|
}
|
|
|
|
private function ensureBaseIntegration(): int
|
|
{
|
|
return $this->integrations->ensureIntegration(
|
|
self::INTEGRATION_TYPE,
|
|
self::INTEGRATION_NAME,
|
|
self::INTEGRATION_BASE_URL,
|
|
20,
|
|
true
|
|
);
|
|
}
|
|
}
|