현금영수증 발급사를 PG 결제사와 독립적으로 선택할 수 있도록 공용 훅 축 (registered_providers/issue/cancel)에 토스·KG 프로바이더를 등록한다. KG 결제로 받으면서 영수증만 토스로 발급하는 구성이 가능해진다. KG 전용 발행 컨트롤러· 라우트·관리자 패널은 이 축으로 이전하며 제거했다 — 이중 발행 경로를 남기지 않기 위해서다. 토스 환불은 네 가지를 바로잡았다. 전액취소를 부분취소로 보내던 문제(R1), 면세금액 미전달로 복합과세 상점의 부가세가 틀어지던 문제(R2), 가상계좌 환불계좌를 싣지 않아 취소가 실패하던 문제(R3), 에스크로 부분취소를 PG 호출 전에 차단하지 않던 문제(E4). 취소·발급 요청에는 멱등키를 부착해 네트워크 재시도가 국세청에 이중 신고되거나 이중 환불되는 것을 막는다. 코어 활동로그 가드가 \Exception 만 잡아 채널 해석 실패(\Error)를 놓치고 있었다. 결제 입금통보 같은 외부 콜백이 로그 문제만으로 500을 반환하던 문제를 \Throwable 로 수정한다. 활동로그는 부수 기록이므로 그것을 유발한 요청까지 죽여서는 안 된다. 토스 API 서비스는 베이스 \Exception 을 직접 던지고 있어 도메인 예외 (TossPaymentsApiException)를 신설했다. KG의 KgInicisApiException 선례와 동형이며 RuntimeException 상속이라 기존 소비자의 catch 는 그대로 동작한다.
90 lines
3.1 KiB
PHP
90 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace Plugins\Sirsoft\VerificationKginicis\Tests\Unit\Services;
|
|
|
|
use Plugins\Sirsoft\VerificationKginicis\Services\InicisCallbackOutcome;
|
|
use Plugins\Sirsoft\VerificationKginicis\Tests\PluginTestCase;
|
|
|
|
/**
|
|
* InicisCallbackOutcome DTO 단위 테스트.
|
|
*
|
|
* Value Object factory + bridge query 변환만 검증한다. 지금은 DB/컨테이너를 쓰지 않지만,
|
|
* 확장 테스트는 PluginTestCase 를 상속한다 — 나중에 컨테이너/설정을 건드리는 단언이 추가될 때
|
|
* 조용히 다른 환경에서 도는 테스트가 되는 것을 막는다.
|
|
*/
|
|
class InicisCallbackOutcomeTest extends PluginTestCase
|
|
{
|
|
public function test_success_factory_produces_verified_outcome_with_token_and_challenge_id(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::success(
|
|
challengeId: 'ch-uuid-1',
|
|
verificationToken: 'tok-abc',
|
|
);
|
|
|
|
$this->assertTrue($outcome->success);
|
|
$this->assertSame('ch-uuid-1', $outcome->challengeId);
|
|
$this->assertSame('tok-abc', $outcome->verificationToken);
|
|
$this->assertNull($outcome->failureCode);
|
|
}
|
|
|
|
public function test_failure_factory_with_challenge_id_preserves_both_fields(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::failure(
|
|
challengeId: 'ch-uuid-2',
|
|
failureCode: 'ALREADY_CONSUMED',
|
|
);
|
|
|
|
$this->assertFalse($outcome->success);
|
|
$this->assertSame('ch-uuid-2', $outcome->challengeId);
|
|
$this->assertSame('ALREADY_CONSUMED', $outcome->failureCode);
|
|
$this->assertNull($outcome->verificationToken);
|
|
}
|
|
|
|
public function test_failure_factory_without_challenge_id_defaults_to_null(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::failure(failureCode: 'PROVIDER_ERROR');
|
|
|
|
$this->assertFalse($outcome->success);
|
|
$this->assertNull($outcome->challengeId);
|
|
$this->assertSame('PROVIDER_ERROR', $outcome->failureCode);
|
|
}
|
|
|
|
public function test_failure_factory_with_default_failure_code_uses_unknown(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::failure();
|
|
|
|
$this->assertFalse($outcome->success);
|
|
$this->assertSame('UNKNOWN', $outcome->failureCode);
|
|
}
|
|
|
|
public function test_to_bridge_query_for_success_returns_token_and_challenge_id(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::success(
|
|
challengeId: 'ch-uuid-3',
|
|
verificationToken: 'tok-xyz',
|
|
);
|
|
|
|
$this->assertSame(
|
|
['verification_token' => 'tok-xyz', 'challenge_id' => 'ch-uuid-3'],
|
|
$outcome->toBridgeQuery(),
|
|
);
|
|
}
|
|
|
|
public function test_to_bridge_query_for_failure_returns_only_identity_error(): void
|
|
{
|
|
$outcome = InicisCallbackOutcome::failure(
|
|
challengeId: 'ch-uuid-4',
|
|
failureCode: 'NOT_FOUND',
|
|
);
|
|
|
|
$this->assertSame(['identity_error' => 'NOT_FOUND'], $outcome->toBridgeQuery());
|
|
}
|
|
|
|
public function test_to_bridge_query_handles_null_failure_code_as_empty_string(): void
|
|
{
|
|
$outcome = new InicisCallbackOutcome(success: false);
|
|
|
|
$this->assertSame(['identity_error' => ''], $outcome->toBridgeQuery());
|
|
}
|
|
}
|