Skip to content

Commit

Permalink
feat: 결제 환불 로직 리팩토링 (#245)
Browse files Browse the repository at this point in the history
* fix: 3:3 조인 시 성별 체크

* style: apply convention

* fix: 미팅팀 나이 제한

* style: apply convention

* feat: 카카오톡 ID 중복 시, 유저 ID 체크

* style: apply convention

* fix: 포트원 Access Token 생존 기간 60초로 수정

- try - catch 시 refreshToken 추가

* fix: 유저 정보 변경

- 학적 상태 졸업생, 대학원생으로 변경 시 학부 학번 삭제
- 전화번호 중복 예외 출력

* fix: 개발자 API 유저 삭제 시, 리프레시 토큰 초기화

* fix: MinAge MaxAge Null 값 거절

* feat: Match API 엔드포인트 경로 변경

- /matches/{matchId}/result -> /matches/result로 변경
- 요청 파라미터를 teamId에서 teamType으로 변경

* refactor: MatchService 파라미터 변경

- 파라미터 teamType으로 변경
- 캐시 키 형식 변경

* feat: teamType 사용 쿼리 메소드 추가

* chore: 사용하지 않는 메서드 제거

* chore: 불필요한 예외 처리 삭제

* docs: Swagger 업데이트

* refactor: getMatchedPartnerInformation API에서 불필요한 preference 정보 제거

- 책임 분리를 위해 새로운 DTO 생성
- ArrayList 변환 로직에서 preference 변환 제거

* feat: 매칭 API 시즌 파라미터 추가

* feat: 필수 파라미터 누락시 에러 처리 추가

* test: 테스트용 임시 이메일 전송 삭제

* feat: 매칭 안된 결제 정보 환불 로직 생성

---------

Co-authored-by: 23tae <[email protected]>
  • Loading branch information
seogwoojin and 23tae authored Dec 9, 2024
1 parent 296e7ba commit f43a277
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AdminService(
fun refundPayment(
requestInfo: RequestInfoDto
): PaymentResponseDto.NotMatchedPaymentRefundResponse {
val result = paymentService.refundPayment()
val result = paymentService.refundUnmatchedPayment()
logger.info("[ADMIN-매칭 실패 유저 환불] $requestInfo")
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface PaymentClient {
fun getAccessToken(
@RequestBody request: PortOneRequestDto.AccessTokenRequest
): PortOneResponseDto.AccessTokenResponse

@GetMapping("/payments/{impUid}", consumes = ["application/json"])
fun checkPayment(
@RequestHeader("Authorization") accessToken: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface PaymentService {
userId: Long,
teamType: TeamType
): PaymentResponseDto.PaymentRefundResponse
fun refundPayment(): PaymentResponseDto.NotMatchedPaymentRefundResponse
fun refundUnmatchedPayment(): PaymentResponseDto.NotMatchedPaymentRefundResponse
fun verifyPayment(userId: Long, teamType: TeamType): PaymentResponseDto.PaymentRequestResponse
fun deleteUserPayment(user: User)
fun synchronizePayment(paymentWebhookResponse: PaymentResponseDto.PaymentWebhookResponse)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.springframework.beans.factory.annotation.Value
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import uoslife.servermeeting.global.auth.exception.ExternalApiFailedException
import uoslife.servermeeting.meetingteam.dao.MeetingTeamDao
import uoslife.servermeeting.match.dao.MatchedDao
import uoslife.servermeeting.meetingteam.dao.UserTeamDao
import uoslife.servermeeting.meetingteam.entity.MeetingTeam
import uoslife.servermeeting.meetingteam.entity.UserTeam
Expand All @@ -24,23 +24,22 @@ import uoslife.servermeeting.payment.entity.enums.PaymentStatus
import uoslife.servermeeting.payment.exception.*
import uoslife.servermeeting.payment.repository.PaymentRepository
import uoslife.servermeeting.payment.service.PaymentService
import uoslife.servermeeting.user.dao.UserDao
import uoslife.servermeeting.user.entity.User
import uoslife.servermeeting.user.entity.enums.GenderType
import uoslife.servermeeting.user.exception.UserNotFoundException
import uoslife.servermeeting.user.repository.UserRepository

@Service
@Qualifier("PortOneService")
class PortOneService(
private val userRepository: UserRepository,
private val userDao: UserDao,
private val userTeamDao: UserTeamDao,
private val paymentDao: PaymentDao,
private val meetingTeamDao: MeetingTeamDao,
private val paymentRepository: PaymentRepository,
private val validator: Validator,
private val userTeamRepository: UserTeamRepository,
private val portOneAPIService: PortOneAPIService,
private val matchedDao: MatchedDao,
@Value("\${portone.api.price.single}") private val singlePrice: Int,
@Value("\${portone.api.price.triple}") private val triplePrice: Int,
) : PaymentService {
Expand Down Expand Up @@ -284,27 +283,46 @@ class PortOneService(
}

@Transactional
override fun refundPayment(): PaymentResponseDto.NotMatchedPaymentRefundResponse {
val userList =
meetingTeamDao
.findUserIdWithMaleMeetingTeam()
.plus(meetingTeamDao.findUserIdWithFeMaleMeetingTeam())
val paymentList = userDao.findNotMatchedPayment(userList)
logger.info("Total payment count: " + paymentList.size)
override fun refundUnmatchedPayment(): PaymentResponseDto.NotMatchedPaymentRefundResponse {
val successPayments = paymentRepository.findByStatus(PaymentStatus.SUCCESS)

val unMatchedPayments = mutableListOf<Payment>()
successPayments.forEach { payment ->
if (!isMatchedPayment(payment)) {
unMatchedPayments.add(payment)
}
}
logger.info("Total unmatched payment count: " + unMatchedPayments.size)

val refundFailedList: MutableList<String> = mutableListOf()
paymentList.forEach { payment ->
unMatchedPayments.forEach { payment ->
try {
portOneAPIService.refundPayment(payment.impUid, payment.price)
updatePaymentStatus(payment, PaymentStatus.REFUND, payment.impUid!!)
val refundPayment = portOneAPIService.refundPayment(payment.impUid, payment.price)
if (refundPayment.code == 0) {
updatePaymentStatus(payment, PaymentStatus.REFUND, payment.impUid!!)
} else {
updatePaymentStatus(payment, PaymentStatus.REFUND_FAILED, payment.impUid!!)
refundFailedList.add(payment.impUid.toString())
}
} catch (e: ExternalApiFailedException) {
logger.info(
"[환불 실패] payment_id: ${payment.id}, impUid: ${payment.impUid}, marchantUid: ${payment.merchantUid}"
)
refundFailedList.add(payment.id.toString())
payment.status = PaymentStatus.REFUND_FAILED
updatePaymentStatus(payment, PaymentStatus.REFUND_FAILED, payment.impUid!!)
refundFailedList.add(payment.impUid.toString())
}
}
return PaymentResponseDto.NotMatchedPaymentRefundResponse(refundFailedList)
}

private fun isMatchedPayment(payment: Payment): Boolean {
val meetingTeam = payment.meetingTeam ?: throw MeetingTeamNotFoundException()
val matched =
when (meetingTeam.gender) {
GenderType.MALE -> {
matchedDao.findMatchByMaleTeamWithFemaleTeam(meetingTeam)
}
GenderType.FEMALE -> {
matchedDao.findMatchByFeMaleTeamWithMaleTeam(meetingTeam)
}
}
return matched != null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ class AsyncEmailService(
.withBody(Body().withHtml(Content(emailBody)))
)
.withSource(emailFrom)
sesClient.sendEmail(request)
// sesClient.sendEmail(request)
}
}

0 comments on commit f43a277

Please sign in to comment.