diff --git a/app/Config/Constants.php b/app/Config/Constants.php
index 990977b..3ce9815 100644
--- a/app/Config/Constants.php
+++ b/app/Config/Constants.php
@@ -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",
diff --git a/app/Controllers/EcommerceController.php b/app/Controllers/EcommerceController.php
index a20613b..e52b4af 100644
--- a/app/Controllers/EcommerceController.php
+++ b/app/Controllers/EcommerceController.php
@@ -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()
diff --git a/app/Controllers/Front/PaymentController.php b/app/Controllers/Front/PaymentController.php
index 37019ca..9ad5e94 100644
--- a/app/Controllers/Front/PaymentController.php
+++ b/app/Controllers/Front/PaymentController.php
@@ -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);
+ }
}
}
diff --git a/app/Controllers/Front/UserController.php b/app/Controllers/Front/UserController.php
index e7e8d19..3a49a34 100644
--- a/app/Controllers/Front/UserController.php
+++ b/app/Controllers/Front/UserController.php
@@ -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];
diff --git a/app/Filters/AuthFilter.php b/app/Filters/AuthFilter.php
index de3ce2d..93639ee 100644
--- a/app/Filters/AuthFilter.php
+++ b/app/Filters/AuthFilter.php
@@ -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', '로그인을하셔야합니다.');
}
}
diff --git a/app/Libraries/Adapter/API/Adapter.php b/app/Libraries/Adapter/API/API.php
similarity index 98%
rename from app/Libraries/Adapter/API/Adapter.php
rename to app/Libraries/Adapter/API/API.php
index adf4c90..0481f03 100644
--- a/app/Libraries/Adapter/API/Adapter.php
+++ b/app/Libraries/Adapter/API/API.php
@@ -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();
diff --git a/app/Libraries/Adapter/API/CurlAdapter.php b/app/Libraries/Adapter/API/CurlAPI.php
similarity index 87%
rename from app/Libraries/Adapter/API/CurlAdapter.php
rename to app/Libraries/Adapter/API/CurlAPI.php
index 73610ed..07cde11 100644
--- a/app/Libraries/Adapter/API/CurlAdapter.php
+++ b/app/Libraries/Adapter/API/CurlAPI.php
@@ -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());
diff --git a/app/Libraries/Adapter/API/GuzzleAdapter.php b/app/Libraries/Adapter/API/GuzzleAPI.php
similarity index 98%
rename from app/Libraries/Adapter/API/GuzzleAdapter.php
rename to app/Libraries/Adapter/API/GuzzleAPI.php
index e1949b8..3592492 100644
--- a/app/Libraries/Adapter/API/GuzzleAdapter.php
+++ b/app/Libraries/Adapter/API/GuzzleAPI.php
@@ -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)
diff --git a/app/Libraries/Adapter/API/LocalAdapter.php b/app/Libraries/Adapter/API/LocalAdapter.php
index 9b20475..cb42fb1 100644
--- a/app/Libraries/Adapter/API/LocalAdapter.php
+++ b/app/Libraries/Adapter/API/LocalAdapter.php
@@ -2,7 +2,7 @@
namespace App\Libraries\Adapter\API;
-class LocalAdapter extends Adapter
+class LocalAPI extends API
{
public function __construct($debug = false)
{
diff --git a/app/Libraries/Adapter/Auth/Adapter.php b/app/Libraries/Adapter/Auth/Auth.php
similarity index 98%
rename from app/Libraries/Adapter/Auth/Adapter.php
rename to app/Libraries/Adapter/Auth/Auth.php
index 23e8080..2302dfd 100644
--- a/app/Libraries/Adapter/Auth/Adapter.php
+++ b/app/Libraries/Adapter/Auth/Auth.php
@@ -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;
diff --git a/app/Libraries/Adapter/Auth/GoogleAdapter.php b/app/Libraries/Adapter/Auth/GoogleAuth.php
similarity index 99%
rename from app/Libraries/Adapter/Auth/GoogleAdapter.php
rename to app/Libraries/Adapter/Auth/GoogleAuth.php
index c7ebfa8..8b0d29e 100644
--- a/app/Libraries/Adapter/Auth/GoogleAdapter.php
+++ b/app/Libraries/Adapter/Auth/GoogleAuth.php
@@ -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)
diff --git a/app/Libraries/Adapter/Auth/LocalAdapter.php b/app/Libraries/Adapter/Auth/LocalAuth.php
similarity index 95%
rename from app/Libraries/Adapter/Auth/LocalAdapter.php
rename to app/Libraries/Adapter/Auth/LocalAuth.php
index a4d3f62..9721453 100644
--- a/app/Libraries/Adapter/Auth/LocalAdapter.php
+++ b/app/Libraries/Adapter/Auth/LocalAuth.php
@@ -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)
{
diff --git a/app/Libraries/Adapter/Payment/CookiePayment.php b/app/Libraries/Adapter/Payment/CookiePayment.php
new file mode 100644
index 0000000..85d1909
--- /dev/null
+++ b/app/Libraries/Adapter/Payment/CookiePayment.php
@@ -0,0 +1,64 @@
+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);
+ }
+}
diff --git a/app/Libraries/Adapter/Payment/Payment.php b/app/Libraries/Adapter/Payment/Payment.php
new file mode 100644
index 0000000..6d2fdd2
--- /dev/null
+++ b/app/Libraries/Adapter/Payment/Payment.php
@@ -0,0 +1,13 @@
+_debug = $debug;
+ }
+ abstract public function execute();
+}
diff --git a/app/Views/front/payment/card.php b/app/Views/front/payment/card.php
index 7ff582b..528f544 100644
--- a/app/Views/front/payment/card.php
+++ b/app/Views/front/payment/card.php
@@ -3,10 +3,16 @@
= html_entity_decode($viewDatas['category']->head) ?>
-
상품정보표시
-
오더정보표시
= form_open_multipart(current_url(), $viewDatas['forms']['attributes'], $viewDatas['forms']['hiddens']) ?>