shoppingmallv2 init...

This commit is contained in:
최준흠git config git config --helpgit config --global user.name 최준흠 2023-08-10 22:26:56 +09:00
parent 7615bbf3b7
commit b4de105a7d
15 changed files with 176 additions and 48 deletions

View File

@ -148,6 +148,13 @@ define('LAYOUTS', [
]
]
]);
//URL
define('URLS', [
'LOGIN' => '/front/user/login',
'SIGNUP' => '/front/user/signup',
'LOGOUT' => '/front/user/logout',
]);
//SESSION 관련
define('SESSION_NAMES', [
'RETURN_URL' => "return_url",

View File

@ -44,7 +44,6 @@ class EcommerceController extends Controller
private $_viewDatas = array();
private $_orderModel = null;
private $_productModel = null;
private $_paymentModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
@ -60,10 +59,7 @@ class EcommerceController extends Controller
{
return $this->_productModel = $this->_productModel ?: new ProductModel();
}
private function getPaymentModel()
{
return $this->_paymentModel = $this->_paymentModel ?: new PaymentModel();
}
//주문정보 확인
private function addCart_validate()

View File

@ -6,9 +6,13 @@ use App\Models\PaymentModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
use App\Models\OrderModel;
use App\Entities\PaymentEntity;
use App\Libraries\Adapter\Payment\CookiePayment as PaymentAdapter;
class PaymentController extends FrontController
{
private $_orderModel = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
$this->_model = new PaymentModel($this->getFields());
@ -19,6 +23,11 @@ class PaymentController extends FrontController
$this->isRole('index');
}
private function getOrderModel()
{
return $this->_orderModel = $this->_orderModel ?: new OrderModel();
}
final public function getFields(string $action = ""): array
{
switch ($action) {
@ -65,6 +74,7 @@ class PaymentController extends FrontController
{
try {
$this->card_init();
$this->_viewDatas['order'] = $this->getOrderModel()->getEntity([$this->getOrderModel()->getPrimaryKey() => $uid]);
helper(['form']);
$this->_viewDatas['forms'] = ['attributes' => ['method' => "post",], 'hiddens' => []];
$this->_session->keepFlashdata(SESSION_NAMES['RETURN_URL']);
@ -86,8 +96,33 @@ class PaymentController extends FrontController
$this->_viewDatas['fieldDatas'] = $this->getFieldFormData($field);
}
}
protected function card_process()
//처리
private function card_process(): PaymentEntity
{
return $this->_model->create($this->_viewDatas['fieldDatas']);
//결제후 정보저장
$adapter = new PaymentAdapter();
$response = $adapter->execute();
echo var_export($response, true);
return $this->_model->create($response);
}
public function card($uid)
{
$msg = "";
try {
$this->_viewDatas = $this->card_init();
$this->card_validate();
$entity = $this->card_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);
}
}
}

View File

@ -2,7 +2,7 @@
namespace App\Controllers\Front;
use App\Libraries\Adapter\Auth\Adapter;
use App\Libraries\Adapter\Auth\Auth as AuthAdapter;
use App\Models\UserModel;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
@ -29,11 +29,11 @@ class UserController extends FrontController
$this->getAdapter($adapter);
}
}
private function getAdapter(string $site): Adapter
private function getAdapter(string $site): AuthAdapter
{
$site = ucfirst($site);
if (!array_key_exists($site, $this->_adapters)) {
$adapterClass = sprintf("\App\Libraries\Adapter\Auth\%sAdapter", $site);
$adapterClass = sprintf("\App\Libraries\Adapter\Auth\%sAuth", $site);
$this->_adapters[$site] = new $adapterClass($site, AUTH_ADAPTERS[$site]['DEBUG']);
}
return $this->_adapters[$site];

View File

@ -30,7 +30,7 @@ class AuthFilter implements FilterInterface
$auth = session()->get(SESSION_NAMES['AUTH']);
// 회원 ROLES이 필요ROLE($arguments[0]) 목록에 존재하지 않으면(ACL)
if (!in_array($arguments[0], explode(DEFAULTS['DELIMITER_ROLE'], $auth[AUTH_FIELDS['ROLE']]))) {
return redirect()->to('/front/user/login')->with(
return redirect()->to(URLS['LOGIN'])->with(
'return_message',
sprintf(
"%s,%s회원님은 접속에 필요한 권한[%s]이 없습니다. ",
@ -42,7 +42,7 @@ class AuthFilter implements FilterInterface
}
} else {
session()->setFlashdata(SESSION_NAMES['RETURN_URL'], $request->getUri()->getPath() . '?' . $request->getUri()->getQuery());
return redirect()->to('/front/user/login')->with('return_message', '로그인을하셔야합니다.');
return redirect()->to(URLS['LOGIN'])->with('return_message', '로그인을하셔야합니다.');
}
}

View File

@ -3,7 +3,7 @@
namespace App\Libraries\Adapter\API;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
abstract class API
{
protected $_client = null;
protected $_serverInfo = array();

View File

@ -5,12 +5,21 @@ namespace App\Libraries\Adapter\API;
// 참고:
// https://techhub.hpe.com/eginfolib/servers/docs/HPRestfultool/iLo4/data_model_reference.html
// https://github.com/SyntaxPhoenix/iloclient
class CurlAdapter extends Adapter
class CurlAPI extends API
{
private $_headers = array('Content-Type: application/json; charset=utf-8');
public function __construct($debug = false)
{
parent::__construct($debug);
}
public function setHeader($key, $value, $delimiter = ":")
{
array_push($this->_headers, "{$key}{$delimiter} {$value}");
}
public function getHeaders(): array
{
return $this->_headers;
}
private function debugging($response, array $datas = array())
{
if (!$this->_debug) {
@ -159,47 +168,45 @@ class CurlAdapter extends Adapter
}
return $this->_client;
}
protected function requestURL(string $url, string $method, array $datas = []): object
public function setSSLVerifay()
{
//SSL 확인여부용
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYPEER, API['SSL_VERIFY']);
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYHOST, API['SSL_VERIFY']);
}
public function setCookie()
{
//cookie값 전달용
foreach (curl_getinfo($this->getClient(), CURLINFO_COOKIELIST) as $cookie_line) {
curl_setopt($this->getClient(), CURLOPT_COOKIELIST, $cookie_line);
}
}
public function setAUthentication()
{
//접속인증 정보값 전달용
curl_setopt($this->getClient(), CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->getClient(), CURLOPT_USERPWD, implode(":", $this->getAccountInfo()));
}
public function requestURL(string $url, string $method, array $datas = []): object
{
curl_setopt($this->getClient(), CURLOPT_URL, $this->getServerInfo() . $url);
switch ($method) {
case 'POST':
curl_setopt($this->getClient(), CURLOPT_POST, TRUE);
curl_setopt($this->getClient(), CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($this->getClient(), CURLOPT_POSTFIELDS, json_encode($datas));
curl_setopt($this->getClient(), CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
//cookie값 파일저장용
curl_setopt($this->getClient(), CURLOPT_COOKIEJAR, API['COOKIE_FILE']);
curl_setopt($this->getClient(), CURLOPT_COOKIEFILE, API['COOKIE_FILE']);
break;
default:
curl_setopt($this->getClient(), CURLOPT_POST, false);
break;
}
//cookie값 전달용
foreach (curl_getinfo($this->getClient(), CURLINFO_COOKIELIST) as $cookie_line) {
curl_setopt($this->getClient(), CURLOPT_COOKIELIST, $cookie_line);
}
//SSL 확인여부용
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYPEER, API['SSL_VERIFY']);
curl_setopt($this->getClient(), CURLOPT_SSL_VERIFYHOST, API['SSL_VERIFY']);
curl_setopt($this->getClient(), CURLOPT_POSTFIELDS, json_encode($datas, true));
curl_setopt($this->getClient(), CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->getClient(), CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->getClient(), CURLOPT_USERPWD, implode(":", $this->getAccountInfo()));
//header값 전달용
$headers = [];
curl_setopt(
$this->getClient(),
CURLOPT_HEADERFUNCTION,
function ($curl, $header) use (&$headers) {
$length = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) { // ignore invalid headers
return $length;
}
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $length;
}
);
curl_setopt($this->getClient(), CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($this->getClient(), CURLOPT_TIMEOUT, 20);
curl_setopt($this->getClient(), CURLOPT_HTTPHEADER, $this->getHeaders());
$response = curl_exec($this->getClient());
$this->debugging($response);
curl_close($this->getClient());

View File

@ -5,7 +5,7 @@ namespace App\Libraries\Adapter\API;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\ClientException;
// 참고:https://github.com/SyntaxPhoenix/iloclient
class GuzzleAdapter extends Adapter
class GuzzleAPI extends API
{
private $_jar = null;
public function __construct($debug = false)

View File

@ -2,7 +2,7 @@
namespace App\Libraries\Adapter\API;
class LocalAdapter extends Adapter
class LocalAPI extends API
{
public function __construct($debug = false)
{

View File

@ -7,7 +7,7 @@ use App\Models\UserModel;
use App\Models\UserSNSModel;
// 참고:https://github.com/SyntaxPhoenix/iloclient
abstract class Adapter
abstract class Auth
{
private $_site = null;
private $_userModel = null;

View File

@ -5,7 +5,7 @@ namespace App\Libraries\Adapter\Auth;
use App\Entities\UserEntity;
use App\Entities\UserSNSEntity;
class GoogleAdapter extends Adapter
class GoogleAuth extends Auth
{
private $_client = null;
public function __construct(string $site, $debug = false)

View File

@ -4,7 +4,7 @@ namespace App\Libraries\Adapter\Auth;
use App\Entities\UserEntity;
class LocalAdapter extends Adapter
class LocalAuth extends Auth
{
public function __construct(string $site, $debug = false)
{

View File

@ -0,0 +1,64 @@
<?php
namespace App\Libraries\Adapter\Payment;
use App\Libraries\Adapter\API\CurlAPI as APIAdapter;
// 참고:
// https://techhub.hpe.com/eginfolib/servers/docs/HPRestfultool/iLo4/data_model_reference.html
// https://github.com/SyntaxPhoenix/iloclient
class CookiePayment extends Payment
{
public function __construct($debug = false)
{
parent::__construct($debug);
}
private function getToken()
{
$adapter = new APIAdapter();
$adapter->setHeader("content-type", "application/json; charset=utf-8");
/* 토큰 발행 API */
$token_url = getenv("payment.cookiepay.token_url") ?: "{TOKEN 발행 URL}";
$token_request_data = array(
'pay2_id' => 'cookiepayments에서 발급받은 ID',
'pay2_key' => 'cookiepayments에서 발급받은 연동키',
);
$token = $adapter->requestURL($token_url, "GET", $token_request_data);
/* 여기 까지 */
if ($token['RTN_CD'] != '0000') {
throw new \Exception("Cookipay에서 Token을 받는데 실패했습니다.");
}
return $token;
}
public function execute()
{
$adapter = new APIAdapter();
$adapter->setHeader("content-type", "application/json; charset=utf-8");
$adapter->setHeader("ApiKey", getenv("payment.cookiepay.apikey") ?: "COOKIEPAY에서 발급받은 연동키");
$adapter->setHeader("TOKEN", $this->getToken());
$cookiepayments_url = getenv("payment.cookiepay.url") ?: "{요청도메인}/keyin/payment";
$request_data_array = array(
'API_ID' => 'COOKIEPAY에서 발급받은 가맹점연동 ID',
'ORDERNO' => '주문번호',
'PRODUCTNAME' => '상품명',
'AMOUNT' => '결제금액',
'BUYERNAME' => '고객명',
'BUYEREMAIL' => '고객 E-MAIL',
'CARDNO' => '카드번호',
'EXPIREDT' => '카드유효기간',
'PRODUCTCODE' => '상품코드',
'BUYERID' => '고객 ID',
'BUYERADDRESS' => '고객 주소',
'BUYERPHONE' => '고객 휴대폰번호',
'QUOTA' => '할부개월',
'ETC1' => '추가필드 1',
'ETC2' => '추가필드 2',
'ETC3' => '추가필드 3',
'ETC4' => '추가필드 4',
'ETC5' => '추가필드 5',
);
return $adapter->requestURL($cookiepayments_url, "GET", $request_data_array);
}
}

View File

@ -0,0 +1,13 @@
<?php
namespace App\Libraries\Adapter\Payment;
abstract class Payment
{
protected $_debug = false;
protected function __construct($debug = false)
{
$this->_debug = $debug;
}
abstract public function execute();
}

View File

@ -3,10 +3,16 @@
<link href="/css/front/content.css" media="screen" rel="stylesheet" type="text/css" />
<div id="content">
<div><?= html_entity_decode($viewDatas['category']->head) ?></div>
<div>상품정보표시</div>
<div>오더정보표시</div>
<?= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>
<table class="form table table-bordered table-hover table-striped">
<tr>
<td class="label">상품명</td>
<td class="column"><?= $viewDatas['order']->getTitle() ?></td>
</tr>
<tr>
<td class="label">결제금액</td>
<td class="column"><?= number_format($viewDatas['order']->price) ?>원</td>
</tr>
<?php foreach ($viewDatas['fields'] as $field) : ?>
<tr>
<td class="label"><?= getFieldLabel_PaymentHelper($field, $viewDatas) ?></td>