Compare commits

..

No commits in common. "1809862c166c018562746be060acdc4e51c531bd" and "300f784f7d5c4b837a3c75e15b82097f7519084b" have entirely different histories.

3 changed files with 29 additions and 10 deletions

View File

@ -61,4 +61,10 @@ class ChargeController(private val service: ChargeService) {
ApiResponse.ok(service.googleCharge(member, request))
}
@PostMapping("/google/verify")
fun googleVerify(
@RequestBody request: GoogleVerifyRequest,
@AuthenticationPrincipal user: User
) = ApiResponse.ok(service.googleVerify(user, request))
}

View File

@ -39,7 +39,7 @@ data class GoogleChargeRequest(
val chargeCan: Int,
val price: Double,
val currencyCode: String,
val productId: String,
val purchaseToken: String,
val paymentGateway: PaymentGateway
)
data class GoogleVerifyRequest(val productId: String, val purchaseToken: String, val chargeId: Long)

View File

@ -187,7 +187,7 @@ class ChargeService(
}
@Transactional
fun googleCharge(member: Member, request: GoogleChargeRequest) {
fun googleCharge(member: Member, request: GoogleChargeRequest): ChargeResponse {
val charge = Charge(request.chargeCan, 0)
charge.title = request.title
charge.member = member
@ -195,25 +195,38 @@ class ChargeService(
val payment = Payment(paymentGateway = request.paymentGateway)
payment.locale = request.currencyCode
payment.price = request.price
payment.receiptId = request.purchaseToken
payment.method = "구글(인 앱 결제)"
charge.payment = payment
chargeRepository.save(charge)
if (request.paymentGateway == PaymentGateway.GOOGLE_IAP) {
return ChargeResponse(chargeId = charge.id!!)
}
@Transactional
fun googleVerify(user: User, request: GoogleVerifyRequest) {
val charge = chargeRepository.findByIdOrNull(request.chargeId)
?: throw SodaException("결제정보에 오류가 있습니다.")
val member = memberRepository.findByEmail(user.username)
?: throw SodaException("로그인 정보를 확인해주세요.")
if (charge.payment!!.paymentGateway == PaymentGateway.GOOGLE_IAP) {
try {
androidPublisher.purchases().products()
.consume("kr.co.vividnext.sodalive", request.productId, request.purchaseToken)
.execute()
val response = androidPublisher.purchases().products()
.get("kr.co.vividnext.sodalive", request.productId, request.purchaseToken)
.execute() ?: throw SodaException("결제정보에 오류가 있습니다.")
if (
response.purchaseState == 0 &&
response.consumptionState == 1 &&
payment.status == PaymentStatus.REQUEST
charge.payment?.status == PaymentStatus.REQUEST
) {
payment.status = PaymentStatus.COMPLETE
member.charge(request.chargeCan, 0, "aos")
charge.payment?.receiptId = response.purchaseToken
charge.payment?.method = "구글(인 앱 결제)"
charge.payment?.status = PaymentStatus.COMPLETE
member.charge(charge.chargeCan, charge.rewardCan, "aos")
applicationEventPublisher.publishEvent(
ChargeSpringEvent(