fix(payment): NHN KCP 관리자 결제 상태 표시 보강
This commit is contained in:
1 parent
e7e2936ea0
commit
48f877bdcd
7 files changed
+269
-11
No files matched your search
@@ -9,6 +9,7 @@
|
||||
### Fixed
|
||||
|
||||
- 비회원 NHN KCP 주문완료/주문상세에서 매출전표 조회가 인증 사용자 전용 라우트에 막히지 않도록 게스트 주문 토큰과 결제 성공 후 임시 영수증 쿠키 접근을 지원했습니다.
|
||||
- 관리자 주문상세의 NHN KCP 결제 정보 패널이 원승인 정보와 현재 취소/환불 상태를 함께 표시하도록 보강했습니다.
|
||||
|
||||
## [1.0.0-beta.5] - 2026-06-23
|
||||
|
||||
|
||||
+91
-2
@@ -88,14 +88,35 @@
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{kcp_status.data?.res_cd === '0000'}}",
|
||||
"if": "{{kcp_status.data?.refund_status === 'completed' && (kcp_status.data?.payment_status === 'cancelled' || kcp_status.data?.payment_status === 'partial_cancelled')}}",
|
||||
"props": { "className": "ml-auto inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.pay_status_cancel_completed"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{kcp_status.data?.payment_status === 'partial_cancelled' && kcp_status.data?.refund_status !== 'completed'}}",
|
||||
"props": { "className": "ml-auto inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.pay_status_partial_cancelled"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{kcp_status.data?.payment_status === 'cancelled' && kcp_status.data?.refund_status !== 'completed'}}",
|
||||
"props": { "className": "ml-auto inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.pay_status_cancelled"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{kcp_status.data?.payment_status === 'paid' && kcp_status.data?.res_cd === '0000'}}",
|
||||
"props": { "className": "ml-auto inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.pay_status_approved"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{kcp_status.data?.res_cd !== '0000'}}",
|
||||
"if": "{{!(kcp_status.data?.refund_status === 'completed' && (kcp_status.data?.payment_status === 'cancelled' || kcp_status.data?.payment_status === 'partial_cancelled')) && kcp_status.data?.payment_status !== 'cancelled' && kcp_status.data?.payment_status !== 'partial_cancelled' && !(kcp_status.data?.payment_status === 'paid' && kcp_status.data?.res_cd === '0000')}}",
|
||||
"props": { "className": "ml-auto inline-flex items-center px-2 py-0.5 rounded-full text-xs font-semibold bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.pay_status_unknown"
|
||||
},
|
||||
@@ -113,6 +134,18 @@
|
||||
"name": "Div",
|
||||
"props": { "className": "grid grid-cols-2 gap-x-4 gap-y-2 text-xs" },
|
||||
"children": [
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"props": { "className": "text-gray-500 dark:text-gray-400" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.result_payment_status"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"props": { "className": "text-gray-900 dark:text-gray-100" },
|
||||
"text": "{{kcp_status.data?.payment_status_label ?? '-'}}"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
@@ -172,6 +205,62 @@
|
||||
"name": "Span",
|
||||
"props": { "className": "font-mono text-gray-900 dark:text-gray-100" },
|
||||
"text": "{{kcp_status.data?.res_cd ?? '-'}}"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{(kcp_status.data?.cancelled_amount ?? 0) > 0}}",
|
||||
"props": { "className": "text-gray-500 dark:text-gray-400" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.result_cancelled_amount"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{(kcp_status.data?.cancelled_amount ?? 0) > 0}}",
|
||||
"props": { "className": "font-mono text-gray-900 dark:text-gray-100" },
|
||||
"text": "{{kcp_status.data?.cancelled_amount_formatted ?? '-'}}"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.cancelled_at}}",
|
||||
"props": { "className": "text-gray-500 dark:text-gray-400" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.result_cancelled_at"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.cancelled_at}}",
|
||||
"props": { "className": "font-mono text-gray-900 dark:text-gray-100" },
|
||||
"text": "{{kcp_status.data?.cancelled_at ?? '-'}}"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.refund_status}}",
|
||||
"props": { "className": "text-gray-500 dark:text-gray-400" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.result_refund_status"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.refund_status}}",
|
||||
"props": { "className": "text-gray-900 dark:text-gray-100" },
|
||||
"text": "{{kcp_status.data?.refund_status_label ?? kcp_status.data?.refund_status ?? '-'}}"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.refund_number}}",
|
||||
"props": { "className": "text-gray-500 dark:text-gray-400" },
|
||||
"text": "$t:sirsoft-pay_nhnkcp.admin.result_refund_number"
|
||||
},
|
||||
{
|
||||
"type": "basic",
|
||||
"name": "Span",
|
||||
"if": "{{!!kcp_status.data?.refund_number}}",
|
||||
"props": { "className": "font-mono text-gray-900 dark:text-gray-100 break-all" },
|
||||
"text": "{{kcp_status.data?.refund_number ?? '-'}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -50,15 +50,22 @@
|
||||
"test_mode_badge": "Test Payment",
|
||||
"test_mode_order_notice": "This order was processed as a test payment.",
|
||||
"order_info_title": "NHN KCP Payment Info",
|
||||
"order_info_description": "Displays stored KCP payment information.",
|
||||
"order_info_description": "Displays stored KCP original approval and current payment status.",
|
||||
"pay_status_approved": "Approved",
|
||||
"pay_status_cancelled": "Cancelled",
|
||||
"pay_status_cancel_completed": "Cancellation Completed",
|
||||
"pay_status_partial_cancelled": "Partially Cancelled",
|
||||
"pay_status_unknown": "Unknown",
|
||||
"result_payment_status": "Current Payment Status",
|
||||
"result_tno": "Transaction No. (TNO)",
|
||||
"result_app_no": "Approval No.",
|
||||
"result_app_time": "Approval Time",
|
||||
"result_app_no": "Original Approval No.",
|
||||
"result_app_time": "Original Approval Time",
|
||||
"result_pay_method": "Pay Method",
|
||||
"result_res_cd": "Result Code",
|
||||
"result_res_cd": "Original Approval Result Code",
|
||||
"result_cancelled_amount": "Cancelled Amount",
|
||||
"result_cancelled_at": "Cancelled At",
|
||||
"result_refund_status": "Refund Status",
|
||||
"result_refund_number": "Refund No.",
|
||||
"escrow_badge": "Escrow",
|
||||
"escrow_delivery_title": "KCP Escrow Delivery Registration",
|
||||
"escrow_delivery_description": "Register the tracking number with KCP after shipping.",
|
||||
|
||||
@@ -50,15 +50,22 @@
|
||||
"test_mode_badge": "테스트 결제",
|
||||
"test_mode_order_notice": "이 주문은 테스트 결제로 처리되었습니다.",
|
||||
"order_info_title": "NHN KCP 결제 정보",
|
||||
"order_info_description": "DB에 저장된 KCP 결제 정보를 표시합니다.",
|
||||
"order_info_description": "DB에 저장된 KCP 원승인 및 현재 결제 상태를 표시합니다.",
|
||||
"pay_status_approved": "승인",
|
||||
"pay_status_cancelled": "취소",
|
||||
"pay_status_cancel_completed": "취소완료",
|
||||
"pay_status_partial_cancelled": "부분취소",
|
||||
"pay_status_unknown": "미확인",
|
||||
"result_payment_status": "현재 결제상태",
|
||||
"result_tno": "거래번호 (TNO)",
|
||||
"result_app_no": "승인번호",
|
||||
"result_app_time": "승인일시",
|
||||
"result_app_no": "원승인번호",
|
||||
"result_app_time": "원승인일시",
|
||||
"result_pay_method": "결제수단",
|
||||
"result_res_cd": "응답코드",
|
||||
"result_res_cd": "원승인 응답코드",
|
||||
"result_cancelled_amount": "취소금액",
|
||||
"result_cancelled_at": "취소일시",
|
||||
"result_refund_status": "환불상태",
|
||||
"result_refund_number": "환불번호",
|
||||
"escrow_badge": "에스크로",
|
||||
"escrow_delivery_title": "KCP 에스크로 배송 등록",
|
||||
"escrow_delivery_description": "상품 발송 후 KCP에 운송장번호를 등록하세요.",
|
||||
|
||||
@@ -9,6 +9,8 @@ use App\Http\Controllers\Api\Base\AdminBaseController;
|
||||
use App\Services\PluginSettingsService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\RefundStatusEnum;
|
||||
use Plugins\Sirsoft\PayNhnkcp\Concerns\ResolvesEasyPayDisplay;
|
||||
|
||||
/**
|
||||
@@ -49,7 +51,18 @@ class AdminTransactionController extends AdminBaseController
|
||||
->where('p.pg_provider', 'nhnkcp')
|
||||
->whereNotNull('p.transaction_id')
|
||||
->where('p.transaction_id', '!=', '')
|
||||
->select(['p.transaction_id', 'p.payment_meta', 'p.payment_method', 'p.embedded_pg_provider'])
|
||||
->select([
|
||||
'p.order_id',
|
||||
'p.transaction_id',
|
||||
'p.payment_meta',
|
||||
'p.payment_method',
|
||||
'p.embedded_pg_provider',
|
||||
'p.payment_status',
|
||||
'p.cancelled_amount',
|
||||
'p.cancelled_at',
|
||||
'p.cancel_history',
|
||||
'p.currency',
|
||||
])
|
||||
->first();
|
||||
|
||||
if (! $payment) {
|
||||
@@ -62,6 +75,15 @@ class AdminTransactionController extends AdminBaseController
|
||||
$meta = $this->decodePaymentMeta($payment->payment_meta ?? null);
|
||||
$rawResponse = $meta['pg_raw_response'] ?? [];
|
||||
$display = $this->resolvePaymentDisplay($payment);
|
||||
$paymentStatus = is_string($payment->payment_status ?? null)
|
||||
? PaymentStatusEnum::tryFrom($payment->payment_status)
|
||||
: null;
|
||||
$refund = $this->latestRefundForOrder((int) $payment->order_id);
|
||||
$refundStatus = is_string($refund->refund_status ?? null)
|
||||
? RefundStatusEnum::tryFrom($refund->refund_status)
|
||||
: null;
|
||||
$cancelledAmount = (float) ($payment->cancelled_amount ?? 0);
|
||||
$refundAmount = $refund ? (float) ($refund->refund_amount ?? 0) : 0.0;
|
||||
|
||||
return ResponseHelper::success('messages.success', [
|
||||
'tno' => $payment->transaction_id,
|
||||
@@ -73,6 +95,21 @@ class AdminTransactionController extends AdminBaseController
|
||||
'account' => $meta['account'] ?? null,
|
||||
'bank_name' => $rawResponse['bank_name'] ?? $meta['bank_name'] ?? null,
|
||||
'_is_test_mode' => $isTest,
|
||||
'payment_status' => $paymentStatus?->value ?? $payment->payment_status,
|
||||
'payment_status_label' => $paymentStatus?->label(),
|
||||
'payment_status_variant' => $paymentStatus?->variant(),
|
||||
'cancelled_amount' => $cancelledAmount,
|
||||
'cancelled_amount_formatted' => $this->formatKrwAmount($cancelledAmount),
|
||||
'cancelled_at' => $payment->cancelled_at,
|
||||
'cancel_history' => $this->decodeJsonArray($payment->cancel_history ?? null),
|
||||
'refund_number' => $refund->refund_number ?? null,
|
||||
'refund_status' => $refundStatus?->value ?? ($refund->refund_status ?? null),
|
||||
'refund_status_label' => $refundStatus?->label(),
|
||||
'refund_status_variant' => $refundStatus?->variant(),
|
||||
'refund_amount' => $refundAmount,
|
||||
'refund_amount_formatted' => $this->formatKrwAmount($refundAmount),
|
||||
'refunded_at' => $refund->refunded_at ?? null,
|
||||
'refund_pg_transaction_id' => $refund->pg_transaction_id ?? null,
|
||||
'_base_pay_method_label' => $display['payment_method_label'],
|
||||
'_embedded_pg_provider' => $display['embedded_pg_provider'],
|
||||
'_embedded_pg_provider_label' => $display['embedded_pg_provider_label'],
|
||||
@@ -80,4 +117,42 @@ class AdminTransactionController extends AdminBaseController
|
||||
'payment_method_display_label' => $display['payment_method_display_label'],
|
||||
]);
|
||||
}
|
||||
|
||||
private function latestRefundForOrder(int $orderId): ?object
|
||||
{
|
||||
return DB::table('ecommerce_order_refunds')
|
||||
->where('order_id', $orderId)
|
||||
->orderByDesc('id')
|
||||
->select([
|
||||
'refund_number',
|
||||
'refund_status',
|
||||
'refund_amount',
|
||||
'pg_transaction_id',
|
||||
'refunded_at',
|
||||
])
|
||||
->first();
|
||||
}
|
||||
|
||||
private function formatKrwAmount(float $amount): string
|
||||
{
|
||||
return number_format((int) round($amount)).'원';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
private function decodeJsonArray(mixed $value): array
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (! is_string($value) || trim($value) === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$decoded = json_decode($value, true);
|
||||
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
}
|
||||
+73
@@ -5,11 +5,13 @@ declare(strict_types=1);
|
||||
namespace Plugins\Sirsoft\PayNhnkcp\Tests\Feature\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderFactory;
|
||||
use Modules\Sirsoft\Ecommerce\Database\Factories\OrderPaymentFactory;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\OrderStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentMethodEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\PaymentStatusEnum;
|
||||
use Modules\Sirsoft\Ecommerce\Enums\RefundStatusEnum;
|
||||
use Plugins\Sirsoft\PayNhnkcp\Tests\PluginTestCase;
|
||||
|
||||
class AdminTransactionControllerTest extends PluginTestCase
|
||||
@@ -65,4 +67,75 @@ class AdminTransactionControllerTest extends PluginTestCase
|
||||
$data['_pay_method_label'] ?? null,
|
||||
);
|
||||
}
|
||||
|
||||
public function test_transaction_status_exposes_current_cancelled_payment_and_refund_state(): void
|
||||
{
|
||||
app()->setLocale('ko');
|
||||
|
||||
$admin = $this->createAdminUser(['sirsoft-ecommerce.orders.read']);
|
||||
$order = OrderFactory::new()->create([
|
||||
'user_id' => User::factory()->create()->id,
|
||||
'order_number' => 'ORD-KCP-CANCELLED-' . random_int(10000, 99999),
|
||||
'order_status' => OrderStatusEnum::CANCELLED,
|
||||
'total_amount' => 1100,
|
||||
'total_due_amount' => 0,
|
||||
'total_paid_amount' => 0,
|
||||
'total_refunded_amount' => 1100,
|
||||
'paid_at' => now()->subMinute(),
|
||||
'cancelled_at' => now(),
|
||||
]);
|
||||
|
||||
OrderPaymentFactory::new()->create([
|
||||
'order_id' => $order->id,
|
||||
'payment_status' => PaymentStatusEnum::CANCELLED,
|
||||
'payment_method' => PaymentMethodEnum::CARD,
|
||||
'pg_provider' => 'nhnkcp',
|
||||
'transaction_id' => '26438048818473',
|
||||
'paid_amount_local' => 1100,
|
||||
'paid_amount_base' => 1100,
|
||||
'cancelled_amount' => 1100,
|
||||
'cancelled_at' => now(),
|
||||
'payment_meta' => [
|
||||
'res_cd' => '0000',
|
||||
'app_time' => '20260707122519',
|
||||
'pg_raw_response' => [
|
||||
'res_cd' => '0000',
|
||||
'tno' => '26438048818473',
|
||||
'app_no' => '37420127',
|
||||
'app_time' => '20260707122519',
|
||||
'card_name' => '롯데카드',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
DB::table('ecommerce_order_refunds')->insert([
|
||||
'order_id' => $order->id,
|
||||
'order_cancel_id' => null,
|
||||
'refund_number' => 'RF-KCP-' . random_int(10000, 99999),
|
||||
'refund_status' => RefundStatusEnum::COMPLETED->value,
|
||||
'refund_method' => 'pg',
|
||||
'refund_amount' => 1100,
|
||||
'refund_points_amount' => 0,
|
||||
'refund_shipping_amount' => 0,
|
||||
'pg_transaction_id' => '26438048818473',
|
||||
'refunded_at' => now(),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($admin)
|
||||
->getJson("/api/plugins/sirsoft-pay_nhnkcp/admin/orders/{$order->order_number}/transaction-status");
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('data.res_cd', '0000')
|
||||
->assertJsonPath('data.payment_status', PaymentStatusEnum::CANCELLED->value)
|
||||
->assertJsonPath('data.cancelled_amount', 1100)
|
||||
->assertJsonPath('data.cancelled_amount_formatted', '1,100원')
|
||||
->assertJsonPath('data.refund_status', RefundStatusEnum::COMPLETED->value)
|
||||
->assertJsonPath('data.refund_pg_transaction_id', '26438048818473');
|
||||
|
||||
$data = $response->json('data');
|
||||
$this->assertContains($data['payment_status_label'] ?? null, ['결제취소', 'Cancelled']);
|
||||
$this->assertContains($data['refund_status_label'] ?? null, ['환불완료', 'Refunded', 'Refund Completed']);
|
||||
}
|
||||
}
|
||||
+6
@@ -62,6 +62,12 @@ class EnsureAdminOrderLayoutExtensionsListenerTest extends TestCase
|
||||
$this->assertIsString($json);
|
||||
$this->assertStringContainsString('kcp_status.data?._is_test_mode === true', $json);
|
||||
$this->assertStringContainsString('sirsoft-pay_nhnkcp.admin.order_info_title', $json);
|
||||
$this->assertStringContainsString("kcp_status.data?.payment_status === 'cancelled'", $json);
|
||||
$this->assertStringContainsString("kcp_status.data?.refund_status === 'completed'", $json);
|
||||
$this->assertStringContainsString('sirsoft-pay_nhnkcp.admin.pay_status_cancel_completed', $json);
|
||||
$this->assertStringContainsString('sirsoft-pay_nhnkcp.admin.result_payment_status', $json);
|
||||
$this->assertStringContainsString('sirsoft-pay_nhnkcp.admin.result_cancelled_amount', $json);
|
||||
$this->assertStringContainsString('sirsoft-pay_nhnkcp.admin.result_refund_status', $json);
|
||||
}
|
||||
|
||||
public function test_detail_listener_uses_wrapper_when_tab_content_area_is_renamed(): void
|
||||
|
||||
Reference in new issue
Block a user