v7.0.0 release

This commit is contained in:
HeuJung committed 2026-07-01 10:30:32 +09:00
1 parent 0e7fa04b03
commit c4ea9a6cd1
3582 files changed
+626189 -160151

No files matched your search

@@ -13,19 +13,25 @@ use Modules\Sirsoft\Ecommerce\Enums\CancelOptionStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\CancelStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\CancelTypeEnum;
use Modules\Sirsoft\Ecommerce\Enums\OrderStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
use Modules\Sirsoft\Ecommerce\Enums\PaymentStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\RefundMethodEnum;
use Modules\Sirsoft\Ecommerce\Enums\RefundPriorityEnum;
use Modules\Sirsoft\Ecommerce\Enums\RefundOptionStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\RefundPriorityEnum;
use Modules\Sirsoft\Ecommerce\Enums\RefundStatusEnum;
use Modules\Sirsoft\Ecommerce\Enums\SequenceType;
use Modules\Sirsoft\Ecommerce\Exceptions\OrderCancellationException;
use Modules\Sirsoft\Ecommerce\Models\Order;
use Modules\Sirsoft\Ecommerce\Models\OrderCancel;
use Modules\Sirsoft\Ecommerce\Models\OrderCancelOption;
use Modules\Sirsoft\Ecommerce\Models\OrderOption;
use Modules\Sirsoft\Ecommerce\Models\OrderRefund;
use Modules\Sirsoft\Ecommerce\Models\OrderRefundOption;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderCancelOptionRepositoryInterface;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderCancelRepositoryInterface;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderOptionRepositoryInterface;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderRefundOptionRepositoryInterface;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderRefundRepositoryInterface;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\OrderShippingRepositoryInterface;
/**
@@ -44,6 +50,10 @@ class OrderCancellationService
* @param EcommerceSettingsService $settingsService 이커머스 설정 서비스
* @param OrderOptionRepositoryInterface $orderOptionRepository 주문 옵션 Repository
* @param OrderShippingRepositoryInterface $orderShippingRepository 주문 배송 Repository
* @param OrderCancelRepositoryInterface $orderCancelRepository 주문 취소 Repository
* @param OrderCancelOptionRepositoryInterface $orderCancelOptionRepository 주문 취소 옵션 Repository
* @param OrderRefundRepositoryInterface $orderRefundRepository 주문 환불 Repository
* @param OrderRefundOptionRepositoryInterface $orderRefundOptionRepository 주문 환불 옵션 Repository
*/
public function __construct(
protected OrderAdjustmentService $adjustmentService,
@@ -53,6 +63,10 @@ class OrderCancellationService
protected EcommerceSettingsService $settingsService,
protected OrderOptionRepositoryInterface $orderOptionRepository,
protected OrderShippingRepositoryInterface $orderShippingRepository,
protected OrderCancelRepositoryInterface $orderCancelRepository,
protected OrderCancelOptionRepositoryInterface $orderCancelOptionRepository,
protected OrderRefundRepositoryInterface $orderRefundRepository,
protected OrderRefundOptionRepositoryInterface $orderRefundOptionRepository,
) {}
/**
@@ -191,6 +205,11 @@ class OrderCancellationService
$this->validateCancellable($order);
$this->validateCancelItems($order, $cancelItems);
// 결제 취소 전 본인인증(IDV) 정책 가드 지점 (관리자/사용자 — payment.cancel purpose).
// EnforceIdentityPolicyListener 가 'sirsoft-ecommerce.payment.cancel' 정책이 활성이고
// grace 만료 시 IdentityVerificationRequiredException(428) 을 throw 한다.
HookManager::doAction('sirsoft-ecommerce.payment.before_cancel', $order, $cancelType->value, $cancelItems);
// 취소 전 훅
HookManager::doAction('sirsoft-ecommerce.order.before_cancel', $order, $cancelType->value, $cancelItems);
@@ -255,14 +274,18 @@ class OrderCancellationService
$this->updatePayment($order, $orderCancel, $adjustmentResult);
// ③-i. PG 환불 훅
if ($cancelPg && $order->payment && $adjustmentResult->refundAmount > 0) {
// PG사 선택이 필요한 결제수단(카드/가상계좌/계좌이체/휴대폰)만 PG 환불 훅에 진입한다.
// 무통장입금(dbank)·포인트·예치금·무료는 PG 리스너가 인식하지 못해 success=false → 트랜잭션 롤백.
// 이들은 PG 훅을 건너뛰고 운영자 수동 환불(APPROVED) 로 처리한다.
if ($cancelPg && $order->payment && $adjustmentResult->refundAmount > 0
&& $order->payment->payment_method?->needsPgProvider()) {
$this->executePgRefund($order, $orderRefund, $adjustmentResult, $reason);
}
}
// ③-i. 쿠폰/마일리지/재고 복원 (결제 여부 무관)
$this->restoreCoupons($order, $adjustmentResult);
$this->restoreMileage($order, $adjustmentResult);
$this->restoreMileage($order, $adjustmentResult, $orderCancel);
$this->restoreStock($order, $cancelItems);
// ③-j. 상태 확정 (completed)
@@ -295,7 +318,6 @@ class OrderCancellationService
* 주문 취소 가능 여부를 검증합니다.
*
* @param Order $order 대상 주문
* @return void
*
* @throws \Exception 취소 불가 시
*/
@@ -307,7 +329,7 @@ class OrderCancellationService
);
if (! $order->isCancellable($cancellableStatuses)) {
throw new \Exception($order->getCancelDeniedReason($cancellableStatuses));
throw new OrderCancellationException($order->getCancelDeniedReason($cancellableStatuses));
}
}
@@ -316,7 +338,6 @@ class OrderCancellationService
*
* @param Order $order 주문
* @param array $cancelItems 취소 대상
* @return void
*
* @throws \Exception 유효하지 않은 아이템
*/
@@ -326,30 +347,33 @@ class OrderCancellationService
$option = $order->options->find($item['order_option_id']);
if (! $option) {
throw new \Exception(__('sirsoft-ecommerce::exceptions.cancel_option_not_found'));
throw new OrderCancellationException(__('sirsoft-ecommerce::exceptions.cancel_option_not_found'));
}
if ($option->option_status === OrderStatusEnum::CANCELLED) {
throw new \Exception(__('sirsoft-ecommerce::exceptions.cancel_option_already_cancelled'));
throw new OrderCancellationException(__('sirsoft-ecommerce::exceptions.cancel_option_already_cancelled'));
}
if ($item['cancel_quantity'] < 1 || $item['cancel_quantity'] > $option->quantity) {
throw new \Exception(__('sirsoft-ecommerce::exceptions.cancel_quantity_invalid'));
throw new OrderCancellationException(__('sirsoft-ecommerce::exceptions.cancel_quantity_invalid'));
}
}
}
/**
* 재계산 결제금액이 원 결제금액을 초과하지 않는지 검증합니다.
* 부분취소로 고객이 추가 결제해야 하는 상황인지 검증합니다.
*
* 부분취소 시 쿠폰 조건 미달(최소 주문금액 등)로 할인이 소멸하면
* 재계산 결제금액이 원 결제금액보다 높아질 수 있습니다.
* 이 경우 고객에게 추가 결제를 요구해야 하므로 취소를 거부합니다.
*
* 차단 판정은 미리보기(previewRefund)와 동일한 AdjustmentResult::isCancelBlocked() 에
* 위임하여, 미리보기 가능/실행 차단 같은 사용자 기만을 제거합니다.
* 실결제 0원(미입금·운영자 0원 결제완료) 주문은 환불/추가청구 개념이 없어 차단하지 않습니다.
*
* @param Order $order 주문
* @param AdjustmentResult $result 환불 계산 결과
* @param CancelTypeEnum $cancelType 취소 유형
* @return void
*
* @throws \Exception 재계산 결제금액 초과 시
*/
@@ -360,12 +384,8 @@ class OrderCancellationService
return;
}
$originalPaid = (float) $order->total_paid_amount + (float) $order->total_points_used_amount;
$recalculatedPaid = $result->recalculatedSnapshot['total_paid_amount']
+ ($result->recalculatedSnapshot['total_points_used_amount'] ?? 0);
if ($recalculatedPaid > $originalPaid) {
throw new \Exception(__('sirsoft-ecommerce::exceptions.cancel_refund_negative'));
if ($result->isCancelBlocked()) {
throw new OrderCancellationException(__('sirsoft-ecommerce::exceptions.cancel_refund_negative'));
}
}
@@ -421,10 +441,11 @@ class OrderCancellationService
array $cancelItems,
): OrderCancel {
$itemsSnapshot = $this->buildItemsSnapshot($order, $cancelItems);
$shippingSnapshot = $this->buildShippingSnapshot($order, $cancelItems);
$cancelReasonType = $reason ?? 'etc';
return OrderCancel::create([
return $this->orderCancelRepository->create([
'order_id' => $order->id,
'cancel_number' => $this->sequenceService->generateCode(SequenceType::CANCEL),
'cancel_type' => $cancelType,
@@ -432,10 +453,61 @@ class OrderCancellationService
'cancel_reason_type' => $cancelReasonType,
'cancel_reason' => $reasonDetail,
'items_snapshot' => $itemsSnapshot,
'shipping_snapshot' => $shippingSnapshot,
'cancelled_by' => $cancelledBy,
]);
}
/**
* 취소 시점의 배송지(국가/우편번호) + 취소 대상 배송정책 스냅샷을 생성합니다 (B5).
*
* 주문 주소(ecommerce_order_addresses)는 사후 변경/삭제될 수 있으므로, 취소 "시점"의
* 배송국가·우편번호와 취소 대상 옵션의 배송정책을 취소 레코드에 독립 복사한다. 이를 통해
* 도서산간/국가별 환불 정책 판단을 주문 주소 상태와 무관하게 이력 기준으로 복원할 수 있다.
* SSoT 는 주문 생성 시점에 보존된 order->shipping_policy_applied_snapshot['address'] 이다.
*
* @param Order $order 주문
* @param array $cancelItems 취소 대상 (order_option_id 기준)
* @return array 배송 스냅샷 (country_code/zipcode + 취소 대상 정책)
*/
protected function buildShippingSnapshot(Order $order, array $cancelItems): array
{
$orderSnapshot = $order->shipping_policy_applied_snapshot ?? [];
$address = $orderSnapshot['address'] ?? [];
// 주문 스냅샷에 배송지가 없으면 현재 배송주소에서 폴백 복원(과거 주문 호환).
if (empty($address['country_code'])) {
$shippingAddress = $order->shippingAddress;
$address = [
'country_code' => strtoupper((string) ($shippingAddress?->recipient_country_code ?: 'KR')),
'zipcode' => $shippingAddress?->zipcode ?: ($shippingAddress?->intl_postal_code ?: null),
];
}
// 취소 대상 옵션의 product_option_id 기준으로 적용 정책만 추려 보존.
$cancelOptionIds = [];
foreach ($cancelItems as $item) {
$option = $order->options->find($item['order_option_id']);
if ($option) {
$cancelOptionIds[$option->product_option_id] = true;
}
}
$policies = [];
foreach ($orderSnapshot as $key => $entry) {
if (is_int($key) && isset($entry['product_option_id'], $entry['policy'])
&& isset($cancelOptionIds[$entry['product_option_id']])) {
$policies[] = $entry;
}
}
return [
'country_code' => strtoupper((string) ($address['country_code'] ?? 'KR')),
'zipcode' => $address['zipcode'] ?? null,
'policies' => $policies,
];
}
/**
* 취소 대상 아이템 스냅샷을 생성합니다.
*
@@ -473,7 +545,6 @@ class OrderCancellationService
* @param OrderCancel $cancel 취소 레코드
* @param Order $order 주문
* @param array $cancelItems 취소 대상
* @return void
*/
protected function createCancelOptions(OrderCancel $cancel, Order $order, array $cancelItems): void
{
@@ -483,7 +554,7 @@ class OrderCancellationService
continue;
}
OrderCancelOption::create([
$this->orderCancelOptionRepository->create([
'order_cancel_id' => $cancel->id,
'order_id' => $order->id,
'order_option_id' => $option->id,
@@ -506,7 +577,6 @@ class OrderCancellationService
* @param Order $order 주문
* @param array $cancelItems 취소 대상
* @param string|null $reason 취소 사유
* @return void
*/
protected function updateOrderOptions(Order $order, array $cancelItems, ?string $reason): void
{
@@ -516,11 +586,15 @@ class OrderCancellationService
continue;
}
// changeStatusWithQuantity 재사용 (분할 로직 포함)
// changeStatusWithQuantity 재사용 (분할 로직 포함).
// restoreStockOnCancel: false — 취소 모달 경로는 아래 restoreStock() 이 재고 복원을 전담하므로
// changeStatusWithQuantity 가 복원하면 이중 복원이 된다(재고 2배 복구 회귀 방지).
$this->orderOptionService->changeStatusWithQuantity(
$option,
OrderStatusEnum::CANCELLED,
$item['cancel_quantity']
$item['cancel_quantity'],
[],
restoreStockOnCancel: false
);
// 취소 수량/사유 누적
@@ -544,7 +618,6 @@ class OrderCancellationService
*
* @param Order $order 주문
* @param AdjustmentResult $result 계산 결과
* @return void
*/
protected function applyOptionUpdates(Order $order, AdjustmentResult $result): void
{
@@ -564,7 +637,6 @@ class OrderCancellationService
* 배송비를 재계산 결과에 따라 갱신합니다.
*
* @param AdjustmentResult $result 계산 결과
* @return void
*/
protected function updateShippings(AdjustmentResult $result): void
{
@@ -584,7 +656,6 @@ class OrderCancellationService
* @param CancelTypeEnum $cancelType 취소 유형
* @param AdjustmentResult $result 계산 결과
* @param string|null $reason 취소 사유
* @return void
*/
protected function updateOrderTotals(
Order $order,
@@ -595,25 +666,30 @@ class OrderCancellationService
$isFullCancel = $cancelType === CancelTypeEnum::FULL;
$previousStatus = $order->order_status;
$orderStatus = $isFullCancel
? OrderStatusEnum::CANCELLED
: OrderStatusEnum::PARTIAL_CANCELLED;
$updateData = array_merge($result->orderUpdates, [
'order_status' => $orderStatus,
'total_cancelled_amount' => (float) $order->total_cancelled_amount + $result->refundAmount,
'cancellation_count' => ($order->cancellation_count ?? 0) + 1,
// 취소일시 — 전체/부분취소 모두 기록(native 컬럼 SSoT). 최초 취소 시각을 보존하고 재취소 시 갱신하지 않는다.
'cancelled_at' => $order->cancelled_at ?? Carbon::now(),
]);
if ($isFullCancel) {
// 전체취소는 주문 상태를 CANCELLED 로 확정한다.
$updateData['order_status'] = OrderStatusEnum::CANCELLED;
$updateData['order_meta'] = array_merge($order->order_meta ?? [], [
'cancel_reason' => $reason,
'cancelled_at' => Carbon::now()->toIso8601String(),
'previous_status' => $previousStatus->value,
]);
}
// 부분취소는 별도 주문 상태(partial_cancelled)를 두지 않는다 — 옵션은 이미 CANCELLED 로 전이됐고,
// 주문 상태는 아래 syncParentOrderStatus 가 "취소 제외 잔여 활성 옵션" 기준으로 파생 결정한다.
// (잔여 옵션이 모두 취소된 경우 syncParentOrderStatus 가 CANCELLED 로 전이.) — PO 2026-06-22
$order->update($updateData);
if (! $isFullCancel) {
$this->orderOptionService->syncParentOrderStatus($order->id);
}
}
// ───────────────────────────────────────────────
@@ -635,7 +711,7 @@ class OrderCancellationService
): OrderRefund {
$refundMethod = $this->determineRefundMethod($order);
return OrderRefund::create([
return $this->orderRefundRepository->create([
'order_id' => $order->id,
'order_cancel_id' => $cancel->id,
'refund_number' => $this->sequenceService->generateCode(SequenceType::REFUND),
@@ -664,12 +740,12 @@ class OrderCancellationService
return RefundMethodEnum::BANK;
}
$paymentMethod = $order->payment->payment_method?->value;
$paymentMethod = $order->payment->payment_method;
return match ($paymentMethod) {
'card', 'bank', 'vbank', 'phone' => RefundMethodEnum::PG,
'dbank' => RefundMethodEnum::BANK,
'point' => RefundMethodEnum::POINTS,
PaymentMethodEnum::CARD, PaymentMethodEnum::BANK, PaymentMethodEnum::VBANK, PaymentMethodEnum::PHONE => RefundMethodEnum::PG,
PaymentMethodEnum::DBANK => RefundMethodEnum::BANK,
PaymentMethodEnum::POINT => RefundMethodEnum::POINTS,
default => RefundMethodEnum::BANK,
};
}
@@ -685,7 +761,6 @@ class OrderCancellationService
* @param Order $order 주문
* @param array $cancelItems 취소 대상
* @param AdjustmentResult $result 계산 결과
* @return void
*/
protected function createRefundOptions(
OrderRefund $refund,
@@ -715,7 +790,7 @@ class OrderCancellationService
$refundAmount = $cancelAmount - $discountAmount;
OrderRefundOption::create([
$this->orderRefundOptionRepository->create([
'order_refund_id' => $refund->id,
'order_id' => $order->id,
'order_option_id' => $option->id,
@@ -739,7 +814,6 @@ class OrderCancellationService
* @param Order $order 주문
* @param OrderCancel $cancel 취소 레코드
* @param AdjustmentResult $result 계산 결과
* @return void
*/
protected function updatePayment(Order $order, OrderCancel $cancel, AdjustmentResult $result): void
{
@@ -750,11 +824,23 @@ class OrderCancellationService
$isFullCancel = $cancel->cancel_type === CancelTypeEnum::FULL;
// 결제 통화(order_currency) 환산 환불액. base≠결제 통화일 때 PG 실환불·누적은 결제 통화로
// 정합되어야 하므로 mc_cancelled_amount 를 결제 통화로 누적한다(base 누적 cancelled_amount 와 별개).
$orderCurrency = $payment->currency ?: ($order->currency_snapshot['order_currency'] ?? null);
$refundLocal = $this->resolveOrderCurrencyRefundAmount($result, $orderCurrency);
$mcCancelled = $payment->mc_cancelled_amount ?? [];
foreach ($result->mcRefundAmount ?? [] as $code => $amount) {
$mcCancelled[$code] = (float) ($mcCancelled[$code] ?? 0) + (float) $amount;
}
$cancelHistory = $payment->cancel_history ?? [];
$cancelHistory[] = [
'cancel_id' => $cancel->id,
'cancel_number' => $cancel->cancel_number,
'amount' => $result->refundAmount,
'amount_local' => $refundLocal,
'currency' => $orderCurrency,
'points_amount' => $result->refundPointsAmount,
'reason' => $cancel->cancel_reason_type,
'date' => Carbon::now()->toIso8601String(),
@@ -762,6 +848,7 @@ class OrderCancellationService
$payment->update([
'cancelled_amount' => (float) $payment->cancelled_amount + $result->refundAmount,
'mc_cancelled_amount' => $mcCancelled,
'cancel_reason' => $cancel->cancel_reason_type,
'cancel_history' => $cancelHistory,
'cancelled_at' => Carbon::now(),
@@ -771,6 +858,25 @@ class OrderCancellationService
]);
}
/**
* 환불액을 결제 통화(order_currency)로 환산해 반환합니다.
*
* 계산 단계에서 스냅샷 환율로 산출한 mc_refund_amount[order_currency] 를 우선 사용하고,
* 없으면(결제 통화 환율 누락 등) base refundAmount 로 폴백합니다.
*
* @param AdjustmentResult $result 환불 계산 결과
* @param string|null $orderCurrency 결제 통화 코드
* @return float 결제 통화 환산 환불액
*/
protected function resolveOrderCurrencyRefundAmount(AdjustmentResult $result, ?string $orderCurrency): float
{
if ($orderCurrency !== null && isset($result->mcRefundAmount[$orderCurrency])) {
return (float) $result->mcRefundAmount[$orderCurrency];
}
return (float) $result->refundAmount;
}
// ───────────────────────────────────────────────
// ③-i. 훅 실행 (PG 환불, 쿠폰/마일리지/재고 복원)
// ───────────────────────────────────────────────
@@ -782,7 +888,6 @@ class OrderCancellationService
* @param OrderRefund $refund 환불 레코드
* @param AdjustmentResult $result 계산 결과
* @param string|null $reason 사유
* @return void
*
* @throws \Exception PG 환불 실패 시
*/
@@ -794,12 +899,19 @@ class OrderCancellationService
): void {
$refund->update(['refund_status' => RefundStatusEnum::PROCESSING]);
// PG 실환불 금액은 결제 통화(order_currency)여야 한다. base≠결제 통화일 때 base 금액을 그대로
// 전송하면 PG 가 결제 통화 단위로 오인해 실환불액이 틀어진다(예: base JPY 500 → KRW 500 환불).
// updatePayment 가 이미 mc_cancelled_amount 를 결제 통화로 누적했으므로, 리스너는 결제 통화 기준
// (paid_amount_local / mc_cancelled_amount[order_currency])으로 부분취소 누적을 계산한다.
$orderCurrency = $order->payment->currency ?: ($order->currency_snapshot['order_currency'] ?? null);
$refundLocal = $this->resolveOrderCurrencyRefundAmount($result, $orderCurrency);
$pgResult = HookManager::applyFilters(
'sirsoft-ecommerce.payment.refund',
['success' => false, 'error_code' => null, 'error_message' => null, 'transaction_id' => null],
$order,
$order->payment,
$result->refundAmount,
$refundLocal,
$reason
);
@@ -822,7 +934,7 @@ class OrderCancellationService
'error_message' => $pgResult['error_message'] ?? null,
]);
throw new \Exception(__('sirsoft-ecommerce::exceptions.pg_refund_failed', [
throw new OrderCancellationException(__('sirsoft-ecommerce::exceptions.pg_refund_failed', [
'error' => $pgResult['error_message'] ?? 'Unknown error',
]));
}
@@ -833,7 +945,6 @@ class OrderCancellationService
*
* @param Order $order 주문
* @param AdjustmentResult $result 계산 결과
* @return void
*/
protected function restoreCoupons(Order $order, AdjustmentResult $result): void
{
@@ -859,16 +970,24 @@ class OrderCancellationService
*
* @param Order $order 주문
* @param AdjustmentResult $result 계산 결과
* @return void
* @param OrderCancel|null $orderCancel 취소 레코드 (복원 멱등 기준)
*/
protected function restoreMileage(Order $order, AdjustmentResult $result): void
protected function restoreMileage(Order $order, AdjustmentResult $result, ?OrderCancel $orderCancel = null): void
{
// 실제 차감이 일어난 주문만 복원한다. 결제수단별 차감 시점이 payment_complete 인데
// 결제 전 취소되어 마일리지가 차감된 적 없는 주문(is_mileage_deducted=false)은 복원 대상이 아니다.
// 가드가 없으면 사용 의도(total_points_used_amount)만으로 신규 lot 이 발행되어 유령 적립이 발생한다.
if (! $order->is_mileage_deducted) {
return;
}
if ($result->refundPointsAmount > 0) {
try {
HookManager::doAction(
'sirsoft-ecommerce.mileage.restore',
$result->refundPointsAmount,
$order
$order,
$orderCancel?->id
);
} catch (\Exception $e) {
Log::warning('마일리지 복원 실패', [
@@ -885,7 +1004,6 @@ class OrderCancellationService
*
* @param Order $order 주문
* @param array $cancelItems 취소 대상
* @return void
*/
protected function restoreStock(Order $order, array $cancelItems): void
{
@@ -905,8 +1023,10 @@ class OrderCancellationService
}
try {
$this->stockService->restoreOptionStock(
$option->product_option_id,
// 복원 + is_stock_deducted 플래그 정리를 한 트랜잭션에서 원자적으로 처리.
// (재고 리스너 제거로 플래그 리셋 주체가 Service 경로로 단일화됨)
$this->stockService->restoreOptionStockForOrderOption(
$option,
$item['cancel_quantity']
);
} catch (\Exception $e) {
@@ -930,7 +1050,6 @@ class OrderCancellationService
* @param OrderCancel $cancel 취소 레코드
* @param OrderRefund|null $refund 환불 레코드
* @param int|null $processedBy 처리 관리자 ID
* @return void
*/
protected function finalizeStatus(OrderCancel $cancel, ?OrderRefund $refund, ?int $processedBy): void
{
@@ -951,11 +1070,21 @@ class OrderCancellationService
// 환불 레코드 확정 (PG 환불 이미 처리된 경우 제외)
if ($refund && ! $refund->refund_status->isFinal()) {
$refund->update([
'refund_status' => RefundStatusEnum::COMPLETED,
'refunded_at' => $now,
'processed_by' => $processedBy,
]);
// PG 환불은 즉시 완료(COMPLETED), 무통장/포인트(BANK/POINTS) 는 운영자 수동 송금 대기로
// APPROVED(환불 승인) 에 둔다. 취소 자체는 완료하되, 실제 송금 전에 "환불 완료"로 거짓 확정하지
// 않는다. 운영자가 송금 후 직접 COMPLETED 로 전환한다.
if ($refund->refund_method === RefundMethodEnum::PG) {
$refund->update([
'refund_status' => RefundStatusEnum::COMPLETED,
'refunded_at' => $now,
'processed_by' => $processedBy,
]);
} else {
$refund->update([
'refund_status' => RefundStatusEnum::APPROVED,
'processed_by' => $processedBy,
]);
}
}
// 환불 옵션 확정