Merge pull request '구글 인 앱 결제 검증 코드 수정' (#143) from test into main
Reviewed-on: #143
This commit is contained in:
		| @@ -1,7 +1,12 @@ | |||||||
| package kr.co.vividnext.sodalive.can.charge | package kr.co.vividnext.sodalive.can.charge | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper | import com.fasterxml.jackson.databind.ObjectMapper | ||||||
|  | import com.google.api.client.http.javanet.NetHttpTransport | ||||||
|  | import com.google.api.client.json.gson.GsonFactory | ||||||
| import com.google.api.services.androidpublisher.AndroidPublisher | import com.google.api.services.androidpublisher.AndroidPublisher | ||||||
|  | import com.google.api.services.androidpublisher.AndroidPublisherScopes | ||||||
|  | import com.google.auth.http.HttpCredentialsAdapter | ||||||
|  | import com.google.auth.oauth2.GoogleCredentials | ||||||
| import kr.co.bootpay.Bootpay | import kr.co.bootpay.Bootpay | ||||||
| import kr.co.vividnext.sodalive.can.CanRepository | import kr.co.vividnext.sodalive.can.CanRepository | ||||||
| import kr.co.vividnext.sodalive.can.charge.event.ChargeSpringEvent | import kr.co.vividnext.sodalive.can.charge.event.ChargeSpringEvent | ||||||
| @@ -24,6 +29,7 @@ import org.springframework.http.HttpHeaders | |||||||
| import org.springframework.security.core.userdetails.User | import org.springframework.security.core.userdetails.User | ||||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||||
| import org.springframework.transaction.annotation.Transactional | import org.springframework.transaction.annotation.Transactional | ||||||
|  | import java.io.FileInputStream | ||||||
|  |  | ||||||
| @Service | @Service | ||||||
| @Transactional(readOnly = true) | @Transactional(readOnly = true) | ||||||
| @@ -37,8 +43,6 @@ class ChargeService( | |||||||
|     private val okHttpClient: OkHttpClient, |     private val okHttpClient: OkHttpClient, | ||||||
|     private val applicationEventPublisher: ApplicationEventPublisher, |     private val applicationEventPublisher: ApplicationEventPublisher, | ||||||
|  |  | ||||||
|     private val androidPublisher: AndroidPublisher, |  | ||||||
|  |  | ||||||
|     @Value("\${bootpay.application-id}") |     @Value("\${bootpay.application-id}") | ||||||
|     private val bootpayApplicationId: String, |     private val bootpayApplicationId: String, | ||||||
|     @Value("\${bootpay.private-key}") |     @Value("\${bootpay.private-key}") | ||||||
| @@ -46,7 +50,9 @@ class ChargeService( | |||||||
|     @Value("\${apple.iap-verify-sandbox-url}") |     @Value("\${apple.iap-verify-sandbox-url}") | ||||||
|     private val appleInAppVerifySandBoxUrl: String, |     private val appleInAppVerifySandBoxUrl: String, | ||||||
|     @Value("\${apple.iap-verify-url}") |     @Value("\${apple.iap-verify-url}") | ||||||
|     private val appleInAppVerifyUrl: String |     private val appleInAppVerifyUrl: String, | ||||||
|  |     @Value("\${firebase.secret-key-path}") | ||||||
|  |     private val secretKeyPath: String | ||||||
| ) { | ) { | ||||||
|  |  | ||||||
|     @Transactional |     @Transactional | ||||||
| @@ -209,11 +215,11 @@ class ChargeService( | |||||||
|             ?: throw SodaException("로그인 정보를 확인해주세요.") |             ?: throw SodaException("로그인 정보를 확인해주세요.") | ||||||
|  |  | ||||||
|         if (charge.payment!!.paymentGateway == PaymentGateway.GOOGLE_IAP) { |         if (charge.payment!!.paymentGateway == PaymentGateway.GOOGLE_IAP) { | ||||||
|             val response = androidPublisher.purchases().products() |             val response = getAndroidPublisher().purchases().products() | ||||||
|                 .get("kr.co.vividnext.sodalive", request.productId, request.purchaseToken) |                 .get("kr.co.vividnext.sodalive", request.productId, request.purchaseToken) | ||||||
|                 .execute() |                 .execute() ?: throw SodaException("결제정보에 오류가 있습니다.") | ||||||
|  |  | ||||||
|             if (response.purchaseState == 0) { |             if (response.purchaseState == 0 && charge.payment?.status == PaymentStatus.REQUEST) { | ||||||
|                 charge.payment?.receiptId = response.purchaseToken |                 charge.payment?.receiptId = response.purchaseToken | ||||||
|                 charge.payment?.method = "구글(인 앱 결제)" |                 charge.payment?.method = "구글(인 앱 결제)" | ||||||
|                 charge.payment?.status = PaymentStatus.COMPLETE |                 charge.payment?.status = PaymentStatus.COMPLETE | ||||||
| @@ -298,4 +304,16 @@ class ChargeService( | |||||||
|             throw SodaException("결제를 완료하지 못했습니다.") |             throw SodaException("결제를 완료하지 못했습니다.") | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     private fun getAndroidPublisher(): AndroidPublisher { | ||||||
|  |         val jsonFactory = GsonFactory.getDefaultInstance() | ||||||
|  |         val httpTransport = NetHttpTransport() | ||||||
|  |  | ||||||
|  |         val credential = GoogleCredentials.fromStream(FileInputStream(secretKeyPath)) | ||||||
|  |             .createScoped(listOf(AndroidPublisherScopes.ANDROIDPUBLISHER)) | ||||||
|  |  | ||||||
|  |         return AndroidPublisher.Builder(httpTransport, jsonFactory, HttpCredentialsAdapter(credential)) | ||||||
|  |             .setApplicationName("소다라이브") | ||||||
|  |             .build() | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user