@@ -30,38 +30,38 @@ public class AdMobRewardServiceImpl implements AdMobRewardService {
3030 @ Override
3131 @ Transactional
3232 public String processReward (AdMobRewardRequest request ) {
33- // // 1. 서명 검증
34- // if (!verifyAdMobSignature(request)) {
35- // log.warn("AdMob 서명 검증 실패: transaction_id={}", request.transaction_id());
36- // throw new CustomException(ErrorCode.REWARD_INVALID_SIGNATURE);
37- // }
38- //
33+ // 1. 서명 검증
34+ if (!verifyAdMobSignature (request )) {
35+ log .warn ("AdMob 서명 검증 실패: transaction_id={}" , request .transaction_id ());
36+ throw new CustomException (ErrorCode .REWARD_INVALID_SIGNATURE );
37+ }
38+
3939 // 2. 중복 처리 방지
4040 // 만약 여기서 true가 안 나온다면, DB에 transaction_id가 아직 안 쌓인 상태입니다.
4141 if (adRewardHistoryRepository .existsByTransactionId (request .transaction_id ())) {
4242 log .info ("이미 처리된 광고 요청입니다: transaction_id={}" , request .transaction_id ());
4343 return "Already Processed" ;
4444 }
45- //
46- // // 3. 유저 확인
47- // User user = userRepository.findById(request.getUserId())
48- // .orElseThrow(() -> new CustomException(ErrorCode.REWARD_INVALID_USER));
49- //
50- // // 4. 보상 이력(AdRewardHistory)을 먼저 저장
51- // // 이력을 먼저 남겨야 다음 요청이 들어왔을 때 위 2번 로직에서 걸러집니다.
52- // AdRewardHistory history = AdRewardHistory.builder()
53- // .transactionId(request.transaction_id())
54- // .user(user)
55- // .rewardAmount(request.reward_amount())
56- // .rewardItem(request.getRewardType())
57- // .build();
58- // adRewardHistoryRepository.save(history);
59- //
60- // // 5. 크레딧 적립
61- // Long refId = parseTransactionId(request.transaction_id());
62- // creditService.addCredit(user.getId(), CreditType.AD_REWARD, refId);
63- //
64- // log.info("보상 지급 완료: user={}, amount={}", user.getId(), request.reward_amount());
45+
46+ // 3. 유저 확인
47+ User user = userRepository .findById (request .getUserId ())
48+ .orElseThrow (() -> new CustomException (ErrorCode .REWARD_INVALID_USER ));
49+
50+ // 4. 보상 이력(AdRewardHistory)을 먼저 저장
51+ // 이력을 먼저 남겨야 다음 요청이 들어왔을 때 위 2번 로직에서 걸러집니다.
52+ AdRewardHistory history = AdRewardHistory .builder ()
53+ .transactionId (request .transaction_id ())
54+ .user (user )
55+ .rewardAmount (request .reward_amount ())
56+ .rewardItem (request .getRewardType ())
57+ .build ();
58+ adRewardHistoryRepository .save (history );
59+
60+ // 5. 크레딧 적립
61+ Long refId = parseTransactionId (request .transaction_id ());
62+ creditService .addCredit (user .getId (), CreditType .AD_REWARD , refId );
63+
64+ log .info ("보상 지급 완료: user={}, amount={}" , user .getId (), request .reward_amount ());
6565 return "OK" ;
6666 }
6767
0 commit comments