feat: [barobill] 카카오톡/SMS 발송 API 이관
- BarobillKakaotalkController 생성 (12개 엔드포인트) - 채널/템플릿 조회, 알림톡/친구톡 발송, 결과 조회, 예약 취소 - BarobillSmsController 생성 (4개 엔드포인트) - SMS 발송, 발신번호 관리, 전송 상태 조회 - finance.php 라우트 등록 (barobill/kakaotalk/*, barobill/sms/*) - 기존 BarobillSoapService SOAP 메서드 활용
This commit is contained in:
131
app/Http/Controllers/Api/V1/BarobillSmsController.php
Normal file
131
app/Http/Controllers/Api/V1/BarobillSmsController.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Helpers\ApiResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Barobill\BarobillMember;
|
||||
use App\Services\Barobill\BarobillSoapService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BarobillSmsController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
private BarobillSoapService $soapService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* SMS 발송
|
||||
*/
|
||||
public function send(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from_number' => 'required|string',
|
||||
'to_name' => 'required|string',
|
||||
'to_number' => 'required|string',
|
||||
'contents' => 'required|string',
|
||||
'send_dt' => 'nullable|string',
|
||||
'ref_key' => 'nullable|string',
|
||||
]);
|
||||
|
||||
return ApiResponse::handle(function () use ($data) {
|
||||
[$member, $corpNum] = $this->initSoap();
|
||||
|
||||
$result = $this->soapService->sendSMSMessage(
|
||||
$corpNum,
|
||||
$member->barobill_id,
|
||||
$data['from_number'],
|
||||
$data['to_name'],
|
||||
$data['to_number'],
|
||||
$data['contents'],
|
||||
$data['send_dt'] ?? '',
|
||||
$data['ref_key'] ?? ''
|
||||
);
|
||||
|
||||
return $this->formatResult($result, 'send_key');
|
||||
}, __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 발신번호 목록
|
||||
*/
|
||||
public function fromNumbers()
|
||||
{
|
||||
return ApiResponse::handle(function () {
|
||||
[$member, $corpNum] = $this->initSoap();
|
||||
|
||||
$result = $this->soapService->getSMSFromNumbers($corpNum);
|
||||
|
||||
return $this->formatResult($result, 'from_numbers');
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 발신번호 등록 여부 확인
|
||||
*/
|
||||
public function checkFromNumber(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
'from_number' => 'required|string',
|
||||
]);
|
||||
|
||||
return ApiResponse::handle(function () use ($data) {
|
||||
[$member, $corpNum] = $this->initSoap();
|
||||
|
||||
$result = $this->soapService->checkSMSFromNumber($corpNum, $data['from_number']);
|
||||
|
||||
return $this->formatResult($result, 'result');
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* SMS 전송 상태 조회
|
||||
*/
|
||||
public function sendState(string $sendKey)
|
||||
{
|
||||
return ApiResponse::handle(function () use ($sendKey) {
|
||||
[$member, $corpNum] = $this->initSoap();
|
||||
|
||||
$result = $this->soapService->getSMSSendState($corpNum, $sendKey);
|
||||
|
||||
return $this->formatResult($result, 'state');
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 바로빌 회원 조회 및 SOAP 초기화
|
||||
*/
|
||||
private function initSoap(): array
|
||||
{
|
||||
$member = $this->getMember();
|
||||
if (! $member) {
|
||||
throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException(
|
||||
__('error.barobill.member_not_found', [], 'ko') ?: '바로빌 회원사가 등록되어 있지 않습니다.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->soapService->initForMember($member);
|
||||
|
||||
return [$member, $member->biz_no];
|
||||
}
|
||||
|
||||
private function getMember(): ?BarobillMember
|
||||
{
|
||||
$tenantId = app('tenant_id');
|
||||
|
||||
return BarobillMember::withoutGlobalScopes()
|
||||
->where('tenant_id', $tenantId)
|
||||
->first();
|
||||
}
|
||||
|
||||
private function formatResult(array $result, string $key): array
|
||||
{
|
||||
if (! ($result['success'] ?? false)) {
|
||||
throw new \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException(
|
||||
$result['error'] ?? '바로빌 API 호출 실패'
|
||||
);
|
||||
}
|
||||
|
||||
return [$key => $result['data'] ?? null];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user