From a52f412cfcfc53771b544299a0b325d5edb894b4 Mon Sep 17 00:00:00 2001 From: hamed <15238-genius.ha@users.noreply.drupalcode.org> Date: Mon, 15 Jun 2026 18:00:13 +0330 Subject: [PATCH] feat(payment): confirm appointment and SMS the patient on success MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The payment callback handled subscription and sms-wallet types but left appointment payments pending. Add a TYPE_APPOINTMENT branch that transitions the booking pending → confirmed (guarded by canTransitionTo, so an already-expired booking is skipped) and dispatches a confirmation SMS to the patient's mobile. Co-Authored-By: Claude Opus 4.8 --- src/Payment/Controller/PaymentController.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Payment/Controller/PaymentController.php b/src/Payment/Controller/PaymentController.php index 344743ad..9331ac98 100644 --- a/src/Payment/Controller/PaymentController.php +++ b/src/Payment/Controller/PaymentController.php @@ -16,6 +16,7 @@ use App\Payment\Repository\PaymentRepository; use App\Payment\Service\CircuitBreakerService; use App\Shared\Constant\ErrorCodes; use App\Shared\Controller\BaseController; +use App\Sms\Service\SmsService; use App\Sms\Service\SmsWalletService; use App\Subscription\Service\SubscriptionService; use OpenApi\Attributes as OA; @@ -44,6 +45,7 @@ class PaymentController extends BaseController private readonly CircuitBreakerService $circuitBreaker, private readonly SubscriptionService $subscriptionService, private readonly SmsWalletService $smsWalletService, + private readonly SmsService $smsService, private readonly DoctorRepository $doctorRepo, private readonly ClinicRepository $clinicRepo, private readonly SiteConfigRepository $configRepo, @@ -273,6 +275,8 @@ class PaymentController extends BaseController $this->handleSubscriptionActivation($payment); } elseif ($payment->getType() === Payment::TYPE_SMS_WALLET) { $this->handleSmsWalletCharge($payment); + } elseif ($payment->getType() === Payment::TYPE_APPOINTMENT) { + $this->handleAppointmentConfirmation($payment); } return $this->redirectToFrontend($payment, true); @@ -590,6 +594,26 @@ class PaymentController extends BaseController $this->smsWalletService->charge($wallet, $payment->getAmountRials(), $payment); } + private function handleAppointmentConfirmation(Payment $payment): void + { + $appointment = $payment->getAppointment(); + if ($appointment === null || !$appointment->canTransitionTo(Appointment::STATUS_CONFIRMED)) { + return; + } + + $appointment->transitionTo(Appointment::STATUS_CONFIRMED); + $this->appointmentRepo->save($appointment); + + $mobile = $appointment->getPatientMobile(); + if ($mobile) { + $when = date('Y-m-d H:i', $appointment->getSlotStart()); + $this->smsService->dispatchAsync( + $mobile, + sprintf('نوبت شما با %s در تاریخ %s ثبت و تأیید شد.', $appointment->getDoctor()->getName(), $when) + ); + } + } + private function handleSubscriptionActivation(Payment $payment): void { $meta = $payment->getMetadata() ?? [];