현금영수증 발급사를 PG 결제사와 독립적으로 선택할 수 있도록 공용 훅 축 (registered_providers/issue/cancel)에 토스·KG 프로바이더를 등록한다. KG 결제로 받으면서 영수증만 토스로 발급하는 구성이 가능해진다. KG 전용 발행 컨트롤러· 라우트·관리자 패널은 이 축으로 이전하며 제거했다 — 이중 발행 경로를 남기지 않기 위해서다. 토스 환불은 네 가지를 바로잡았다. 전액취소를 부분취소로 보내던 문제(R1), 면세금액 미전달로 복합과세 상점의 부가세가 틀어지던 문제(R2), 가상계좌 환불계좌를 싣지 않아 취소가 실패하던 문제(R3), 에스크로 부분취소를 PG 호출 전에 차단하지 않던 문제(E4). 취소·발급 요청에는 멱등키를 부착해 네트워크 재시도가 국세청에 이중 신고되거나 이중 환불되는 것을 막는다. 코어 활동로그 가드가 \Exception 만 잡아 채널 해석 실패(\Error)를 놓치고 있었다. 결제 입금통보 같은 외부 콜백이 로그 문제만으로 500을 반환하던 문제를 \Throwable 로 수정한다. 활동로그는 부수 기록이므로 그것을 유발한 요청까지 죽여서는 안 된다. 토스 API 서비스는 베이스 \Exception 을 직접 던지고 있어 도메인 예외 (TossPaymentsApiException)를 신설했다. KG의 KgInicisApiException 선례와 동형이며 RuntimeException 상속이라 기존 소비자의 catch 는 그대로 동작한다.
111 lines
4.0 KiB
PHP
111 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Ecommerce\Tests\Unit\Services;
|
|
|
|
use App\Extension\HookManager;
|
|
use Illuminate\Support\Facades\File;
|
|
use Modules\Sirsoft\Ecommerce\Services\EcommerceSettingsService;
|
|
use Modules\Sirsoft\Ecommerce\Tests\ModuleTestCase;
|
|
use ReflectionClass;
|
|
|
|
/**
|
|
* 결제수단별 마일리지 차감 시점 설정 테스트 (마일리지/MP06)
|
|
*
|
|
* EcommerceSettingsService::getMileageDeductionTiming(string) 의 결제수단별 반환과
|
|
* 미설정 기본값(무통장=order_placed / 그 외=payment_complete)을 검증한다.
|
|
*/
|
|
class EcommerceSettingsMileageTimingTest extends ModuleTestCase
|
|
{
|
|
private EcommerceSettingsService $service;
|
|
|
|
private string $storagePath;
|
|
|
|
private array $originalFilters = [];
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->storagePath = storage_path('framework/testing/modules/sirsoft-ecommerce/settings');
|
|
|
|
$ref = new ReflectionClass(HookManager::class);
|
|
$prop = $ref->getProperty('filters');
|
|
$this->originalFilters = $prop->getValue();
|
|
$prop->setValue(null, []);
|
|
|
|
if (File::isDirectory($this->storagePath)) {
|
|
File::cleanDirectory($this->storagePath);
|
|
}
|
|
|
|
$this->service = new EcommerceSettingsService;
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
if (File::isDirectory($this->storagePath)) {
|
|
File::cleanDirectory($this->storagePath);
|
|
}
|
|
|
|
$ref = new ReflectionClass(HookManager::class);
|
|
$prop = $ref->getProperty('filters');
|
|
$prop->setValue(null, $this->originalFilters);
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
/**
|
|
* 결제수단별 설정값이 있으면 그 값을 반환한다.
|
|
*/
|
|
public function test_returns_per_method_timing_when_set(): void
|
|
{
|
|
$this->service->saveSettings([
|
|
'order_settings' => [
|
|
'payment_methods' => [
|
|
['id' => 'dbank', 'sort_order' => 1, 'is_active' => true, 'min_order_amount' => 0, 'mileage_deduction_timing' => 'order_placed'],
|
|
['id' => 'card', 'sort_order' => 2, 'is_active' => true, 'min_order_amount' => 0, 'mileage_deduction_timing' => 'payment_complete'],
|
|
],
|
|
],
|
|
]);
|
|
$this->service->clearCache();
|
|
|
|
$this->assertEquals('order_placed', $this->service->getMileageDeductionTiming('dbank'));
|
|
$this->assertEquals('payment_complete', $this->service->getMileageDeductionTiming('card'));
|
|
}
|
|
|
|
/**
|
|
* 무통장 계열 결제수단의 미설정 기본값은 order_placed 다.
|
|
*/
|
|
public function test_default_for_bank_methods_is_order_placed(): void
|
|
{
|
|
$this->assertEquals('order_placed', $this->service->getMileageDeductionTiming('vbank'));
|
|
$this->assertEquals('order_placed', $this->service->getMileageDeductionTiming('dbank'));
|
|
}
|
|
|
|
/**
|
|
* 그 외(미정의 포함) 결제수단의 미설정 기본값은 payment_complete 다.
|
|
*/
|
|
public function test_default_for_other_methods_is_payment_complete(): void
|
|
{
|
|
$this->assertEquals('payment_complete', $this->service->getMileageDeductionTiming('card'));
|
|
$this->assertEquals('payment_complete', $this->service->getMileageDeductionTiming('nonexistent_method'));
|
|
}
|
|
|
|
/**
|
|
* 기본 카탈로그 defaults: 무통장은 order_placed, 카드는 payment_complete.
|
|
*/
|
|
public function test_catalog_defaults_per_method(): void
|
|
{
|
|
$this->service->clearCache();
|
|
$settings = $this->service->getSettings('order_settings');
|
|
$methods = collect($settings['payment_methods']);
|
|
|
|
$dbank = $methods->firstWhere('id', 'dbank');
|
|
$card = $methods->firstWhere('id', 'card');
|
|
$vbank = $methods->firstWhere('id', 'vbank');
|
|
|
|
$this->assertEquals('order_placed', $dbank['mileage_deduction_timing']);
|
|
$this->assertEquals('order_placed', $vbank['mileage_deduction_timing']);
|
|
$this->assertEquals('payment_complete', $card['mileage_deduction_timing']);
|
|
}
|
|
}
|