diff --git a/plugins/_bundled/sirsoft-message_bizppurio/CHANGELOG.md b/plugins/_bundled/sirsoft-message_bizppurio/CHANGELOG.md index 28c1dfb6..2423abfa 100644 --- a/plugins/_bundled/sirsoft-message_bizppurio/CHANGELOG.md +++ b/plugins/_bundled/sirsoft-message_bizppurio/CHANGELOG.md @@ -38,6 +38,7 @@ - 플러그인을 삭제하면 이 플러그인이 알림 설정에 추가했던 문자·알림톡 채널이 함께 정리됩니다. 메일·사이트 내 알림 등 다른 채널과 알림 자체는 그대로 유지되며, 플러그인을 다시 설치하면 문자·알림톡 채널이 자동으로 복원됩니다. - 잔액 부족으로 발송이 실패해 관리자에게 보내는 알림에서, 실패한 채널(문자/알림톡)과 결과 코드가 안내 문구에 실제 값으로 표시됩니다. 후불 결제 한도를 초과한 경우도 잔액 부족과 동일하게 관리자에게 알립니다. - 발송 결과 코드의 사유 안내를 비즈뿌리오 최신 공식 명세에 맞춰 정비했습니다. 일부 코드의 설명을 정정하고 누락된 코드(접속 IP 오류, 수신거부, 발신 프로필 키 오류 등)를 추가해, 발송 이력에서 실패 사유가 더 정확히 표시됩니다. +- 발송 요청이 실패하면 비즈뿌리오가 알려준 실제 사유와 결과 코드가 발송 이력에 기록됩니다. 예전에는 "발송 요청 실패"로만 표시되어 원인을 알 수 없었지만, 이제 "발신 프로필 키가 유효하지 않음 (7103)"처럼 구체적인 사유가 표시되어 문제를 바로 확인할 수 있습니다. ### Changed diff --git a/plugins/_bundled/sirsoft-message_bizppurio/src/Services/BizppurioApiClient.php b/plugins/_bundled/sirsoft-message_bizppurio/src/Services/BizppurioApiClient.php index d8c6a50b..d7ffd430 100644 --- a/plugins/_bundled/sirsoft-message_bizppurio/src/Services/BizppurioApiClient.php +++ b/plugins/_bundled/sirsoft-message_bizppurio/src/Services/BizppurioApiClient.php @@ -100,8 +100,18 @@ class BizppurioApiClient ->post($this->baseUrl().'/v3/message', $payload); if ($response->failed()) { + // 비즈뿌리오는 실패 응답에도 code·description 을 담아준다(명세). 이를 추출해 + // 예외에 실어, 발송 이력·로그에 "왜 실패했는지"(결과코드+사유)가 남도록 한다. + // body 가 없거나 파싱 불가하면 HTTP 상태만 보존한다. + $body = $response->json(); + $code = is_array($body) ? (string) ($body['code'] ?? '') : ''; + $description = is_array($body) ? (string) ($body['description'] ?? '') : ''; + throw new BizppurioApiException( - __('sirsoft-message_bizppurio::messages.error.send_failed'), + $description !== '' + ? $description + : __('sirsoft-message_bizppurio::messages.error.send_failed'), + resultCode: $code !== '' ? $code : null, httpStatus: $response->status(), ); } diff --git a/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/BizppurioApiClientTest.php b/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/BizppurioApiClientTest.php index 84397004..e36ba1f8 100644 --- a/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/BizppurioApiClientTest.php +++ b/plugins/_bundled/sirsoft-message_bizppurio/tests/Unit/Services/BizppurioApiClientTest.php @@ -110,6 +110,50 @@ class BizppurioApiClientTest extends PluginTestCase $client->sendMessage($this->payload); } + /** + * HTTP 실패 응답에 code·description 이 있으면 예외에 사유·결과코드로 담긴다. + * + * 회귀 배경: 실패 시 "메시지 발송 요청에 실패했습니다"만 뜨고 비즈뿌리오가 준 실제 사유·코드를 + * 버려, 발송 이력·로그로 원인을 알 수 없던 문제. 실패 body 를 추출해 예외에 실어 이력에 남긴다. + */ + public function test_http_실패시_응답_body_의_사유와_코드가_예외에_담긴다(): void + { + Http::fake([ + '*/v3/message' => Http::response( + ['code' => 7103, 'description' => '발신 프로필 키가 유효하지 않음'], + 400, + ), + ]); + + $client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings()); + + try { + $client->sendMessage($this->payload); + $this->fail('예외가 발생해야 한다.'); + } catch (BizppurioApiException $e) { + $this->assertSame('7103', $e->getResultCode(), '실패 body 의 code 가 예외에 담겨야 한다.'); + $this->assertSame('발신 프로필 키가 유효하지 않음', $e->getMessage(), '실패 body 의 description 이 예외 메시지로 담겨야 한다.'); + } + } + + /** + * HTTP 실패 응답에 body 가 없으면 기본 사유로 폴백하고 결과코드는 null. + */ + public function test_http_실패시_body_없으면_기본_사유_폴백(): void + { + Http::fake(['*/v3/message' => Http::response([], 500)]); + + $client = new BizppurioApiClient($this->makeToken('T'), $this->makeSettings()); + + try { + $client->sendMessage($this->payload); + $this->fail('예외가 발생해야 한다.'); + } catch (BizppurioApiException $e) { + $this->assertNull($e->getResultCode()); + $this->assertNotSame('', $e->getMessage()); + } + } + public function test_영구실패_결과코드는_그대로_반환(): void { Http::fake([