- 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:
@@ -38,6 +38,25 @@ ALTER TABLE member ADD COLUMN IF NOT EXISTS profile_image MEDIUMTEXT NULL COMMEN
|
||||
-- 포인트(게시판 글/댓글 작성 보상). 기존 회원은 0 으로 시작 (멱등).
|
||||
ALTER TABLE member ADD COLUMN IF NOT EXISTS points BIGINT NOT NULL DEFAULT 0 COMMENT '활동 포인트' AFTER plan;
|
||||
|
||||
-- 멤버십 만료일 (유료 구독). NULL = 만료 없음(관리자 영구 부여) 또는 무료. 만료 지나면 스케줄러가 FREE 로 강등.
|
||||
ALTER TABLE member ADD COLUMN IF NOT EXISTS plan_expires_at DATETIME NULL COMMENT '유료 멤버십 만료일시' AFTER plan;
|
||||
|
||||
-- 인앱 결제 기록 (영수증 검증·중복 방지·감사)
|
||||
CREATE TABLE IF NOT EXISTS iap_purchase (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
member_id BIGINT NOT NULL,
|
||||
platform VARCHAR(20) NOT NULL COMMENT 'GOOGLE_PLAY / TEST',
|
||||
product_id VARCHAR(100) NOT NULL COMMENT '상품 ID(premium_monthly 등)',
|
||||
purchase_token VARCHAR(512) NOT NULL COMMENT 'Play 구매 토큰(또는 테스트 토큰)',
|
||||
order_id VARCHAR(120) NULL,
|
||||
status VARCHAR(20) NOT NULL COMMENT 'VERIFIED / FAILED',
|
||||
expires_at DATETIME NULL COMMENT '이 결제로 부여된 만료일',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_iap_token (purchase_token),
|
||||
KEY idx_iap_member (member_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 포인트 적립/차감 이력 (감사 + 일일 지급 한도 계산용).
|
||||
CREATE TABLE IF NOT EXISTS point_history (
|
||||
id BIGINT NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
UPDATE auth_session SET name = #{name} WHERE token = #{token}
|
||||
</update>
|
||||
|
||||
<update id="updatePlan">
|
||||
UPDATE auth_session SET plan = #{plan} WHERE token = #{token}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM auth_session WHERE token = #{token}
|
||||
</delete>
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.sb.web.billing.mapper.IapPurchaseMapper">
|
||||
|
||||
<resultMap id="iapResultMap" type="com.sb.web.billing.domain.IapPurchase">
|
||||
<id property="id" column="id"/>
|
||||
<result property="memberId" column="member_id"/>
|
||||
<result property="platform" column="platform"/>
|
||||
<result property="productId" column="product_id"/>
|
||||
<result property="purchaseToken" column="purchase_token"/>
|
||||
<result property="orderId" column="order_id"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="expiresAt" column="expires_at"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
</resultMap>
|
||||
|
||||
<insert id="insert" parameterType="com.sb.web.billing.domain.IapPurchase"
|
||||
useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO iap_purchase (member_id, platform, product_id, purchase_token, order_id, status, expires_at, created_at)
|
||||
VALUES (#{memberId}, #{platform}, #{productId}, #{purchaseToken}, #{orderId}, #{status}, #{expiresAt}, NOW())
|
||||
</insert>
|
||||
|
||||
<select id="findByToken" resultMap="iapResultMap">
|
||||
SELECT id, member_id, platform, product_id, purchase_token, order_id, status, expires_at, created_at
|
||||
FROM iap_purchase WHERE purchase_token = #{purchaseToken}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -16,6 +16,7 @@
|
||||
<result property="profileImage" column="profile_image"/>
|
||||
<result property="role" column="role"/>
|
||||
<result property="plan" column="plan"/>
|
||||
<result property="planExpiresAt" column="plan_expires_at"/>
|
||||
<result property="points" column="points"/>
|
||||
<result property="status" column="status"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
@@ -23,7 +24,7 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="columns">
|
||||
id, login_id, password, name, email, provider, provider_id, google_id, google_picture, profile_image, role, plan, points, status, created_at, updated_at
|
||||
id, login_id, password, name, email, provider, provider_id, google_id, google_picture, profile_image, role, plan, plan_expires_at, points, status, created_at, updated_at
|
||||
</sql>
|
||||
|
||||
<select id="findById" parameterType="long" resultMap="memberResultMap">
|
||||
@@ -96,8 +97,20 @@
|
||||
UPDATE member SET role = #{role}, updated_at = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 관리자 수동 변경: 만료일 없이(영구) 설정/해제 -->
|
||||
<update id="updatePlan">
|
||||
UPDATE member SET plan = #{plan}, updated_at = NOW() WHERE id = #{id}
|
||||
UPDATE member SET plan = #{plan}, plan_expires_at = NULL, updated_at = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 결제로 멤버십 부여/갱신: plan + 만료일 -->
|
||||
<update id="updateMembership">
|
||||
UPDATE member SET plan = #{plan}, plan_expires_at = #{expiresAt}, updated_at = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 만료된 유료회원 자동 강등 (스케줄러) -->
|
||||
<update id="downgradeExpired">
|
||||
UPDATE member SET plan = 'FREE', updated_at = NOW()
|
||||
WHERE plan = 'PREMIUM' AND plan_expires_at IS NOT NULL AND plan_expires_at < NOW()
|
||||
</update>
|
||||
|
||||
<update id="updateStatus">
|
||||
|
||||
Reference in New Issue
Block a user