cfg->wiretransfer(); $userAgent = $isMobile ? 'MW' : 'PC'; // wire 라우트 네이밍은 web.php 그대로 사용 $returnUrl = route('wire.return', ['a' => $attemptToken], true); $cancelUrl = route('web.payments.danal.cancel', ['a' => $attemptToken], true); $notiUrl = route('wire.noti', [], true); $req = [ 'TXTYPE' => 'AUTH', 'SERVICETYPE' => 'WIRETRANSFER', 'ORDERID' => $order->oid, 'ITEMNAME' => $this->safeItemName($this->orderTitle($order)), 'AMOUNT' => (string)$order->pay_money, 'USERNAME' => (string)($buyer['user_name'] ?? ''), 'USERID' => (string)($buyer['user_id'] ?? (string)$order->mem_no), 'USEREMAIL' => (string)($buyer['user_email'] ?? ''), 'USERPHONE' => (string)($buyer['user_phone'] ?? ''), 'USERAGENT' => $userAgent, 'RETURNURL' => $returnUrl, 'CANCELURL' => $cancelUrl, 'ISNOTI' => (string)($c['is_noti'] ?? 'Y'), 'NOTIURL' => $notiUrl, // NOTI에서 token 추출(권장) 'BYPASSVALUE' => 'AT=' . $attemptToken, ]; \Log::info('danal_wire_auth_req', [ 'cpid' => $c['cpid'] ?? null, 'key_len' => isset($c['key']) ? strlen((string)$c['key']) : null, 'iv_len' => isset($c['iv']) ? strlen((string)$c['iv']) : null, 'req' => $req, ]); $res = $this->client->call((string)$c['tx_url'], (string)$c['cpid'], $req, (string)$c['key'], (string)$c['iv']); $params = ['STARTPARAMS' => (string)($res['STARTPARAMS'] ?? '')]; if (!empty($c['ci_url'])) $params['CIURL'] = (string)$c['ci_url']; if (!empty($c['color'])) $params['COLOR'] = (string)$c['color']; return [ 'req' => $req, 'res' => $res, 'start' => [ 'actionUrl' => (string)($res['STARTURL'] ?? ''), 'params' => $params, 'acceptCharset' => 'EUC-KR', ], ]; } public function decryptReturn(string $returnParams): array { $c = $this->cfg->wiretransfer(); return $this->client->decryptReturnParams($returnParams, (string)$c['key'], (string)$c['iv']); } public function bill(GcPinOrder $order, string $tid): array { $c = $this->cfg->wiretransfer(); $req = [ 'TXTYPE' => 'BILL', 'SERVICETYPE' => 'WIRETRANSFER', 'TID' => $tid, // AUTH 금액과 반드시 동일 'AMOUNT' => (string)$order->pay_money, ]; $res = $this->client->call((string)$c['tx_url'], (string)$c['cpid'], $req, (string)$c['key'], (string)$c['iv']); return ['req' => $req, 'res' => $res]; } public function decryptNotiData(string $data): array { $c = $this->cfg->wiretransfer(); return $this->client->decryptReturnParams($data, (string)$c['key'], (string)$c['iv']); } private function orderTitle(GcPinOrder $order): string { $items = $order->items()->limit(2)->get(); if ($items->count() === 0) return '상품권'; if ($items->count() === 1) return (string)$items[0]->item_name; return (string)$items[0]->item_name . ' 외'; } private function safeItemName(string $s): string { $s = str_replace(["&","'","\"","\\","<",">","|","\r","\n","," , "+"], " ", $s); return trim(preg_replace('/\s+/', ' ', $s)) ?: '상품권'; } }