Prechádzať zdrojové kódy

네이버페이 임시 커밋

card007 5 rokov pred
rodič
commit
2036dd4b55

+ 22 - 8
src/main/java/com/style24/front/biz/service/TsfOrderService.java

@@ -17,11 +17,14 @@ import org.springframework.transaction.annotation.Transactional;
 import org.thymeleaf.util.StringUtils;
 
 import com.gagaframework.web.parameter.GagaMap;
+import com.style24.core.biz.service.TscKakaoPayService;
 import com.style24.core.biz.service.TscKcpService;
+import com.style24.core.biz.service.TscNaverPayService;
 import com.style24.core.support.env.TscConstants;
 import com.style24.core.support.session.TscSession;
 import com.style24.front.biz.dao.TsfOrderDao;
 import com.style24.front.support.security.session.TsfSession;
+import com.style24.persistence.domain.KakaoPay;
 import com.style24.persistence.domain.Order;
 import com.style24.persistence.domain.Payment;
 
@@ -42,6 +45,12 @@ public class TsfOrderService {
 
 	@Autowired
 	private TscKcpService coreKcpService;
+	
+	@Autowired
+	private TscKakaoPayService coreKakaoPayService;
+	
+	@Autowired
+	private TscNaverPayService coreNaverPayService;
 
 	/**
 	 * 마이페이지 검색 기간 영역 설정
@@ -237,7 +246,7 @@ public class TsfOrderService {
 			if(TscConstants.PgGb.KCP.value().equals(param.getPgGb()) || TscConstants.PgGb.PAYCO.value().equals(param.getPgGb())) {
 				result = coreKcpService.kcpPayRequest(param, request, response);
 			} else if (TscConstants.PgGb.KAKAO.value().equals(param.getPgGb())) {
-				result = null;
+				result = coreKakaoPayService.approveKakaoPayment(param);
 			} else if (TscConstants.PgGb.NAVER.value().equals(param.getPgGb())) {
 				result = null;
 			} else {
@@ -250,9 +259,15 @@ public class TsfOrderService {
 
 			if(updatePaymentForOrderFinished(result) < 1) {
 				// TODO 전체 취소 로직 추가
-				coreKcpService.kcpPayRollBack(result, request);
-
-				throw new IllegalArgumentException("결제 정보 저장 실패. 새로고침 후 다시 시작해주세요.");
+				if(TscConstants.PgGb.KCP.value().equals(param.getPgGb()) || TscConstants.PgGb.PAYCO.value().equals(param.getPgGb())) {
+					coreKcpService.kcpPayRollBack(result, request);
+				} else if (TscConstants.PgGb.KAKAO.value().equals(param.getPgGb())) {
+					coreKakaoPayService.cancelKakaoPayment(param);
+				} else if (TscConstants.PgGb.NAVER.value().equals(param.getPgGb())) {
+					result = null;
+				} else {
+					throw new IllegalArgumentException("결제 정보 저장 실패. 새로고침 후 다시 시작해주세요.");
+				}
 			}
 
 			coreKcpService.kcpPayRollBack(result, request);
@@ -335,11 +350,10 @@ public class TsfOrderService {
 	public Payment setPgDataInfo(Order order) {
 		Payment payment = new Payment();
 		if(TscConstants.PgGb.KAKAO.value().equals(order.getPgGb())) {			// 카카오페이
-			// TODO 카카오페이 데이터 세팅
-			payment = null;
+			KakaoPay kakaoPay = coreKakaoPayService.kakaoPaymentReady(order);
+			payment = coreKakaoPayService.setKakaoOrderData(kakaoPay, order);
 		} else if(TscConstants.PgGb.NAVER.value().equals(order.getPgGb())) {	// 네이버페이
-			// TODO 네이버페이 데이터 세팅
-			payment = null;
+			payment = coreNaverPayService.setNaverOrderData(order);
 		} else if(TscConstants.PgGb.KCP.value().equals(order.getPgGb()) || TscConstants.PgGb.PAYCO.value().equals(order.getPgGb())){	// KCP, PAYCO
 			payment = coreKcpService.setKcpOrderData(order);
 		} else {

+ 14 - 16
src/main/java/com/style24/front/biz/web/TsfOrderController.java

@@ -789,6 +789,16 @@ public class TsfOrderController extends TsfBaseController {
 		// pgGb = 결제타입, payMeans = 결제수단, ordNo = 주문번호, goodsNm = 상품명, payAmt = 실결제금액, ordNm = 주문자명, ordPhnno = 휴대폰번호, custNo = 고객번호
 		// 선택 데이터
 		// ordEmail = 주문자메일, ordTelno = 전화번호
+		
+		/* 
+		=== 카카오페이 & 네이버페이 파라메터 ===
+		ordNo = 주문번호
+		custNo = 고객번호
+		goodsNm = 상품명
+		ordGoodsQty = 주문상품수량
+		payAmt = 결제금액
+		======================
+		*/
 		Payment payment = orderService.setPgDataInfo(order);
 
 		mav.addObject("payment", payment);
@@ -854,16 +864,10 @@ public class TsfOrderController extends TsfBaseController {
 	 */
 	@RequestMapping(value = "/kakao/payment/approve")
 	@ResponseBody
-	public GagaMap approveKakaoPayment(@RequestBody Order order) {
+	public GagaMap approveKakaoPayment(@RequestBody Payment payment) {
 		GagaMap result = new GagaMap();
 
-		if (TsfSession.getInfo().getCustNo() == null) {
-			order.setCustNo(0);
-		} else {
-			order.setCustNo(TsfSession.getInfo().getCustNo());
-		}
-
-		result.set("payment", kakaoPayService.approveKakaoPayment(order));
+		result.set("payment", kakaoPayService.approveKakaoPayment(payment));
 		result.set("status", GagaResponseStatus.SUCCESS.getCode());
 
 		return result;
@@ -904,16 +908,10 @@ public class TsfOrderController extends TsfBaseController {
 	 */
 	@RequestMapping(value = "/kakao/payment/cancel")
 	@ResponseBody
-	public GagaMap cancelKakaoPayment(@RequestBody Order order) {
+	public GagaMap cancelKakaoPayment(@RequestBody Payment payment) {
 		GagaMap result = new GagaMap();
 
-		if (TsfSession.getInfo().getCustNo() == null) {
-			order.setCustNo(0);
-		} else {
-			order.setCustNo(TsfSession.getInfo().getCustNo());
-		}
-
-		result.set("kakaoPay", kakaoPayService.cancelKakaoPayment(order));
+		result.set("kakaoPay", kakaoPayService.cancelKakaoPayment(payment));
 		result.set("status", GagaResponseStatus.SUCCESS.getCode());
 
 		return result;

+ 2 - 0
src/main/resources/config/application.yml

@@ -60,6 +60,7 @@ naverPay:
     clientId: 8TSWSyJMMUvOLKUySQx6
     clientSecret: oGXnO7cMD1
     paymentReadyUrl: /naverpay/payments/v2/reserve
+    paymentRedirectUrl: /order/naver/payment/request
     approvePaymentUrl: /naverpay/payments/v2/apply/payment
     paymentOrderUrl: /naverpay/payments/v2/list/history
     cancelPaymentUrl: /naverpay/payments/v1/cancel
@@ -91,6 +92,7 @@ kakao:
     authorizeUrl: https://kauth.kakao.com/oauth/authorize
     unlinkUrl : https://kapi.kakao.com/v1/user/unlink
     paymentReadyUrl : https://kapi.kakao.com/v1/payment/ready
+    paymentRedirectUrl : /order/kakao/payment/request
     approvePaymentUrl : https://kapi.kakao.com/v1/payment/approve
     paymentOrderUrl : https://kapi.kakao.com/v1/payment/order
     cancelPaymentUrl : https://kapi.kakao.com/v1/payment/cancel

+ 15 - 34
src/main/webapp/WEB-INF/views/web/order/OrderFormWeb.html

@@ -132,34 +132,15 @@
 
 		// 카카오페이 결제준비 처리
 		var fnKakaoPaymentReady = function() {
-			const protocol = 'http:';
-			let url = '/order/kakao/payment/ready';
-			let redirectUrl = '/order/kakao/payment/request';
-			let data = {};
-			data.ordNo = $('#order_info input[name=ordr_idxx]').val();
-			data.goodsNm = $('#order_info input[name=good_name]').val();
-			data.ordQty = $('#ordQty').text();
-			data.realOrdAmt = $('#order_info input[name=good_mny]').val();
-			data.approvalUrl = protocol + _frontUrl + redirectUrl;
-			data.failUrl = protocol + _frontUrl + redirectUrl;
-			data.cancelUrl = protocol + _frontUrl + redirectUrl;
-
-			let jsonData = JSON.stringify(data);
-
-			gagajf.ajaxJsonSubmit(url, jsonData, function(result) {
-				let tid = result.kakaoPay.tid;
-				let nextRedirectUrl = result.kakaoPay.next_redirect_pc_url;
-				let option = 'width=420, height=520';
-
-				$('#order_info').append('<input type=hidden name="pgTid" value="' + tid + '" />');
-
-				window.open(nextRedirectUrl, 'kakaoPaymentPopup', option);
-			});
+			let nextRedirectUrl = $('#order_info input[name=nextRedirectPcUrl]').val();
+			let option = 'width=420, height=520';
+			
+			window.open(nextRedirectUrl, 'kakaoPaymentPopup', option);
 		}
 
 		// 카카오페이 결제 승인 요청
 		var fnKakaoPaymentRequest = function(pgToken) {
-			$('#order_info').append('<input type=hidden name="pgToken" value="' + pgToken + '" />');
+			$('#order_info input[name=pgToken]').val(pgToken);
 
 			let url = '/order/kakao/payment/approve';
 			let data = {};
@@ -220,15 +201,15 @@
 	<!-- =========== 네이버페이 ============= -->
 	<script src="https://nsp.pay.naver.com/sdk/js/naverpay.min.js"></script>
 	<script th:inline="javascript">
-		let custNo = [[${sessionInfo.custNo}]];
-		let naverPayClientId = [[${@environment.getProperty('naverPay.clientId')}]];
-		let redirectUrl = '/order/naver/payment/request';
-		const protocol = 'http:';
-		
-		var oPay = Naver.Pay.create({
-			"mode" : "development",				// development or production
-			"clientId": naverPayClientId	// clientId
-		});
+		//let custNo = [[${sessionInfo.custNo}]];
+		//let naverPayClientId = [[${@environment.getProperty('naverPay.clientId')}]];
+		//let redirectUrl = '/order/naver/payment/request';
+		//const protocol = 'http:';
+		//
+		//var oPay = Naver.Pay.create({
+		//	"mode" : "development",				// development or production
+		//	"clientId": naverPayClientId	// clientId
+		//});
 		
 		$(document).on("click", "#naverBtn", function() {
 			$.ajax( {
@@ -1889,4 +1870,4 @@ $(document).ready( function() {
 
 </th:block>
 </body>
-</html>
+</html>

+ 23 - 0
src/main/webapp/WEB-INF/views/web/pg/kcpOrderWeb.html

@@ -63,4 +63,27 @@
 	<input type="hidden" name="cash_yn"         value=""/>
 	<input type="hidden" name="cash_tr_code"    value=""/>
 	<input type="hidden" name="cash_id_info"    value=""/>
+
+	<!-- 카카오페이 관련 정보 -->
+	<input type="hidden" name="pgTid" th:value="${payment.pgTid}"/>
+	<input type="hidden" name="partnerOrderId" th:value="${payment.partnerOrderId}"/>
+	<input type="hidden" name="partnerUserId" th:value="${payment.partnerUserId}"/>
+	<input type="hidden" name="pgToken" th:value="${payment.pgToken}"/>
+	<input type="hidden" name="nextRedirectAppUrl" th:value="${payment.nextRedirectAppUrl}"/>
+	<input type="hidden" name="nextRedirectMobileUrl" th:value="${payment.nextRedirectMobileUrl}"/>
+	<input type="hidden" name="nextRedirectPcUrl" th:value="${payment.nextRedirectPcUrl}"/>
+	<input type="hidden" name="androidAppScheme" th:value="${payment.androidAppScheme}"/>
+	<input type="hidden" name="iosAppScheme" th:value="${payment.iosAppScheme}"/>
+
+	<!-- 네이버페이 관련 정보 -->
+	<input type="hidden" name="modelVersion" value="2"/>
+	<input type="hidden" name="merchantUserKey" th:value="${payment.custNo}"/>
+	<input type="hidden" name="merchantPayKey" th:value="${payment.ordNo}"/>
+	<input type="hidden" name="productName" th:value="${payment.productName}"/>
+	<input type="hidden" name="productCount" th:value="${payment.productCount}"/>
+	<input type="hidden" name="totalPayAmount" th:value="${payment.payAmt}"/>
+	<input type="hidden" name="taxScopeAmount" th:value="${payment.payAmt}"/>
+	<input type="hidden" name="taxExScopeAmount" value=0/>
+	<input type="hidden" name="returnUrl" th:value="${payment.returnUrl}"/>
+
 </html>