@@ -10,6 +10,7 @@ import goodspace.teaming.payment.domain.PaymentApproveRespond
1010import goodspace.teaming.payment.dto.PaymentApproveRequestDto
1111import goodspace.teaming.payment.dto.PaymentApproveRespondDto
1212import goodspace.teaming.payment.dto.PaymentVerifyRespondDto
13+ import goodspace.teaming.payment.dto.toEntity
1314import goodspace.teaming.payment.repository.PaymentRepository
1415import org.springframework.context.ApplicationEventPublisher
1516import org.springframework.http.HttpHeaders
@@ -27,17 +28,35 @@ class PaymentService(
2728 private val paymentRepository : PaymentRepository ,
2829 private val userRoomRepository : UserRoomRepository
2930){
30- fun requestApprove (paymentVerifyRespondDto : PaymentVerifyRespondDto ): PaymentApproveRespondDto {
31+ @Transactional
32+ fun requestApprove (paymentVerifyRespondDto : PaymentVerifyRespondDto ): ResponseEntity <Void > {
3133 if (paymentVerifyRespondDto.authResultCode != " 0000" ){
3234 throw RuntimeException (" 카드사인증 인증 실패: ${paymentVerifyRespondDto.authResultCode} in requestApprove Service Layer" )
3335 }
3436
3537 val amount = paymentVerifyRespondDto.amount
36- val (userId, roomId) = paymentVerifyRespondDto.mallReserved.split(" :" )
37- return approvePayment(paymentVerifyRespondDto.tid, amount, userId, roomId)
38+ val (userId, roomId, platform) = paymentVerifyRespondDto.mallReserved.split(" :" )
39+
40+ val paymentApproveRespondDto = approvePayment(paymentVerifyRespondDto.tid, amount, userId, roomId, platform)
41+
42+ val redirectUrl = when {
43+ paymentApproveRespondDto.resultCode == " 0000" && platform == " APP" -> " teaming://payment/success"
44+ paymentApproveRespondDto.resultCode != " 0000" && platform == " APP" -> " teaming://payment/fail"
45+ paymentApproveRespondDto.resultCode == " 0000" && platform == " WEB" -> " https://teaming-three.vercel.app/payment/success"
46+ else -> " https://teaming-three.vercel.app/payment/fail"
47+ }
48+
49+ if (paymentApproveRespondDto.resultCode == " 0000" ) {
50+ savePaymentResult(paymentApproveRespondDto.toEntity())
51+ }
52+
53+ return ResponseEntity .status(HttpStatus .FOUND )
54+ .header(" Location" , redirectUrl)
55+ .build()
3856 }
3957
40- fun approvePayment (tid : String , amount : String , userId : String , roomId : String ): PaymentApproveRespondDto {
58+ @Transactional
59+ fun approvePayment (tid : String , amount : String , userId : String , roomId : String , platform : String ): PaymentApproveRespondDto {
4160 val url = " ${nicepayProperties.approveUrl} /$tid "
4261 val request = PaymentApproveRequestDto (
4362 amount = amount
@@ -57,6 +76,7 @@ class PaymentService(
5776 if (paymentApproveRespondDto.resultCode == " 0000" || paymentApproveRespondDto.resultCode == " 3001" ) {
5877 saveUserRoomInfo(userId, roomId)
5978 }
79+
6080 return paymentApproveRespondDto
6181 }
6282
0 commit comments