瀏覽代碼

카카오페이 임시 커밋

card007 5 年之前
父節點
當前提交
b540a0576c
共有 1 個文件被更改,包括 97 次插入0 次删除
  1. 97 0
      src/main/java/com/style24/core/biz/service/TscKakaoPayService.java

+ 97 - 0
src/main/java/com/style24/core/biz/service/TscKakaoPayService.java

@@ -0,0 +1,97 @@
+package com.style24.core.biz.service;
+
+import java.net.URI;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import com.gagaframework.web.parameter.GagaMap;
+import com.gagaframework.web.util.GagaFileUtil;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.style24.core.biz.dao.TscPointDao;
+import com.style24.persistence.domain.Order;
+import com.style24.persistence.domain.Point;
+
+import lombok.extern.slf4j.Slf4j;
+
+/**
+ * 카카오페이 Service
+ * 
+ * @author card007
+ * @since 2020. 03. 03
+ */
+@Service
+@Slf4j
+public class TscKakaoPayService {
+
+	@Autowired
+	private Environment env;
+
+	@Autowired
+	private RestTemplate restTemplate;
+
+	public static final String PROTOCOL = "http:";
+
+	/**
+	 * 카카오페이 결제준비 처리
+	 * 
+	 * @param Order
+	 * @return GagaMap
+	 * @author card007
+	 * @since 2021. 03. 03
+	 */
+	@Transactional("shopTxnManager")
+	public GagaMap kakaoPaymentReady(Order order) {
+		GagaMap map = new GagaMap();
+		String paymentReadyUrl = env.getProperty("kakao.paymentReadyUrl");
+		try {
+			MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
+			params.add("cid", "TC0ONETIME");
+			params.add("partner_order_id", order.getOrdNo()+"");
+			params.add("partner_user_id", order.getCustNo()+"");
+			params.add("item_name", order.getGoodsNm());
+			params.add("quantity", order.getOrdQty()+"");
+			params.add("total_amount", order.getRealOrdAmt()+"");
+			params.add("vat_amount", (order.getRealOrdAmt()*0.1)+"");
+			params.add("tax_free_amount", "0");
+			params.add("approval_url", PROTOCOL + env.getProperty("domain.front"));
+			params.add("fail_url", PROTOCOL + env.getProperty("domain.front"));
+			params.add("cancel_url", PROTOCOL + env.getProperty("domain.front"));
+
+			// Header
+			HttpHeaders headers = new HttpHeaders();
+			headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+			headers.set("Authorization", env.getProperty("kakao.adminKey"));
+
+			HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);
+			URI url = URI.create(paymentReadyUrl);
+
+			// POST방식으로 호출
+			ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, request, String.class);
+			log.info("responseEntity.getStatusCode(): {} ", responseEntity.getStatusCode());
+
+			String jsonResult = responseEntity.getBody();
+			log.info("responseEntity.getBody(): {} ", jsonResult);
+
+			Gson gson = new GsonBuilder().create();
+			map = gson.fromJson(jsonResult, GagaMap.class); //access_token, refresh_token
+
+		} catch (Exception e) {
+			log.error(e.getMessage());
+		}
+		
+		return map;
+	}
+	
+}