108 lines
4.0 KiB
PHP
108 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Ecommerce\Payment;
|
|
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class DepositController extends PaymentController
|
|
{
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
$this->_viewDatas['className'] = 'Deposit';
|
|
parent::initController($request, $response, $logger);
|
|
}
|
|
|
|
public function getFields(string $action = ""): array
|
|
{
|
|
switch ($action) {
|
|
case 'insert':
|
|
return ["order_uid", "email", "mobile"];
|
|
break;
|
|
default:
|
|
return [];
|
|
break;
|
|
}
|
|
}
|
|
protected function getFieldRule(string $field, array $rules, string $action = ""): array
|
|
{
|
|
switch ($field) {
|
|
case "order_uid":
|
|
$rules[$field] = 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]';
|
|
break;
|
|
case "email":
|
|
$rules[$field] = 'required|valid_email';
|
|
break;
|
|
case "mobile":
|
|
$rules[$field] = 'required|regex_match[/^[0-9]{3}-[0-9]{4}-[0-9]{4}/]';
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules, $action);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
public function getFieldFilters(): array
|
|
{
|
|
return [];
|
|
}
|
|
public function getFieldBatchFilters(): array
|
|
{
|
|
return parent::getFieldBatchFilters();
|
|
}
|
|
|
|
//무통장입금결제Form
|
|
//Insert관련
|
|
protected function insert_form_process()
|
|
{
|
|
$this->_viewDatas['bank'] = [
|
|
"name" => getenv("payment.deposit.bank.name") ?: "은행명",
|
|
"account" => getenv("payment.deposit.bank.account") ?: "계좌번호",
|
|
"holder" => getenv("payment.deposit.bank.holder") ?: "예금주"
|
|
];
|
|
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => ['order_uid' => $this->_viewDatas['order']->getPrimaryKey()]];
|
|
}
|
|
public function insert_form()
|
|
{
|
|
try {
|
|
$uid = $this->request->getVar('order_uid') ?: throw new \Exception("주문번호가 지정되지 않았습니다.");
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$this->_viewDatas['order'] = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]);
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return view($this->_viewPath . '/deposit', ['viewDatas' => $this->_viewDatas]);
|
|
} catch (\Exception $e) {
|
|
log_message("error", $e->getMessage());
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/")->with('return_message', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
protected function insert_process()
|
|
{
|
|
//결제후 정보저장
|
|
$entity = $this->getPaymentModel()->create($this->_viewDatas['fieldDatas']);
|
|
//아래는 Order Complete처리용
|
|
parent::insert_process();
|
|
return $entity;
|
|
}
|
|
//카드결제
|
|
public function insert()
|
|
{
|
|
$msg = "";
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$this->insert_validate();
|
|
$entity = $this->insert_process();
|
|
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 " . __FUNCTION__ . " 완료하였습니다.";
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
} catch (\Exception $e) {
|
|
$msg = "{$this->_viewDatas['title']}에서 " . __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage();
|
|
log_message("error", $e->getMessage());
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return redirect()->back()->withInput();
|
|
} finally {
|
|
$this->_session->setFlashdata("return_message", $msg);
|
|
}
|
|
}
|
|
}
|