77 lines
3.3 KiB
PHP
77 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Ecommerce\Payment;
|
|
|
|
use App\Controllers\Ecommerce\EcommerceController;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Models\CategoryModel;
|
|
use App\Models\PaymentModel;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
abstract class PaymentController extends EcommerceController
|
|
{
|
|
private $_categoryModel = null;
|
|
protected $_category = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->_viewPath .= 'payment/';
|
|
|
|
//Default 회원정보 Category
|
|
$this->_category = DEFAULTS['ORDER_CATEGORY'];
|
|
$this->_category ?: throw new \Exception("분류를 지정하지 않으셨습니다.");
|
|
$this->_viewDatas['category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_category]);
|
|
$this->_viewDatas['parent_category'] = $this->getCategoryModel()->getEntity([$this->getCategoryModel()->getPrimaryKey() => $this->_viewDatas['category']->getHierarchy_ParentUID()]);
|
|
}
|
|
|
|
final protected function getCategoryModel()
|
|
{
|
|
return $this->_categoryModel = $this->_categoryModel ?: new CategoryModel();
|
|
}
|
|
|
|
//Update관련
|
|
protected function update_form_process($entity)
|
|
{
|
|
$entity = parent::update_form_process($entity);
|
|
$this->_viewDatas['user'] = $this->getUserModel()->getEntity([$this->getUserModel()->getPrimaryKey() => $this->_viewDatas['auth'][AUTH_FIELDS['ID']]]);
|
|
return $entity;
|
|
}
|
|
final public function update_form($uid)
|
|
{
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$entity = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]);
|
|
$this->_viewDatas['entity'] = $this->update_form_process($entity);
|
|
helper(['form']);
|
|
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
|
|
return view($this->_viewPath . '/update', ['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());
|
|
}
|
|
}
|
|
|
|
//결제처리
|
|
public function update($uid)
|
|
{
|
|
$msg = "";
|
|
try {
|
|
$this->_viewDatas = $this->init(__FUNCTION__);
|
|
$entity = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]);
|
|
$this->update_validate($entity);
|
|
$entity = $this->update_process($entity);
|
|
$msg = "{$this->_viewDatas['title']}에서 {$entity->getTitle()}의 결제가 완료하였습니다.";
|
|
return redirect()->to($this->_session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
|
|
} catch (\Exception $e) {
|
|
$msg = "{$this->_viewDatas['title']}에서 결제를 실패하였습니다.\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);
|
|
}
|
|
}
|
|
}
|