fix:알림톡 미설정 시 에러 방지 - 기본 발송을 이메일로 변경, 알림톡 실패 시 이메일 자동 폴백

This commit is contained in:
김보곤
2026-02-19 23:50:37 +09:00
parent 6cf440f349
commit 3724bc4475
2 changed files with 37 additions and 23 deletions

View File

@@ -760,7 +760,7 @@ public function send(Request $request, int $id): JsonResponse
return response()->json(['success' => false, 'message' => '초안 상태에서만 발송할 수 있습니다.'], 422);
}
$sendMethod = $request->input('send_method', 'alimtalk');
$sendMethod = $request->input('send_method', 'email');
$smsFallback = $request->boolean('sms_fallback', true);
$contract->update([
@@ -848,7 +848,7 @@ public function remind(Request $request, int $id): JsonResponse
$nextSigner->update(['status' => 'notified']);
$results = $this->dispatchNotification(
$contract, $nextSigner,
$contract->send_method ?? 'alimtalk',
$contract->send_method ?? 'email',
$contract->sms_fallback ?? true,
isReminder: true,
);
@@ -908,26 +908,34 @@ private function dispatchNotification(
bool $isReminder = false,
): array {
$results = [];
$alimtalkFailed = false;
// 알림톡 발송
if (in_array($sendMethod, ['alimtalk', 'both']) && $signer->phone) {
$results[] = $this->sendAlimtalk($contract, $signer, $smsFallback, $isReminder);
$alimtalkResult = $this->sendAlimtalk($contract, $signer, $smsFallback, $isReminder);
$results[] = $alimtalkResult;
$alimtalkFailed = !($alimtalkResult['success'] ?? false);
}
// 이메일 발송 (email/both 선택 시, 또는 알림톡인데 번호 없으면 폴백)
if (in_array($sendMethod, ['email', 'both']) || ($sendMethod === 'alimtalk' && !$signer->phone)) {
if ($signer->email) {
try {
Mail::to($signer->email)->send(new EsignRequestMail($contract, $signer, $isReminder));
$results[] = ['success' => true, 'channel' => 'email', 'error' => null];
} catch (\Throwable $e) {
\Log::warning('E-Sign 이메일 발송 실패', [
'contract_id' => $contract->id,
'signer_id' => $signer->id,
'error' => $e->getMessage(),
]);
$results[] = ['success' => false, 'channel' => 'email', 'error' => $e->getMessage()];
}
// 이메일 발송 조건:
// 1) email/both 선택 시
// 2) alimtalk인데 번호 없으면 폴백
// 3) alimtalk 발송 실패 시 이메일 자동 폴백
$shouldSendEmail = in_array($sendMethod, ['email', 'both'])
|| ($sendMethod === 'alimtalk' && !$signer->phone)
|| ($sendMethod === 'alimtalk' && $alimtalkFailed);
if ($shouldSendEmail && $signer->email) {
try {
Mail::to($signer->email)->send(new EsignRequestMail($contract, $signer, $isReminder));
$results[] = ['success' => true, 'channel' => 'email', 'error' => null];
} catch (\Throwable $e) {
\Log::warning('E-Sign 이메일 발송 실패', [
'contract_id' => $contract->id,
'signer_id' => $signer->id,
'error' => $e->getMessage(),
]);
$results[] = ['success' => false, 'channel' => 'email', 'error' => $e->getMessage()];
}
}
@@ -949,6 +957,10 @@ private function sendAlimtalk(
return ['success' => false, 'channel' => 'alimtalk', 'error' => '바로빌 회원 미등록'];
}
if (!$member->corp_num) {
return ['success' => false, 'channel' => 'alimtalk', 'error' => '사업자번호 미설정 (알림톡 발송 불가)'];
}
$barobill = app(BarobillService::class);
$barobill->setServerMode($member->is_test_mode ? 'test' : 'production');