Files
Gnuboard7/modules/_bundled/sirsoft-ecommerce/src/Http/Resources/CashReceiptResource.php
T
HeuJung e21bff678f fix(core,ecommerce,board,basic,pay_kginicis,pay_nhnkcp,pay_nicepayments): 7.0.6 회귀 3건·잠복 결함 3건 해소 + 통화 하드코딩 전수 제거
7.0.6 사이클에서 유입된 회귀 3건을 출시 전에 닫는다. 추가옵션 저장소의
반환 타입 선언이 실제 반환(중첩 맵)과 어긋나 추가옵션 있는 상품의 담기·
바로구매가 죽었고, 검색 엔진이 결과 소비 시점에 SELECT 를 재작성해 정렬이
참조하던 스코어 별칭을 지웠으며, 미들웨어 targets 가 늘어난 라우트를
따라가지 못해 비회원 현금영수증이 전면 불능이었다. 셋 다 정적 검사의
사각지대였으므로 룰 2건과 계약 테스트를 함께 세워 재발을 막는다.

같은 유형의 잠복 결함 3건(빈 반환의 타입 불일치 2건, 없는 메서드 호출 1건)도
호출 경로가 생기는 순간 fatal 이므로 함께 닫았다.

브라우저 검수 중 드러난 선행 결함 5건을 이어서 수정한다. 엔진이 event 키로
선언한 액션을 React prop 으로 연결하지 않아 오류 없이 조용히 무반응이었고,
연결한 뒤에는 커스텀 컴포넌트의 이벤트 payload 가 유실됐다. 비회원 주문상세
응답에 현금영수증 키가 없어 발급 결과에 도달할 수 없었으며, 입금확인과
현금영수증 발급이 base 통화 금액을 써서 결제 통화가 다른 주문에서 각각
저장 실패와 잘못된 증빙을 냈다.

마지막으로 통화 단위를 코드·문구에서 걷어내 설정으로 이관한다. 다국어
문구의 원/円, 프론트의 KRW 고정표와 리터럴 폴백 173건, 서버 포맷의 통화
코드 리터럴이 대상이며, 기본 통화가 원이 아닌 상점에서 값은 맞고 단위만
틀린 금액이 예외 없이 나가던 문제였다. 통화 판정을 설정 단일 출처로 모으고
규칙 3건을 정적 검사로 고정했다.
2026-08-10 09:07:46 +09:00

114 lines
5.1 KiB
PHP

<?php
namespace Modules\Sirsoft\Ecommerce\Http\Resources;
use App\Http\Resources\BaseApiResource;
use Illuminate\Http\Request;
use Modules\Sirsoft\Ecommerce\Http\Resources\Traits\HasMultiCurrencyPrices;
/**
* 현금영수증 이력 리소스
*
* 식별번호는 마스킹 값만 노출한다 — 원본 평문·암호문은 어떤 응답에도 포함되지 않는다.
* 프로바이더 원응답(raw_response)도 노출하지 않는다.
*/
class CashReceiptResource extends BaseApiResource
{
use HasMultiCurrencyPrices;
/** 영수증 금액 표기 통화 (부모가 주입). 미주입 시 기본 통화로 폴백. */
protected ?string $receiptCurrencyCode = null;
/**
* 리소스를 배열로 변환
*
* @param Request $request 요청
* @return array 현금영수증 정보 배열
*/
public function toArray(Request $request): array
{
// 현금영수증 금액은 구매자가 실제로 낸 금액, 즉 **결제 통화(order_currency)** 기준이다
// (CashReceiptService::calculateIssuableAmount 가 그 통화로 산출한다).
// base 통화 기호로 포맷하면 값은 맞는데 단위만 틀린 증빙이 화면에 뜬다(¥310 vs 310원).
$receiptCurrency = $this->resolveReceiptCurrencyCode();
return [
'id' => $this->id,
'provider' => $this->provider,
'transaction_type' => $this->transaction_type,
// 관리자 발급 이력 표는 원시값(issue/cancel, FAILED)이 아니라 표시명을 노출한다.
'transaction_type_label' => $this->transaction_type?->label(),
'receipt_type' => $this->receipt_type,
'receipt_type_label' => $this->receipt_type?->label(),
'amount' => $this->roundToCurrency($this->amount, $receiptCurrency),
'amount_formatted' => $this->formatCurrencyPrice(
$this->roundToCurrency($this->amount, $receiptCurrency),
$receiptCurrency
),
'tax_free_amount' => $this->roundToCurrency($this->tax_free_amount, $receiptCurrency),
'tax_free_amount_formatted' => $this->formatCurrencyPrice(
$this->roundToCurrency($this->tax_free_amount, $receiptCurrency),
$receiptCurrency
),
'identifier_masked' => $this->identifier_masked,
'receipt_url' => $this->receipt_url,
'issue_number' => $this->issue_number,
'issue_status' => $this->issue_status,
'issue_status_label' => $this->issue_status?->label(),
// 이력 표의 결과 열 — 발급/취소 행이 같은 열을 공유하므로 중립 표현을 쓴다.
// issue_status_label 은 발급 관점 표현("발급 완료")이라 취소 행에 쓰면 오해를 부른다.
'result_label' => $this->issue_status
? __('sirsoft-ecommerce::cash_receipt.result_status.'.strtolower($this->issue_status->value))
: null,
'error_code' => $this->error_code,
'error_message' => $this->error_message,
// 머신 ISO8601 — 표시는 issued_at_formatted 사용
'issued_at' => $this->issued_at?->toIso8601String(), // audit:allow datetime-display-user-timezone reason: machine ISO8601, display uses issued_at_formatted sibling
'issued_at_formatted' => $this->formatDateTimeStringForUser($this->issued_at),
// 이력 표의 시각 열 — 발급 실패 이력은 issued_at 이 null 이므로 기록 시각으로 대체한다.
'occurred_at_formatted' => $this->formatDateTimeStringForUser($this->issued_at ?? $this->created_at),
];
}
/**
* 영수증 금액의 표기 통화를 주입합니다.
*
* 부모 리소스(주문)가 이미 알고 있는 결제 통화를 내려 준다. 영수증마다 order 관계를
* 되짚으면 발급 이력 목록에서 N+1 이 된다.
*
* @param string|null $currencyCode 결제 통화 코드
* @return static
*/
public function withReceiptCurrency(?string $currencyCode): static
{
$this->receiptCurrencyCode = $currencyCode;
return $this;
}
/**
* 영수증 금액의 표기 통화를 반환합니다.
*
* 발급액은 결제 통화 기준으로 산출·저장되므로 표기도 그 통화를 따른다.
* 부모가 주입한 base 통화(withOrderCurrency)에 흔들리지 않는다.
*
* @return string 통화 코드 (미주입 시 기본 통화)
*/
protected function resolveReceiptCurrencyCode(): string
{
if (is_string($this->receiptCurrencyCode) && $this->receiptCurrencyCode !== '') {
return $this->receiptCurrencyCode;
}
// 관계가 이미 로드된 경우에만 참조 (추가 쿼리 금지)
if ($this->resource->relationLoaded('order') && $this->resource->order !== null) {
$order = $this->resource->order;
return $order->currency
?: (data_get($order->currency_snapshot, 'order_currency') ?: $this->getDefaultCurrencyCode());
}
return $this->getDefaultCurrencyCode();
}
}