feat: 인앱 결제(Google Play) 스캐폴드 + 멤버십 만료 처리
- member.plan_expires_at + iap_purchase 테이블(중복 결제 방지) - POST /api/billing/google/verify: 구매 검증 후 PREMIUM 부여/갱신(만료 연장), 세션 plan 즉시 동기화 - GET /api/billing/products: 구독 상품(월간/연간) - 테스트 모드(billing.test-mode=true): test- 토큰 검증 없이 승인 → 전 과정 테스트 가능 - GooglePlayVerifier 인터페이스 + 스텁(실연동 지점), 실연동 시 구현체 교체 - 관리자 수동 plan 변경은 만료일 없이(영구), 결제는 만료일 부여 - 만료 자동 강등 스케줄러(매시), MemberResponse.planExpiresAt 노출 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
d1c13e7cc1
commit
1e93280140
@@ -30,6 +30,7 @@ public class Member implements Serializable {
|
||||
private String profileImage; // 사용자 지정 프로필 이미지(data URL). 우선순위: profileImage > googlePicture > 이니셜
|
||||
private String role; // USER / ADMIN
|
||||
private String plan; // FREE / PREMIUM (멤버십)
|
||||
private LocalDateTime planExpiresAt; // 유료 멤버십 만료일 (NULL=만료없음/무료)
|
||||
private Long points; // 활동 포인트 (게시판 글/댓글 작성 보상)
|
||||
private String status; // ACTIVE / SUSPENDED / WITHDRAWN
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@@ -18,6 +18,7 @@ public class MemberResponse {
|
||||
private String provider;
|
||||
private String role;
|
||||
private String plan; // FREE / PREMIUM
|
||||
private java.time.LocalDateTime planExpiresAt; // 유료 멤버십 만료일
|
||||
private Long points; // 활동 포인트
|
||||
private String googlePicture; // 구글 아바타 URL
|
||||
private String profileImage; // 사용자 지정 프로필 이미지(data URL)
|
||||
@@ -31,6 +32,7 @@ public class MemberResponse {
|
||||
.provider(m.getProvider())
|
||||
.role(m.getRole())
|
||||
.plan(m.getPlan())
|
||||
.planExpiresAt(m.getPlanExpiresAt())
|
||||
.points(m.getPoints())
|
||||
.googlePicture(m.getGooglePicture())
|
||||
.profileImage(m.getProfileImage())
|
||||
|
||||
@@ -21,6 +21,9 @@ public interface AuthSessionMapper {
|
||||
/** 프로필 변경 시 백업 세션의 표시 이름 동기화 */
|
||||
int updateName(@Param("token") String token, @Param("name") String name);
|
||||
|
||||
/** 멤버십 변경 시 백업 세션의 plan 동기화 */
|
||||
int updatePlan(@Param("token") String token, @Param("plan") String plan);
|
||||
|
||||
int delete(@Param("token") String token);
|
||||
|
||||
int deleteExpired(@Param("now") LocalDateTime now);
|
||||
|
||||
@@ -50,6 +50,13 @@ public interface MemberMapper {
|
||||
|
||||
int updatePlan(@Param("id") Long id, @Param("plan") String plan);
|
||||
|
||||
/** 결제로 멤버십 부여/갱신 (plan + 만료일) */
|
||||
int updateMembership(@Param("id") Long id, @Param("plan") String plan,
|
||||
@Param("expiresAt") java.time.LocalDateTime expiresAt);
|
||||
|
||||
/** 만료된 유료회원을 FREE 로 강등 (스케줄러). 강등된 건수 반환 */
|
||||
int downgradeExpired();
|
||||
|
||||
int updateStatus(@Param("id") Long id, @Param("status") String status);
|
||||
|
||||
int deleteById(@Param("id") Long id);
|
||||
|
||||
@@ -402,6 +402,32 @@ public class AuthService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 결제/멤버십 변경 시 활성 세션(Redis + DB 백업)의 plan 을 즉시 맞춘다 (재로그인 없이 유료 기능 개방). */
|
||||
public void syncSessionPlan(String token, String plan) {
|
||||
if (token == null || token.isBlank()) {
|
||||
return;
|
||||
}
|
||||
String key = SESSION_PREFIX + token;
|
||||
try {
|
||||
Object cached = redisTemplate.opsForValue().get(key);
|
||||
if (cached instanceof SessionUser u) {
|
||||
u.setPlan(plan);
|
||||
Long ttl = redisTemplate.getExpire(key, java.util.concurrent.TimeUnit.SECONDS);
|
||||
Duration remain = (ttl != null && ttl > 0)
|
||||
? Duration.ofSeconds(ttl)
|
||||
: (u.isRememberMe() ? REMEMBER_TTL : SESSION_TTL);
|
||||
redisTemplate.opsForValue().set(key, u, remain);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("[billing] Redis 세션 plan 동기화 실패(무시): {}", e.toString());
|
||||
}
|
||||
try {
|
||||
authSessionMapper.updatePlan(token, plan);
|
||||
} catch (Exception ignore) {
|
||||
// DB 백업 동기화 실패해도 다음 로그인 시 갱신됨
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 비밀번호 변경 (본인). 현재 비밀번호 검증 후 새 비밀번호로 교체.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user