현금영수증 발급사를 PG 결제사와 독립적으로 선택할 수 있도록 공용 훅 축 (registered_providers/issue/cancel)에 토스·KG 프로바이더를 등록한다. KG 결제로 받으면서 영수증만 토스로 발급하는 구성이 가능해진다. KG 전용 발행 컨트롤러· 라우트·관리자 패널은 이 축으로 이전하며 제거했다 — 이중 발행 경로를 남기지 않기 위해서다. 토스 환불은 네 가지를 바로잡았다. 전액취소를 부분취소로 보내던 문제(R1), 면세금액 미전달로 복합과세 상점의 부가세가 틀어지던 문제(R2), 가상계좌 환불계좌를 싣지 않아 취소가 실패하던 문제(R3), 에스크로 부분취소를 PG 호출 전에 차단하지 않던 문제(E4). 취소·발급 요청에는 멱등키를 부착해 네트워크 재시도가 국세청에 이중 신고되거나 이중 환불되는 것을 막는다. 코어 활동로그 가드가 \Exception 만 잡아 채널 해석 실패(\Error)를 놓치고 있었다. 결제 입금통보 같은 외부 콜백이 로그 문제만으로 500을 반환하던 문제를 \Throwable 로 수정한다. 활동로그는 부수 기록이므로 그것을 유발한 요청까지 죽여서는 안 된다. 토스 API 서비스는 베이스 \Exception 을 직접 던지고 있어 도메인 예외 (TossPaymentsApiException)를 신설했다. KG의 KgInicisApiException 선례와 동형이며 RuntimeException 상속이라 기존 소비자의 catch 는 그대로 동작한다.
118 lines
4.0 KiB
PHP
118 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace Modules\Sirsoft\Ecommerce\Tests\Unit\DTO;
|
|
|
|
use Modules\Sirsoft\Ecommerce\DTO\AppliedPromotions;
|
|
use Modules\Sirsoft\Ecommerce\DTO\CouponApplication;
|
|
use Modules\Sirsoft\Ecommerce\DTO\DiscountCodeApplication;
|
|
use Modules\Sirsoft\Ecommerce\DTO\PromotionsSummary;
|
|
use Modules\Sirsoft\Ecommerce\Tests\ModuleTestCase;
|
|
|
|
/**
|
|
* PromotionsSummary 평탄 키 생산 표준 검증 (주문 스냅샷 표준화/MP06)
|
|
*
|
|
* 주문 생성 시 promotions_applied_snapshot 이 coupon_issue_ids / item_coupons / discount_code
|
|
* 평탄 키를 항상 포함하도록 표준화한 것을 검증한다. 취소 복원/재계산이 이 평탄 키를 SSoT 로 읽는다.
|
|
*/
|
|
class PromotionsSummaryFlatKeysTest extends ModuleTestCase
|
|
{
|
|
/**
|
|
* 상품 쿠폰 + 주문 쿠폰을 가진 요약 DTO 를 구성합니다.
|
|
*/
|
|
private function makeSummary(): PromotionsSummary
|
|
{
|
|
// 상품 쿠폰 (옵션 11, 12 에 적용)
|
|
$productCoupon = new CouponApplication(
|
|
couponId: 101,
|
|
couponIssueId: 5001,
|
|
name: '상품 쿠폰',
|
|
targetType: 'product_amount',
|
|
appliedItems: [
|
|
['product_option_id' => 11, 'discount_amount' => 1000],
|
|
['product_option_id' => 12, 'discount_amount' => 1000],
|
|
],
|
|
);
|
|
|
|
// 주문 쿠폰
|
|
$orderCoupon = new CouponApplication(
|
|
couponId: 122,
|
|
couponIssueId: 6001,
|
|
name: '주문 쿠폰',
|
|
targetType: 'order_amount',
|
|
appliedItems: [
|
|
['product_option_id' => 11, 'discount_amount' => 2000],
|
|
],
|
|
);
|
|
|
|
$product = new AppliedPromotions(coupons: [$productCoupon]);
|
|
$order = new AppliedPromotions(
|
|
coupons: [$orderCoupon],
|
|
discountCodes: [new DiscountCodeApplication(codeId: 7, code: 'WELCOME10', name: '환영코드')],
|
|
);
|
|
|
|
return new PromotionsSummary(productPromotions: $product, orderPromotions: $order);
|
|
}
|
|
|
|
/**
|
|
* toArray() 가 평탄 키 3종을 포함한다.
|
|
*/
|
|
public function test_to_array_includes_flat_keys(): void
|
|
{
|
|
$arr = $this->makeSummary()->toArray();
|
|
|
|
$this->assertArrayHasKey('coupon_issue_ids', $arr);
|
|
$this->assertArrayHasKey('item_coupons', $arr);
|
|
$this->assertArrayHasKey('discount_code', $arr);
|
|
// 기존 구조도 유지
|
|
$this->assertArrayHasKey('product_promotions', $arr);
|
|
$this->assertArrayHasKey('order_promotions', $arr);
|
|
}
|
|
|
|
/**
|
|
* coupon_issue_ids 는 상품+주문 전체 쿠폰 발급 ID (중복 제거).
|
|
*/
|
|
public function test_coupon_issue_ids_covers_all_coupons(): void
|
|
{
|
|
$arr = $this->makeSummary()->toArray();
|
|
|
|
$this->assertEqualsCanonicalizing([5001, 6001], $arr['coupon_issue_ids']);
|
|
}
|
|
|
|
/**
|
|
* item_coupons 는 상품 쿠폰을 적용 옵션별로 매핑한다 (주문 쿠폰 제외).
|
|
*/
|
|
public function test_item_coupons_maps_product_coupons_by_option(): void
|
|
{
|
|
$arr = $this->makeSummary()->toArray();
|
|
|
|
$this->assertEquals([5001], $arr['item_coupons'][11] ?? null);
|
|
$this->assertEquals([5001], $arr['item_coupons'][12] ?? null);
|
|
// 주문 쿠폰(6001)은 item_coupons 에 들어가지 않는다
|
|
foreach ($arr['item_coupons'] as $ids) {
|
|
$this->assertNotContains(6001, $ids);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* discount_code 는 적용된 할인코드 문자열.
|
|
*/
|
|
public function test_discount_code_returns_code_string(): void
|
|
{
|
|
$arr = $this->makeSummary()->toArray();
|
|
|
|
$this->assertEquals('WELCOME10', $arr['discount_code']);
|
|
}
|
|
|
|
/**
|
|
* 쿠폰/코드가 없으면 평탄 키는 빈 값.
|
|
*/
|
|
public function test_empty_promotions_produce_empty_flat_keys(): void
|
|
{
|
|
$arr = (new PromotionsSummary)->toArray();
|
|
|
|
$this->assertSame([], $arr['coupon_issue_ids']);
|
|
$this->assertSame([], $arr['item_coupons']);
|
|
$this->assertNull($arr['discount_code']);
|
|
}
|
|
}
|