From 71edc772c88de51ac37f45e91a2c1f03ac25ec72 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Thu, 25 Jun 2026 16:34:54 +0330 Subject: [PATCH] feat(payment): add Jalali date formatting for appointment confirmation SMS --- docs/api/payment.md | 2 +- src/Payment/Controller/PaymentController.php | 3 ++- src/Representation/Service/JalaliDateService.php | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/api/payment.md b/docs/api/payment.md index 9735b0e4..08b72222 100644 --- a/docs/api/payment.md +++ b/docs/api/payment.md @@ -109,7 +109,7 @@ Initiate payment for an appointment. Returns a redirect URL to the payment gatew > **مبلغ نوبت:** مبلغِ پرداخت از کلید `appointment_fee_rials` تنظیمات سایت خوانده می‌شود (نه از client و نه hardcode). برای تغییر، در `/admin/settings` ویرایش کنید. > -> **On successful callback** for an appointment payment, the booking is transitioned `pending → confirmed` (its 15-minute `expires_at` is cleared) and a confirmation SMS is dispatched to the patient's mobile. If the booking already lapsed to `expired` before payment confirmed, it is **not** re-confirmed (the transition is rejected) — handle refund out of band. +> **On successful callback** for an appointment payment, the booking is transitioned `pending → confirmed` (its 15-minute `expires_at` is cleared) and a confirmation SMS is dispatched to the patient's mobile. تاریخِ نوبت در متن پیامک به‌صورت **شمسی** (`JalaliDateService::formatDateTime`، مثل `۱۴۰۵/۰۴/۰۲ ۰۹:۰۰`) درج می‌شود. If the booking already lapsed to `expired` before payment confirmed, it is **not** re-confirmed (the transition is rejected) — handle refund out of band. > > **پورسانت نماینده:** اگر پزشک نوبت `representation_id` داشته باشد و `appointment_commission_enabled=1` باشد، پس از confirm شدن `CommissionService` هزینه پنل پیامک و مالیات را کسر و سهم نماینده را به کیف‌پولش واریز می‌کند (ردیف `FinancialBreakdown` ثبت می‌شود). برای پرداخت اشتراک هم اگر `upgrade_commission_enabled=1` و پزشک/کلینیک `representation_id` داشته باشد همین منطق با درصد `upgrade_commission_percent` اعمال می‌شود. کلیدهای تنظیمات و ترتیب محاسبه در `docs/api/admin.md`. diff --git a/src/Payment/Controller/PaymentController.php b/src/Payment/Controller/PaymentController.php index 1f0b7020..ec2c6ac1 100644 --- a/src/Payment/Controller/PaymentController.php +++ b/src/Payment/Controller/PaymentController.php @@ -51,6 +51,7 @@ class PaymentController extends BaseController private readonly ClinicRepository $clinicRepo, private readonly SiteConfigRepository $configRepo, private readonly \App\Settlement\Service\CommissionService $commissionService, + private readonly \App\Representation\Service\JalaliDateService $jalali, private readonly string $appBaseUrl, private readonly string $allowedFrontendHosts = '', ) {} @@ -646,7 +647,7 @@ class PaymentController extends BaseController $mobile = $appointment->getPatientMobile(); if ($mobile) { - $when = date('Y-m-d H:i', $appointment->getSlotStart()); + $when = $this->jalali->formatDateTime($appointment->getSlotStart()); $message = $this->smsText->resolve(\App\Sms\Entity\SmsLog::TAG_PAYMENT, [ 'doctor' => $appointment->getDoctor()->getName(), 'date' => $when, diff --git a/src/Representation/Service/JalaliDateService.php b/src/Representation/Service/JalaliDateService.php index 010699e9..cd8640b8 100644 --- a/src/Representation/Service/JalaliDateService.php +++ b/src/Representation/Service/JalaliDateService.php @@ -43,6 +43,21 @@ class JalaliDateService return [$jy, $jm, $jd]; } + /** تبدیل timestamp به رشته‌ی شمسی: «۱۴۰۵/۰۴/۰۲ ۰۹:۰۰» (پیش‌فرض با ساعت). */ + public function formatDateTime(int $timestamp, bool $withTime = true): string + { + $pattern = $withTime ? 'yyyy/MM/dd HH:mm' : 'yyyy/MM/dd'; + $f = new \IntlDateFormatter( + 'fa_IR@calendar=persian', + \IntlDateFormatter::NONE, + \IntlDateFormatter::NONE, + 'Asia/Tehran', + \IntlDateFormatter::TRADITIONAL, + $pattern, + ); + return $f->format($timestamp); + } + public function jalaliYear(int $timestamp): int { return $this->gregorianToJalali(