728x90

imp77046491
0884598594525840
hyFD8et93jBBdq78RDlrvOvczyHe1Gnjf2WngqxjJ8VWy34qHqRcenoOW62YMph2rdqIDX2m6YiF1n6J
이거 두개 설정하고 pg상점아이디를 jsp에 입력했어야했다.


package edu.bit.board.controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.servlet.ModelAndView; //import edu.bit.ex.vo.BoardVO; import lombok.AllArgsConstructor; import lombok.extern.log4j.Log4j; @Log4j @AllArgsConstructor @RestController @RequestMapping("/payments/*") public class PaymentCheck2 { @GetMapping("/complete") public ModelAndView list(ModelAndView mav) { mav.setViewName("money"); //mav.addObject("member", mav); log.info("결제모듈"); return mav; } // public String home() { // log.info("home"); // return "redirect:/payments/complete"; // } //@ResponseBody // @RequestMapping("/complete") // public String write() { // log.info("gggg"); // // return "money"; // } }
[money.jsp] <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <!-- jQuery --> <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> <!-- iamport.payment.js --> <script type="text/javascript" src="https://cdn.iamport.kr/js/iamport.payment-1.1.5.js"></script> </head> <body> <button onclick="requestPay()">결제하기</button> <script> <%-- <%String name = (String) request.getAttribute("name"); String email = (String) request.getAttribute("email"); String phone = (String) request.getAttribute("phone"); String address = (String) request.getAttribute("address"); int totalPrice = (int) request.getAttribute("totalPrice");%> --%> $(function() { var IMP = window.IMP; IMP.init('imp77046491'); /* 'iamport' 대신 부여받은 "가맹점 식별코드"를 사용 */ var msg; IMP .request_pay( { pg : "INIBillTst", pay_method : "card", merchant_uid : "ORD20180131-0000011", name : "노르웨이 회전 의자", amount : 100, buyer_email : "gildong@gmail.com", buyer_name : "홍길동", buyer_tel : "010-4242-4242", buyer_addr : "서울특별시 강남구 신사동", buyer_postcode : "01181" }, function(rsp) { // callback if (rsp.success) { //[1] 서버단에서 결제정보 조회를 위해 jQuery ajax로 imp_uid 전달하기 jQuery .ajax( { url : "${pageContext.request.contextPath}/payments/complete", //cross-domain error가 발생하지 않도록 주의해주세요 type : 'POST', dataType : 'json', data : { imp_uid : rsp.imp_uid //기타 필요한 데이터가 있으면 추가 전달 } }) .done( function(data) { //[2] 서버에서 REST API로 결제정보확인 및 서비스루틴이 정상적인 경우 if (everythings_fine) { msg = '결제가 완료되었습니다.'; msg += '\n고유ID : ' + rsp.imp_uid; msg += '\n상점 거래ID : ' + rsp.merchant_uid; msg += '\결제 금액 : ' + rsp.paid_amount; msg += '카드 승인번호 : ' + rsp.apply_num; alert(msg); } else { //[3] 아직 제대로 결제가 되지 않았습니다. //[4] 결제된 금액이 요청한 금액과 달라 결제를 자동취소처리하였습니다. } }); //성공시 이동할 페이지 location.href = '${pageContext.request.contextPath}/order/paySuccess?msg=' + msg; } else { msg = '결제에 실패하였습니다.'; msg += '에러내용 : ' + rsp.error_msg; //실패시 이동할 페이지 location.href = "${pageContext.request.contextPath}/order/payFail"; alert(msg); } }); }); </script> </body> </html>

728x90
댓글