| @@ -1,23 +0,0 @@ | ||||
| package kr.co.vividnext.sodalive.can.charge.free | ||||
|  | ||||
| import kr.co.vividnext.sodalive.common.BaseEntity | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import javax.persistence.Entity | ||||
| import javax.persistence.FetchType | ||||
| import javax.persistence.JoinColumn | ||||
| import javax.persistence.ManyToOne | ||||
|  | ||||
| @Entity | ||||
| data class AdsCharge( | ||||
|     val transactionKey: String, | ||||
|     val adKey: String, | ||||
|     val adName: String, | ||||
|     val adProfit: Float, | ||||
|     val adCurrency: String, | ||||
|     val point: Float, | ||||
|     val deviceIfa: String | ||||
| ) : BaseEntity() { | ||||
|     @ManyToOne(fetch = FetchType.LAZY) | ||||
|     @JoinColumn(name = "member_id", nullable = false) | ||||
|     var member: Member? = null | ||||
| } | ||||
| @@ -1,35 +0,0 @@ | ||||
| package kr.co.vividnext.sodalive.can.charge.free | ||||
|  | ||||
| import org.springframework.web.bind.annotation.GetMapping | ||||
| import org.springframework.web.bind.annotation.RequestMapping | ||||
| import org.springframework.web.bind.annotation.RequestParam | ||||
| import org.springframework.web.bind.annotation.RestController | ||||
|  | ||||
| @RestController | ||||
| @RequestMapping("/charge/ads") | ||||
| class AdsChargeController(private val service: AdsChargeService) { | ||||
|     @GetMapping | ||||
|     fun adsCharge( | ||||
|         @RequestParam("transaction_key") transactionKey: String, | ||||
|         @RequestParam("placement_uid") placementUid: String, | ||||
|         @RequestParam("ad_key") adKey: String, | ||||
|         @RequestParam("ad_name") adName: String, | ||||
|         @RequestParam("ad_profit") adProfit: String, | ||||
|         @RequestParam("ad_currency") adCurrency: String, | ||||
|         @RequestParam("point") point: String, | ||||
|         @RequestParam("device_ifa") deviceIfa: String, | ||||
|         @RequestParam("picker_uid") memberId: String | ||||
|     ) { | ||||
|         service.adsCharge( | ||||
|             transactionKey, | ||||
|             placementUid, | ||||
|             adKey, | ||||
|             adName, | ||||
|             adProfit, | ||||
|             adCurrency, | ||||
|             point, | ||||
|             deviceIfa, | ||||
|             memberId | ||||
|         ) | ||||
|     } | ||||
| } | ||||
| @@ -1,7 +0,0 @@ | ||||
| package kr.co.vividnext.sodalive.can.charge.free | ||||
|  | ||||
| import org.springframework.data.jpa.repository.JpaRepository | ||||
| import org.springframework.stereotype.Repository | ||||
|  | ||||
| @Repository | ||||
| interface AdsChargeRepository : JpaRepository<AdsCharge, Long> | ||||
| @@ -1,85 +0,0 @@ | ||||
| package kr.co.vividnext.sodalive.can.charge.free | ||||
|  | ||||
| import kr.co.vividnext.sodalive.can.charge.Charge | ||||
| import kr.co.vividnext.sodalive.can.charge.ChargeRepository | ||||
| import kr.co.vividnext.sodalive.can.charge.ChargeStatus | ||||
| import kr.co.vividnext.sodalive.can.payment.Payment | ||||
| import kr.co.vividnext.sodalive.can.payment.PaymentGateway | ||||
| import kr.co.vividnext.sodalive.can.payment.PaymentStatus | ||||
| import kr.co.vividnext.sodalive.common.AdsChargeException | ||||
| import kr.co.vividnext.sodalive.fcm.FcmEvent | ||||
| import kr.co.vividnext.sodalive.fcm.FcmEventType | ||||
| import kr.co.vividnext.sodalive.member.MemberRepository | ||||
| import org.springframework.beans.factory.annotation.Value | ||||
| import org.springframework.context.ApplicationEventPublisher | ||||
| import org.springframework.data.repository.findByIdOrNull | ||||
| import org.springframework.stereotype.Service | ||||
| import org.springframework.transaction.annotation.Transactional | ||||
|  | ||||
| @Service | ||||
| class AdsChargeService( | ||||
|     private val repository: AdsChargeRepository, | ||||
|     private val memberRepository: MemberRepository, | ||||
|     private val chargeRepository: ChargeRepository, | ||||
|     private val applicationEventPublisher: ApplicationEventPublisher, | ||||
|  | ||||
|     @Value("\${point-click.placement-uid}") | ||||
|     private val placementUid: String | ||||
| ) { | ||||
|     @Transactional | ||||
|     fun adsCharge( | ||||
|         transactionKey: String, | ||||
|         placementUid: String, | ||||
|         adKey: String, | ||||
|         adName: String, | ||||
|         adProfit: String, | ||||
|         adCurrency: String, | ||||
|         point: String, | ||||
|         deviceIfa: String, | ||||
|         memberId: String | ||||
|     ) { | ||||
|         if (placementUid != this.placementUid) { | ||||
|             throw AdsChargeException("잘못된 요청입니다.") | ||||
|         } | ||||
|  | ||||
|         val member = memberRepository.findByIdOrNull(id = memberId.toLong()) | ||||
|             ?: throw AdsChargeException("잘못된 요청입니다.") | ||||
|  | ||||
|         val adsCharge = AdsCharge( | ||||
|             transactionKey = transactionKey, | ||||
|             adKey = adKey, | ||||
|             adName = adName, | ||||
|             adProfit = adProfit.toFloat(), | ||||
|             adCurrency = adCurrency, | ||||
|             point = point.toFloat(), | ||||
|             deviceIfa = deviceIfa | ||||
|         ) | ||||
|         adsCharge.member = member | ||||
|         repository.save(adsCharge) | ||||
|  | ||||
|         val charge = Charge(0, rewardCan = adsCharge.point.toInt(), status = ChargeStatus.ADS) | ||||
|         charge.title = "${adsCharge.point.toInt()} 캔" | ||||
|         charge.member = member | ||||
|  | ||||
|         val payment = Payment( | ||||
|             status = PaymentStatus.COMPLETE, | ||||
|             paymentGateway = PaymentGateway.POINT_CLICK_AD | ||||
|         ) | ||||
|  | ||||
|         payment.method = "제휴보상" | ||||
|         charge.payment = payment | ||||
|         chargeRepository.save(charge) | ||||
|  | ||||
|         member.charge(0, adsCharge.point.toInt(), "ads") | ||||
|  | ||||
|         applicationEventPublisher.publishEvent( | ||||
|             FcmEvent( | ||||
|                 type = FcmEventType.INDIVIDUAL, | ||||
|                 title = "제휴보상", | ||||
|                 message = "${adsCharge.point.toInt()} 캔이 지급되었습니다.", | ||||
|                 recipients = listOf(member.id!!), | ||||
|                 isAuth = null | ||||
|             ) | ||||
|         ) | ||||
|     } | ||||
| } | ||||
| @@ -12,6 +12,7 @@ data class GetRoomListResponse( | ||||
|     val price: Int, | ||||
|     val tags: List<String>, | ||||
|     val channelName: String?, | ||||
|     val creatorProfileImage: String, | ||||
|     val creatorNickname: String, | ||||
|     val creatorId: Long, | ||||
|     val isReservation: Boolean, | ||||
|   | ||||
| @@ -146,6 +146,11 @@ class LiveRoomService( | ||||
|                     isAdult = it.isAdult, | ||||
|                     price = it.price, | ||||
|                     channelName = it.channelName, | ||||
|                     creatorProfileImage = if (it.member!!.profileImage != null) { | ||||
|                         "$cloudFrontHost/${it.member!!.profileImage}" | ||||
|                     } else { | ||||
|                         "$cloudFrontHost/profile/default-profile.png" | ||||
|                     }, | ||||
|                     creatorNickname = it.member!!.nickname, | ||||
|                     creatorId = it.member!!.id!!, | ||||
|                     tags = it.tags | ||||
|   | ||||
| @@ -20,9 +20,6 @@ agora: | ||||
|     appId: ${AGORA_APP_ID} | ||||
|     appCertificate: ${AGORA_APP_CERTIFICATE} | ||||
|  | ||||
| pointClick: | ||||
|     placementUid: fc07cfb1-ef16-455c-bdad-22aa9e8fd78c | ||||
|  | ||||
| firebase: | ||||
|     secretKeyPath: ${GOOGLE_APPLICATION_CREDENTIALS} | ||||
|  | ||||
| @@ -92,6 +89,3 @@ spring: | ||||
|             hibernate: | ||||
|                 show_sql: true | ||||
|                 format_sql: true | ||||
|  | ||||
| pointClick: | ||||
|     placementUid: test | ||||
|   | ||||
| @@ -13,9 +13,6 @@ agora: | ||||
|     appId: ${AGORA_APP_ID} | ||||
|     appCertificate: ${AGORA_APP_CERTIFICATE} | ||||
|  | ||||
| pointClick: | ||||
|     placementUid: test | ||||
|  | ||||
| cloud: | ||||
|     aws: | ||||
|         credentials: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user