Skip to content

Commit 53272cd

Browse files
authored
Merge pull request GoodSpace-Kr#138 from borntocode2/main
[modify] payment logic
2 parents 187e3a0 + 0db38a5 commit 53272cd

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/main/kotlin/goodspace/teaming/payment/controller/PaymentController.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ class PaymentController(
2020
) {
2121

2222
@GetMapping(value = ["/html"], produces = [MediaType.TEXT_HTML_VALUE])
23-
fun showPaymentPage(@RequestParam amount: Long, principal: Principal, @RequestParam roomId: Long
23+
fun showPaymentPage(@RequestParam amount: Long, principal: Principal, @RequestParam roomId: Long, @RequestParam platform: String
2424
): String {
2525
val userId = principal.getUserId()
26-
val userPayInfo = "$userId:$roomId"
26+
val userPayInfo = "$userId:$roomId:$platform"
2727

2828
return """<!DOCTYPE html>
2929
<html lang="en">
@@ -57,7 +57,7 @@ class PaymentController(
5757
}
5858

5959
@PostMapping("/request")
60-
fun requestPayment(@RequestParam params: MultiValueMap<String, String>): ResponseEntity<HttpStatus> {
60+
fun requestPayment(@RequestParam params: MultiValueMap<String, String>): ResponseEntity<Void> {
6161
val dto = PaymentVerifyRespondDto(
6262
authResultCode = params["authResultCode"]?.firstOrNull() ?: "",
6363
authResultMsg = params["authResultMsg"]?.firstOrNull() ?: "",
@@ -70,11 +70,6 @@ class PaymentController(
7070
signature = params["signature"]?.firstOrNull() ?: ""
7171
)
7272

73-
val paymentApproveRespondDto: PaymentApproveRespondDto = paymentService.requestApprove(dto)
74-
paymentService.savePaymentResult(paymentApproveRespondDto.toEntity())
75-
76-
77-
78-
return paymentService.mapResultCodeToHttpStatus(paymentApproveRespondDto.resultCode)
73+
return paymentService.requestApprove(dto)
7974
}
8075
}

src/main/kotlin/goodspace/teaming/payment/service/PaymentService.kt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import goodspace.teaming.payment.domain.PaymentApproveRespond
1010
import goodspace.teaming.payment.dto.PaymentApproveRequestDto
1111
import goodspace.teaming.payment.dto.PaymentApproveRespondDto
1212
import goodspace.teaming.payment.dto.PaymentVerifyRespondDto
13+
import goodspace.teaming.payment.dto.toEntity
1314
import goodspace.teaming.payment.repository.PaymentRepository
1415
import org.springframework.context.ApplicationEventPublisher
1516
import 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

Comments
 (0)