Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Backend/Controllers/MessagingAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
/** Налаштування провайдера SMS та типів повідомлень; баланс і приблизна к-сть SMS. */
class MessagingAdmin extends IndexAdmin
{
private const TURBOSMS_PRICE_PER_SMS = 1.29;
private const SMSCLUB_PRICE_PER_SMS = 1.29;
private const float TURBOSMS_PRICE_PER_SMS = 1.29;
private const float SMSCLUB_PRICE_PER_SMS = 1.29;

public function fetch(SmsClubProvider $smsClubProvider, TurboSmsProvider $turbosmsProvider, EntityFactory $entityFactory)
{
Expand Down
8 changes: 4 additions & 4 deletions Helpers/DeliveryStatusMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeliveryStatusMapping
public const EVENT_RECEIVED = 'received';

/** Код НП => [system_status, event]. В дорозі: 4,41,5,6,101. Прибуло: 7,8. Отримано: 9,10,11. */
private const NOVA_POSHTA_MAP = [
private const array NOVA_POSHTA_MAP = [
'4' => [self::SYSTEM_IN_TRANSIT, self::EVENT_SHIPPED],
'41' => [self::SYSTEM_IN_TRANSIT, self::EVENT_SHIPPED],
'5' => [self::SYSTEM_IN_TRANSIT, self::EVENT_SHIPPED],
Expand All @@ -29,9 +29,9 @@ class DeliveryStatusMapping
'11' => [self::SYSTEM_RECEIVED, self::EVENT_RECEIVED],
];

private const NP_IN_TRANSIT = ['4' => true, '41' => true, '5' => true, '6' => true, '101' => true];
private const NP_ARRIVED = ['7' => true, '8' => true];
private const NP_RECEIVED = ['9' => true, '10' => true, '11' => true];
private const array NP_IN_TRANSIT = ['4' => true, '41' => true, '5' => true, '6' => true, '101' => true];
private const array NP_ARRIVED = ['7' => true, '8' => true];
private const array NP_RECEIVED = ['9' => true, '10' => true, '11' => true];

/** Статуси, для яких не створюємо події: отримано, видалено, відмова, повернення, тощо. */
public const NP_FINAL_STATUSES = ['2', '3', '9', '10', '11', '102', '103', '105', '106'];
Expand Down
2 changes: 1 addition & 1 deletion Helpers/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/** Тексти SMS за типами подій. */
class MessageTemplates
{
private const DEFAULT_PARAMS = [
private const array DEFAULT_PARAMS = [
'doc_number' => '',
'order_id' => '',
'warehouse' => '',
Expand Down
18 changes: 9 additions & 9 deletions Helpers/MessagingCronHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
/** Крон: події доставки НП → створення/відправка SMS; повтор при помилках. */
class MessagingCronHelper
{
private const NOVA_POSHTA_TRACKING_ENTITY_CLASS = 'Okay\Modules\Sviat\NovaPoshtaTracking\Entities\NovaPoshtaTrackingEntity';
private const string NOVA_POSHTA_TRACKING_ENTITY_CLASS = \Okay\Modules\Sviat\NovaPoshtaTracking\Entities\NovaPoshtaTrackingEntity::class;

private const STORAGE_FREE_DAYS = 7;
private const STORAGE_WARNING_DAY = 6;
private const SEC_PER_HOUR = 3600;
private const SEC_PER_DAY = 86400;
private const int STORAGE_FREE_DAYS = 7;
private const int STORAGE_WARNING_DAY = 6;
private const int SEC_PER_HOUR = 3600;
private const int SEC_PER_DAY = 86400;

private const SETTING_SHIPPED = 'sviat__messaging__shipped_enabled';
private const SETTING_ARRIVED = 'sviat__messaging__arrived_enabled';
private const SETTING_REMINDER_2DAY = 'sviat__messaging__reminder_2day_enabled';
private const SETTING_STORAGE_WARNING = 'sviat__messaging__storage_warning_enabled';
private const string SETTING_SHIPPED = 'sviat__messaging__shipped_enabled';
private const string SETTING_ARRIVED = 'sviat__messaging__arrived_enabled';
private const string SETTING_REMINDER_2DAY = 'sviat__messaging__reminder_2day_enabled';
private const string SETTING_STORAGE_WARNING = 'sviat__messaging__storage_warning_enabled';

private $entityFactory;
private $eventService;
Expand Down
4 changes: 2 additions & 2 deletions Helpers/PhoneFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/** Формат і валідація номера для SMS (UA, E.164). */
class PhoneFormatter
{
private const MIN_DIGITS = 9;
private const int MIN_DIGITS = 9;

public static function format(string $phone): ?string
{
Expand All @@ -23,7 +23,7 @@ public static function format(string $phone): ?string
return null;
}
return $phoneUtil->format($parsed, \libphonenumber\PhoneNumberFormat::E164);
} catch (\Exception $e) {
} catch (\Exception) {
return null;
}
}
Expand Down
38 changes: 19 additions & 19 deletions Init/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ public function install()
{
$this->setBackendMainController('MessagingAdmin');
$this->migrateEntityTable(NotificationLogEntity::class, [
(new EntityField('id'))->setIndexPrimaryKey()->setTypeInt(11, false)->setAutoIncrement(),
(new EntityField('order_id'))->setTypeInt(11)->setNullable()->setIndex(),
(new EntityField('phone'))->setTypeVarchar(32)->setIndex(),
(new EntityField('channel'))->setTypeEnum(['sms', 'viber'], false)->setIndex(),
(new EntityField('type'))->setTypeEnum(['shipped', 'arrived', 'reminder_2day', 'storage_warning', 'manual'], false)->setIndex(),
(new EntityField('status'))->setTypeEnum(['pending', 'sent', 'error', 'skipped'], false)->setIndex(),
(new EntityField('priority'))->setTypeTinyInt(2)->setNullable()->setDefault(5),
(new EntityField('message'))->setTypeText()->setNullable(),
(new EntityField('provider'))->setTypeVarchar(64)->setNullable(),
(new EntityField('provider_message_id'))->setTypeVarchar(255)->setNullable(),
(new EntityField('event_key'))->setTypeVarchar(255)->setNullable()->setIndexUnique(),
(new EntityField('attempts'))->setTypeInt(11)->setNullable()->setDefault(0),
(new EntityField('error_text'))->setTypeText()->setNullable(),
(new EntityField('meta'))->setTypeLongText()->setNullable(),
(new EntityField('created_at'))->setTypeDatetime()->setNullable()->setIndex(),
(new EntityField('scheduled_at'))->setTypeDatetime()->setNullable(),
(new EntityField('sent_at'))->setTypeDatetime()->setNullable(),
new EntityField('id')->setIndexPrimaryKey()->setTypeInt(11, false)->setAutoIncrement(),
new EntityField('order_id')->setTypeInt(11)->setNullable()->setIndex(),
new EntityField('phone')->setTypeVarchar(32)->setIndex(),
new EntityField('channel')->setTypeEnum(['sms', 'viber'], false)->setIndex(),
new EntityField('type')->setTypeEnum(['shipped', 'arrived', 'reminder_2day', 'storage_warning', 'manual'], false)->setIndex(),
new EntityField('status')->setTypeEnum(['pending', 'sent', 'error', 'skipped'], false)->setIndex(),
new EntityField('priority')->setTypeTinyInt(2)->setNullable()->setDefault(5),
new EntityField('message')->setTypeText()->setNullable(),
new EntityField('provider')->setTypeVarchar(64)->setNullable(),
new EntityField('provider_message_id')->setTypeVarchar(255)->setNullable(),
new EntityField('event_key')->setTypeVarchar(255)->setNullable()->setIndexUnique(),
new EntityField('attempts')->setTypeInt(11)->setNullable()->setDefault(0),
new EntityField('error_text')->setTypeText()->setNullable(),
new EntityField('meta')->setTypeLongText()->setNullable(),
new EntityField('created_at')->setTypeDatetime()->setNullable()->setIndex(),
new EntityField('scheduled_at')->setTypeDatetime()->setNullable(),
new EntityField('sent_at')->setTypeDatetime()->setNullable(),
]);
}

Expand All @@ -41,14 +41,14 @@ public function init()
$this->addBackendControllerPermission('MessagingAdmin', 'sviat__messaging');

$this->registerSchedule(
(new Schedule([MessagingCronHelper::class, 'processEventsAndSend']))
new Schedule([MessagingCronHelper::class, 'processEventsAndSend'])
->name('Messaging: process events and send SMS')
->time('*/20 * * * *')
->overlap(false)
->timeout(600)
);
$this->registerSchedule(
(new Schedule([MessagingCronHelper::class, 'retryFailed']))
new Schedule([MessagingCronHelper::class, 'retryFailed'])
->name('Messaging: retry failed SMS')
->time('*/15 * * * *')
->overlap(false)
Expand Down
2 changes: 1 addition & 1 deletion Init/module.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Okay": "4.5.3",
"version": "1.0.2",
"version": "1.0.3",
"moduleName": "Messaging (SMS/Viber повідомлення)",
"vendor": {
"email": "devsviat@proton.me",
Expand Down
10 changes: 5 additions & 5 deletions Providers/SmsClubProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
/** SMS Club API (Bearer token): send, balance, status, originators. */
class SmsClubProvider implements SmsProviderInterface
{
private const API_BASE = 'https://im.smsclub.mobi/sms';
private const API_SEND = self::API_BASE . '/send';
private const API_BALANCE = self::API_BASE . '/balance';
private const API_STATUS = self::API_BASE . '/status';
private const API_ORIGINATOR = self::API_BASE . '/originator';
private const string API_BASE = 'https://im.smsclub.mobi/sms';
private const string API_SEND = self::API_BASE . '/send';
private const string API_BALANCE = self::API_BASE . '/balance';
private const string API_STATUS = self::API_BASE . '/status';
private const string API_ORIGINATOR = self::API_BASE . '/originator';

private $settings;

Expand Down
8 changes: 4 additions & 4 deletions Providers/TurboSmsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
/** TurboSMS API (Bearer token): send, balance, status. */
class TurboSmsProvider implements SmsProviderInterface
{
private const API_BASE = 'https://api.turbosms.ua';
private const API_SEND_URL = self::API_BASE . '/message/send.json';
private const API_STATUS_URL = self::API_BASE . '/message/status.json';
private const API_BALANCE_URL = self::API_BASE . '/user/balance.json';
private const string API_BASE = 'https://api.turbosms.ua';
private const string API_SEND_URL = self::API_BASE . '/message/send.json';
private const string API_STATUS_URL = self::API_BASE . '/message/status.json';
private const string API_BALANCE_URL = self::API_BASE . '/user/balance.json';

private $settings;

Expand Down
2 changes: 1 addition & 1 deletion Services/NotificationEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function isCashOnDelivery(object $order): bool
try {
$npData = $this->entityFactory->get(NPCostDeliveryDataEntity::class)->findOne(['order_id' => $order->id]);
return $npData && !empty($npData->control_payment);
} catch (\Throwable $e) {
} catch (\Throwable) {
return false;
}
}
Expand Down
Loading