Просмотр исходного кода

이태영 - 20210507 네이버페이 개발 중

xodud lee 5 лет назад
Родитель
Сommit
6ee7ecba54

+ 4 - 4
src/main/java/com/style24/front/biz/service/TsfCartService.java

@@ -142,7 +142,7 @@ public class TsfCartService {
 					}
 
 					// 금일 주문 수량 체크
-					if (!StringUtils.isEmpty(param.getCartGb()) && ("O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
+					if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
 						int goodsCartCnt = 0;
 						if(param.getCustNo() != 0) {
 							goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
@@ -203,7 +203,7 @@ public class TsfCartService {
 				}
 
 				// 금일 주문 수량 체크
-				if (!StringUtils.isEmpty(param.getCartGb()) && ("O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
+				if (!StringUtils.isEmpty(param.getCartGb()) && ("N".equals(param.getCartGb()) || "O".equals(param.getCartGb()) || "G".equals(param.getCartGb()))) {
 					int goodsCartCnt = 0;
 					if(param.getCustNo() != 0) {
 						goodsCartCnt = cartDao.getGoodsTodayOrderCnt(param);
@@ -307,7 +307,7 @@ public class TsfCartService {
 				cart.setCartGb(TscConstants.CartGb.CART.value());
 				// 같은 장바구니 상품 확인
 				cartSqList = cartDao.selectHasSetItemCartList(cart);
-			} else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && "O".equals(cartInfos.iterator().next().getCartGb())) {
+			} else if (!StringUtils.isEmpty(cartInfos.iterator().next().getCartGb()) && ("N".equals(cartInfos.iterator().next().getCartGb()) || "O".equals(cartInfos.iterator().next().getCartGb()))) {
 				if ("P".equals(TsfSession.getFrontGb())) {
 					cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
 				} else {
@@ -376,7 +376,7 @@ public class TsfCartService {
 
 		if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "C".equals(params.iterator().next().getCartGb())) {
 			cart.setCartGb(TscConstants.CartGb.CART.value());
-		} else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && "O".equals(params.iterator().next().getCartGb())) {
+		} else if (!StringUtils.isEmpty(params.iterator().next().getCartGb()) && ("N".equals(params.iterator().next().getCartGb()) || "O".equals(params.iterator().next().getCartGb()))) {
 			if ("P".equals(TsfSession.getFrontGb())) {
 				cart.setCartGb(TscConstants.CartGb.PC_ORDER.value());
 			} else {

+ 40 - 0
src/main/java/com/style24/front/biz/service/TsfOrderService.java

@@ -330,6 +330,10 @@ public class TsfOrderService {
 			param.setPayMeans(TscConstants.PayMeans.CREDIT_CARD.value());
 		}
 
+		if(TscConstants.FrontGb.MOB.value().equals(TsfSession.getFrontGb()) && StringUtils.isNotEmpty(request.getParameter("param_opt_3"))) {
+			param.setOrdChgSq(Integer.parseInt(request.getParameter("param_opt_3")));
+		}
+
 		try {
 			if(StringUtils.isEmpty(param.getPgGb())) {
 				throw new IllegalArgumentException("결제수단을 선택해주세요.");
@@ -352,6 +356,13 @@ public class TsfOrderService {
 					result.setPayMeans(param.getPayMeans());
 				} else {
 					// 일반 KCP 결제
+					if(param.getOrdChgSq() > 0) {
+						param.setPgOrdNo("C" + param.getOrdChgSq());
+					} else {
+						param.setPgOrdNo(request.getParameter("ordr_idxx"));
+					}
+
+					param.setOrdNo(Integer.parseInt(request.getParameter("ordr_idxx")));
 					result = coreKcpService.kcpPayRequest(param, request, response);
 				}
 			} else if (TscConstants.PgGb.KAKAO.value().equals(param.getPgGb())) {
@@ -902,4 +913,33 @@ public class TsfOrderService {
 
 		return "SUCCESS";
 	}
+
+	public GagaMap nPayReq50(Order param) {
+		GagaMap result = new GagaMap();
+
+		try {
+			param.setFrontGb(TsfSession.getFrontGb());
+			param.setSiteCd(TscConstants.Site.STYLE24.value());
+			if(TsfSession.isLogin()) {
+				param.setCustNo(TsfSession.getInfo().getCustNo());
+			} else {
+				param.setCustNo(0);
+				param.setJsessionId(TsfSession.getSessionId());
+			}
+
+			// 장바구니 정보 조회
+			Collection<Order> cartList = coreOrderService.getCartGoodsList(param);
+
+
+
+			result.put("state", "sucess");
+		} catch(Exception e) {
+			result.put("state", "fail");
+			result.put("message", "주문실패");
+
+			e.printStackTrace();
+		}
+
+		return result;
+	}
 }

+ 41 - 15
src/main/java/com/style24/front/biz/web/TsfPgController.java

@@ -1,31 +1,31 @@
 package com.style24.front.biz.web;
 
-import java.io.PrintWriter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.servlet.ModelAndView;
-
+import com.gagaframework.web.parameter.GagaMap;
 import com.style24.core.biz.service.TscOrderService;
 import com.style24.front.biz.service.TsfOrderService;
 import com.style24.front.support.controller.TsfBaseController;
 import com.style24.front.support.security.session.TsfSession;
 import com.style24.persistence.domain.Order;
 import com.style24.persistence.domain.Payment;
-
 import kr.co.kcp.net.connection.ConnectionKCP;
 import kr.co.kcp.net.connection.dto.ParamData;
 import kr.co.kcp.net.connection.util.HttpJsonXml;
 import kr.co.kcp.net.connection.util.OpenHash;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.PrintWriter;
+import java.util.Collection;
 
 @Controller
 @RequestMapping("/pg")
@@ -169,4 +169,30 @@ public class TsfPgController extends TsfBaseController {
 		mav.setViewName(super.getDeviceViewName("pg/kcpOrder"));
 		return mav;
 	}
+
+	/**
+	 * 네이버 페이 결제 모듈
+	 * @param request
+	 * @param response
+	 * @param cart
+	 * @param model
+	 * @return
+	 * @throws Exception
+	 */
+	@ResponseBody
+	@PostMapping("/nPayReq")
+	public GagaMap nPayReq(@RequestBody Order param) {
+		GagaMap map = new GagaMap();
+		//for(Order param : params) {
+		//	log.info("CHECK NPAY INPUT >>>> {} / {} / {}", param.getGoodsCd(), param.getOptCd(), param.getGoodsQty());
+		//}
+
+		for(int cartSq : param.getCartSqArr()) {
+			log.info("CHECK NPAY INPUT >>>> {}", param.getCartSqArr());
+		}
+
+		map = orderService.nPayReq50(param);
+
+		return map;
+	}
 }

+ 1 - 0
src/main/resources/config/application-locd.yml

@@ -87,6 +87,7 @@ naverPay:
     button.key : 5DF64042-EF37-45F1-878E-67C7098135E6
     common.certification.key : s_3799db3bf4af-
     certification.key: 2BC5E173-2840-4B48-BC7D-FF770005DD76
+    order.api.url: https://test-api.pay.naver.com/o/customer/api/order/v20/register
 
 # ERP (한세드림)
 erp:

+ 5 - 0
src/main/resources/config/application-run.yml

@@ -97,3 +97,8 @@ naverPay:
     payUrl:
         web : pay.naver.com
         mob : m.pay.naver.com
+    shop.id: istyle2401
+    button.key: 5DF64042-EF37-45F1-878E-67C7098135E6
+    common.certification.key: s_3799db3bf4af-
+    certification.key: 2BC5E173-2840-4B48-BC7D-FF770005DD76
+    order.api.url: https://api.pay.naver.com/o/customer/api/order/v20/register

+ 1 - 0
src/main/resources/config/application-style.yml

@@ -87,3 +87,4 @@ naverPay:
     button.key: 5DF64042-EF37-45F1-878E-67C7098135E6
     common.certification.key: s_3799db3bf4af-
     certification.key: 2BC5E173-2840-4B48-BC7D-FF770005DD76
+    order.api.url: https://test-api.pay.naver.com/o/customer/api/order/v20/register

+ 5 - 0
src/main/resources/config/application-tsit.yml

@@ -84,3 +84,8 @@ naverPay:
     payUrl:
         web : test-pay.naver.com
         mob : test-m.pay.naver.com
+    shop.id: istyle2401
+    button.key: 5DF64042-EF37-45F1-878E-67C7098135E6
+    common.certification.key: s_3799db3bf4af-
+    certification.key: 2BC5E173-2840-4B48-BC7D-FF770005DD76
+    order.api.url: https://test-api.pay.naver.com/o/customer/api/order/v20/register

+ 3 - 2
src/main/webapp/WEB-INF/views/mob/pg/kcpOrderMob.html

@@ -28,8 +28,8 @@
 	<input type="hidden" name="van_code"		value="">							<!-- 인증시 필요한 파라미터(변경불가)-->
 	<input type="hidden" name="quotaopt"		th:value="${payment.quotaopt}"/>	<!-- 최대 할부 개월 수(0 ~ 18까지 설정 가능) -->
 	<input type="hidden" name="ipgm_date"		value=""/>							<!-- 가상계좌설정 -->
-	<input type="hidden" name="PayUrl"			th:value="${'http:' + @environment.getProperty('domain.front') + '/order/create/preOrder'}" id="PayUrl"/>	<!-- 결제 정보 등록시 응답 타입 ( 필드가 없거나 값이 '' 일경우 TEXT, 값이 XML 또는 JSON 지원 -->
-	<input type="hidden" name="Ret_URL"			th:value="${'http:' + @environment.getProperty('domain.front') + '/pg/pay/result/response'}">			<!-- 리턴 URL (kcp와 통신후 결제를 요청할 수 있는 암호화 데이터를 전송 받을 가맹점의 주문페이지 URL) -->
+	<input type="hidden" name="PayUrl"			th:value="${'http:' + @environment.getProperty('domain.front') + payment.payUrl}" id="PayUrl"/>	<!-- 결제 정보 등록시 응답 타입 ( 필드가 없거나 값이 '' 일경우 TEXT, 값이 XML 또는 JSON 지원 -->
+	<input type="hidden" name="Ret_URL"			th:value="${'http:' + @environment.getProperty('domain.front') + payment.retUrl}">			<!-- 리턴 URL (kcp와 통신후 결제를 요청할 수 있는 암호화 데이터를 전송 받을 가맹점의 주문페이지 URL) -->
 
 	<input type="hidden" name="tablet_size"		value="1.0">						<!-- 화면 크기 조정 -->
 	<input type="hidden" name="response_type"	value="TEXT"/>						<!-- 결제 정보 등록시 응답 타입 ( 필드가 없거나 값이 '' 일경우 TEXT, 값이 XML 또는 JSON 지원 -->
@@ -51,6 +51,7 @@
 	<input type="hidden" name="cash_tr_code"	value=""/>
 	<input type="hidden" name="param_opt_1"		th:value="${payment.pgGb}" />		<!-- 모바일은 URL 로 변수 이동하므로 추가 변수로 KCP인지 PAYCO인지 송부 -->
 	<input type="hidden" name="param_opt_2"		th:value="${payment.shopUserId}" />	<!-- 모바일은 URL 로 변수 이동하므로 추가 변수로 custNo 송부 -->
+	<input type="hidden" name="param_opt_3"		th:value="${payment.ordChgSq}" />	<!-- 모바일은 URL 로 변수 이동하므로 추가 변수로 custNo 송부 -->
 
 	<input type="hidden" name="shop_user_id"	th:value="${payment.shopUserId}" />	<!-- 필수, 쇼핑몰회원ID 기관에 따라 RM 조치를 위해 쇼핑몰 관리 ID를 필수로 요청 -->
 

+ 74 - 35
src/main/webapp/WEB-INF/views/web/goods/GoodsDetailFormWeb.html

@@ -372,9 +372,6 @@
 								<th:block th:with="buttonKey=${@environment.getProperty('naverPay.button.key')}">
 									<script type="text/javascript" src="http://pay.naver.com/customer/js/naverPayButton.js" charset="UTF-8"></script>
 									<script type="text/javascript" >
-										//<![CDATA[
-										/*#if($!NPAY_USE_YN == "Y")
-										#if ($LANG == "ko")*/
 										/*버튼설정*/
 										naver.NaverPayButton.apply({
 											BUTTON_KEY              : "[[${buttonKey}]]",       // 네이버페이에서 제공받은 버튼 인증 키 입력
@@ -385,47 +382,59 @@
 											BUY_BUTTON_HANDLER      : buy_nc,                   // 구매하기 버튼 이벤트 Handler 함수 등록, 품절인 경우 not_buy_nc 함수 사용
 											"":""
 										});
-										/*#end
-										#end*/
 
 										/*네이버구매하기*/
 										function buy_nc(url) {
-											if ($('#goods_color').val().isBlank()) {
-												alert("$!{rc.getMessage(\"msg.alert.validation.select.color\")}");    /*컬러*/
-												return false;
-											}
-											if ($('#goods_size').val().isBlank()) {
-												alert("$!{rc.getMessage(\"msg.alert.validation.select.option\")}");   /*옵션*/
-												return false;
-											}
-											if ($('#size_qty').val().isBlank()) {
-												alert("$!{rc.getMessage(\"msg.alert.validation.select.qty\")}");      /*수량*/
-												return false;
-											}
+											let goodsCd = "[[${goodsInfo.goodsCd}]]";
+											let optCd = $(".opt_size .form_field input[type=radio]:checked").attr("optcd");
+											let goodsQty = $(".opt_count .number_count input[name=cea]").val();
+											let goodsType = "[[${goodsInfo.goodsType}]]";
 
-											/*네이버페이로 주문 정보를 등록하는 가맹점 페이지로 이동.*/
-											var itemCount   = $('#size_qty').val();
-											var itemUPrice  = "$!shopView.sale_amt";
-											var itemTPrice  = itemUPrice * itemCount;
+											if(goodsType == "G056_N") {
+												if (!goodsCd) {
+													mcxDialog.alert("상품정보가 존재하지 않습니다. 새로고침 후 다시 시도해주세요.");
+													return false;
+												}
+												if (!optCd) {
+													mcxDialog.alert("상품 옵션을 확인 할 수 없습니다. 새로고침 후 다시 시도해주세요.");   /*옵션*/
+													return false;
+												}
+												if (!goodsQty || goodsQty < 1) {
+													mcxDialog.alert("구매 수량을 확인해주세요.");      /*수량*/
+													return false;
+												}
 
-											var params          = new Object();
-											params.ITEM_CD      = $('#goods_code').val();
-											params.ITEM_COUNT   = itemCount;
-											params.ITEM_OPTION  = $('#goods_color').val()+"/"+$('#goods_size').val();
-											params.BACK_URL     = location.href;
+												let compsList = [];
+												let obj = new Object();
+												obj.goodsCd = goodsCd;
+												obj.optCd = optCd;
+												obj.goodsQty = goodsQty;
+												obj.goodsType = goodsType;
+												obj.cartGb = "N";
+												obj.afLinkCd =$("#cartForm  input[name=afLinkCd]").val();
+												obj.ithrCd =$("#cartForm  input[name=ithrCd]").val();
+												obj.contentsLoc =$("#cartForm  input[name=contentsLoc]").val();
+												obj.planDtlSq = $("#cartForm  input[name=planDtlSq]").val();
+												compsList.push(obj);
 
-											var nPayReqUrl     = "/order/nPayReq.do";
+												// 장바구니담기
+												cfnAddCart(compsList);
+											} else {
+												// TODO 세트상품 추가 예정
+												alert("개발 중");
+											}
 
-											/*네이버페이 ajax*/
-											jQuery.ajax({
-												type        : 'POST',
-												url         : '/order/nPayReq.do',
-												data        : params,
+											/*$.ajax( {
+												type        : "POST",
+												url         : "/pg/nPayReq",
+												dataType    : 'json',
+												contentType : 'application/json',
+												data        : JSON.stringify(param),
 												async       : false,
 												error: function(xhr, status, error) {
-													alert(status + '; ' + error);
+													alert("!!  " + status + '; ' + error);
 												},
-												success     : function(result) {
+												success : function(result) {
 													if (result.state == "sucess") {
 														window.open('about:blank', 'popupView');
 														document.nPayForm.target = 'popupView';
@@ -435,7 +444,7 @@
 														alert(result.message);
 													}
 												}
-											});
+											});*/
 
 											//해당 페이지에서 주문 정보 등록 후 네이버페이 주문서 페이지로 이동.
 											//네이버페이로 주문 정보를 등록하는 가맹점 페이지로 이동.
@@ -443,6 +452,36 @@
 											return false;
 										}
 
+										function buy_nc_req(cartSqArr) {
+											alert(cartSqArr.length);
+											// buyList[0].backUrl = location.href;
+
+											$.ajax( {
+												type		: "POST",
+												url 		: "/pg/nPayReq",
+												dataType 	: 'json',
+												data		: {cartSqArr : JSON.stringify(cartSqArr)},
+												beforeSend : function(xhr, settings) {
+													xhr.setRequestHeader("AJAX"			, "true");
+													xhr.setRequestHeader('Accept'		, 'application/json');
+													xhr.setRequestHeader('Content-Type'	, 'application/json');
+												},
+												error: function(xhr, status, error) {
+													alert(status + '; ' + error);
+												},
+												success : function(result) {
+													if (result.state == "sucess") {
+														window.open('about:blank', 'popupView');
+														document.nPayForm.target = 'popupView';
+														document.nPayForm.action = "$!{NPAY_ORDER_URL}" + result.orderKey + "/" + result.resultNo;
+														document.nPayForm.submit();
+													} else {
+														alert(result.message);
+													}
+												}
+											});
+										}
+
 										/*네이버찜*/
 										/*function wishlist_nc(url) {
 											// 네이버페이로 찜 정보를 등록하는 가맹점 페이지 팝업 창 생성.

+ 2 - 0
src/main/webapp/ux/style24_link.js

@@ -338,6 +338,8 @@ function cfnAddCart(cartList) {
 					}
 					$("#directOrderForm").html(orderHtml);
 					$("#directOrderForm").submit();
+				} else if (result.cartGb == "N") {
+					buy_nc_req(result.cartSqList);
 				} else {
 					mcxDialog.alert("해당 기능을 사용 할 수 없습니다. 새로고침 후 다시 시도해주세요.");
 				}