|
|
@@ -0,0 +1,82 @@
|
|
|
+package com.style24.core.biz.thirdparty;
|
|
|
+
|
|
|
+import java.net.URI;
|
|
|
+
|
|
|
+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.Component;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import com.gagaframework.web.parameter.GagaMap;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
+import com.style24.core.support.message.TscMessageByLocale;
|
|
|
+import com.style24.persistence.domain.KakaoPay;
|
|
|
+import com.style24.persistence.domain.NaverPay;
|
|
|
+
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 네이버페이 API
|
|
|
+ *
|
|
|
+ * @author card007
|
|
|
+ * @since 2021. 03. 07
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class NaverPayApi {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private Environment env;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TscMessageByLocale message;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 네이버페이 API
|
|
|
+ *
|
|
|
+ * @param Order
|
|
|
+ * @return GagaMap
|
|
|
+ * @author card007
|
|
|
+ * @since 2021. 03. 07
|
|
|
+ */
|
|
|
+ public NaverPay naverPaymentApi(NaverPay params, String apiUrl) {
|
|
|
+ NaverPay naverPay;
|
|
|
+ try {
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+ headers.set("X-Naver-Client-Id", "8TSWSyJMMUvOLKUySQx6");
|
|
|
+ headers.set("X-Naver-Client-Secret", "oGXnO7cMD1");
|
|
|
+ // headers.set("X-Naver-Client-Id", env.getProperty("naver.clientId"));
|
|
|
+ // headers.set("X-Naver-Client-Secret", env.getProperty("naver.clientSecret"));
|
|
|
+
|
|
|
+
|
|
|
+ HttpEntity<NaverPay> request = new HttpEntity<>(params, headers);
|
|
|
+ URI url = URI.create(apiUrl);
|
|
|
+
|
|
|
+ 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();
|
|
|
+ naverPay = gson.fromJson(jsonResult, NaverPay.class);
|
|
|
+ naverPay.setStatusCode(responseEntity.getStatusCode().value());
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // throw new IllegalStateException(message.getMessage("FAIL_0004"));
|
|
|
+ throw new IllegalStateException(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return naverPay;
|
|
|
+ }
|
|
|
+}
|