skills/payment-module/SKILL.md
구독 결제 모듈을 자동으로 구축합니다. 레퍼런스 설계 문서를 기반으로 블루프린트 작성, 스프린트 생성, 구현, 테스트 시나리오 작성, 테스트 실행 및 디버깅까지 전체 파이프라인을 자동 실행합니다. 플랜 관리, 결제 수단(빌링키), 구독 관리, 청구서/결제, PG사 연동(토스페이먼츠/KCP), 웹훅, 정기결제 스케줄러, Dunning(재시도), 크레딧 관리, 비례 배분(Proration) 기능을 포함합니다.
npx skillsauth add astra-technology-company-limited/astra-methodology payment-moduleInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
레퍼런스 설계 문서($CLAUDE_PLUGIN_ROOT/docs/payment/system-design.md)를 기반으로 대상 프로젝트에 구독 결제 모듈 전체를 자동 구축합니다.
자동 구축 범위:
$CLAUDE_PLUGIN_ROOT/docs/payment/system-design.md 파일을 읽어 레퍼런스 설계 정보를 로드한다:
중요: 레퍼런스는 **AMA 프로젝트(Next.js 14 + PostgreSQL + Drizzle ORM + 토스페이먼츠)**를 기준으로 작성되었다. 대상 프로젝트의 기술 스택에 맞게 **적응(adapt)**해야 한다.
$ARGUMENTS에서 대상 프로젝트 경로를 파싱한다. 인자가 없으면 현재 작업 디렉토리를 사용한다.
대상 프로젝트에서 다음을 분석한다:
CLAUDE.md 읽기 — 기술 스택, 프로젝트 구조, 컨벤션 확인package.json 또는 build.gradle 또는 pom.xml 또는 pyproject.toml 읽기 — 프레임워크/의존성 파악docs/blueprints/ 스캔 — 기존 블루프린트 번호 확인 (다음 번호 결정)docs/database/database-design.md 읽기 — 기존 DB 스키마 확인 (특히 인증/워크스페이스 모듈 테이블)docs/sprints/ 스캔 — sprint-{N}-{name}/ 패턴 디렉토리에서 현재 스프린트 번호 확인src/ 스캔 — 기존 코드 구조, 라우팅 패턴, 인증/워크스페이스 모듈 코드 확인src/styles/design-tokens.css + docs/design-system/ 스캔 — 디자인 토큰, 컴포넌트 패턴 확인결제 모듈은 인증 모듈과 워크스페이스 모듈에 의존한다. 다음을 확인한다:
인증 모듈 (필수):
워크스페이스 모듈 (필수):
선행 모듈이 없는 경우 AskUserQuestion으로 사용자에게 알린다:
## 선행 모듈 의존성 확인
결제 모듈은 인증 모듈(TB_COMM_USER, JWT)과 워크스페이스 모듈(TB_COMM_WKSPC, TR_COMM_WKSPC_MBR)에 의존합니다.
감지 결과:
- 인증 모듈: {감지됨/미감지}
- 워크스페이스 모듈: {감지됨/미감지}
다음 중 선택해 주세요:
1. 미감지된 모듈을 먼저 구축 (/auth-module, /workspace-module 순서대로 실행)
2. 기존 인증/워크스페이스 시스템이 있으며 경로를 알려주겠음
3. 선행 모듈 없이 결제 모듈만 구축 (사용자/워크스페이스 테이블 직접 생성)
대상 프로젝트의 기술 스택에 따라 레퍼런스 설계를 적응한다:
| 레퍼런스 (AMA) | 대상 프로젝트 | 적응 방법 |
|---------------|------------|----------|
| Next.js 14 API Routes | Spring Boot | @RestController + @RequestMapping |
| Next.js 14 API Routes | NestJS | @Controller + @Get/@Post |
| Next.js 14 API Routes | FastAPI | @router.get/@router.post |
| Next.js 14 API Routes | Next.js | 그대로 사용 |
| Drizzle ORM | JPA/Hibernate | @Entity + @Table + @Column |
| Drizzle ORM | TypeORM | @Entity + @Column |
| Drizzle ORM | Prisma | schema.prisma 모델 |
| Drizzle ORM | SQLAlchemy | Base + Column |
| 토스페이먼츠 SDK | Stripe | stripe 라이브러리, Stripe Billing API |
| 토스페이먼츠 SDK | 자체 PG 연동 | PG 추상화 인터페이스에 맞춰 어댑터 구현 |
| node-cron | Spring Scheduler | @Scheduled 어노테이션 |
| node-cron | APScheduler (Python) | BackgroundScheduler |
| crypto-js (AES) | Java | javax.crypto.Cipher AES/GCM |
| crypto-js (AES) | Python | cryptography.fernet |
| React (TSX) | React (TSX) | 그대로 사용 |
| React (TSX) | Vue 3 | Composition API + <script setup> |
| React (TSX) | Angular | Component + Service + Guard |
| React (TSX) | React Native | RN 컴포넌트 + AsyncStorage |
| Zod (검증) | class-validator (Java/TS) | @IsNotEmpty, @IsNumber 등 |
| Zod (검증) | Pydantic (Python) | BaseModel + Field |
적응이 필요한 경우 AskUserQuestion으로 사용자에게 확인한다:
## 결제 모듈 기술 스택 확인
레퍼런스: Next.js 14 + PostgreSQL + Drizzle ORM + 토스페이먼츠
대상 프로젝트: {detected-tech-stack}
다음 사항을 확인해 주세요:
1. PG사: 토스페이먼츠 / Stripe / NHN KCP / 나이스페이 / 기타 ({detected})
2. ORM: {detected}
3. 암호화 라이브러리: {detected or recommended}
4. 프론트엔드 프레임워크: {detected}
5. 스케줄러: {detected or recommended}
추가 요구사항이 있으면 알려주세요 (예: PG사 추가, 통화 변경, 크레딧 미사용 등).
레퍼런스 설계 문서에서 추출한 결제 모듈 기능 목록:
| # | 그룹 | 기능 | API 엔드포인트 | 화면 |
|---|------|------|--------------|------|
| 1 | 플랜 | 플랜 목록 조회 | GET /billing/plans | /pricing |
| 2 | 플랜 | 플랜 상세 조회 | GET /billing/plans/[id] | - |
| 3 | 플랜 | 플랜 생성 | POST /billing/plans | /admin/settings/plans |
| 4 | 플랜 | 플랜 수정 | PATCH /billing/plans/[id] | /admin/settings/plans/[id] |
| 5 | 결제 수단 | 결제 수단 목록 | GET /workspaces/[wsId]/billing/payment-methods | billing/payment-method |
| 6 | 결제 수단 | 결제 수단 등록 (빌링키) | POST /workspaces/[wsId]/billing/payment-methods | billing/payment-method |
| 7 | 결제 수단 | 기본 결제 수단 변경 | PATCH .../payment-methods/[id]/default | - |
| 8 | 결제 수단 | 결제 수단 삭제 | DELETE .../payment-methods/[id] | - |
| 9 | 구독 | 현재 구독 조회 | GET .../subscriptions/current | billing/subscription |
| 10 | 구독 | 구독 시작 | POST .../subscriptions | billing/subscription |
| 11 | 구독 | 플랜 변경 (비례 배분) | PATCH .../subscriptions/[id]/plan | 모달 |
| 12 | 구독 | 구독 해지 | POST .../subscriptions/[id]/cancel | 모달 |
| 13 | 구독 | 구독 일시정지 | POST .../subscriptions/[id]/pause | - |
| 14 | 구독 | 구독 재개 | POST .../subscriptions/[id]/resume | - |
| 15 | 구독 | 전체 구독 목록 (관리자) | GET /billing/subscriptions | /admin/settings/subscriptions |
| 16 | 청구서 | 청구서 목록 | GET .../invoices | billing/invoices |
| 17 | 청구서 | 청구서 상세 | GET .../invoices/[id] | billing/invoices/[id] |
| 18 | 청구서 | 수동 결제 | POST .../invoices/[id]/pay | - |
| 19 | 결제 | 환불 처리 (관리자) | POST /billing/payments/[id]/refund | - |
| 20 | 웹훅 | 토스페이먼츠 웹훅 | POST /billing/webhook/toss | - |
| 21 | 웹훅 | KCP 웹훅 | POST /billing/webhook/kcp | - |
| 22 | 크레딧 | 내 크레딧 조회 | GET .../credits/me | billing/subscription |
| 23 | 크레딧 | 크레딧 사용 내역 | GET .../credits/me/history | - |
| 24 | 크레딧 | 크레딧 확인 | GET .../credits/check | - |
| 25 | 크레딧 | 크레딧 차감 (내부) | POST .../credits/deduct | - |
| 26 | 크레딧 | 멤버별 크레딧 현황 | GET .../credits/members | billing/credits |
| 27 | 크레딧 | 크레딧 수동 조정 | POST .../credits/[userId]/adjust | billing/credits |
| 28 | 인프라 | PG 추상화 레이어 | - | - |
| 29 | 인프라 | 빌링키 암호화/복호화 | - | - |
| 30 | 인프라 | 비례 배분 계산 유틸 | - | - |
| 31 | 인프라 | 정기결제 스케줄러 | - | - |
| 32 | 인프라 | Dunning 매니저 | - | - |
docs/blueprints/ 디렉토리를 스캔하여 기존 번호 중 가장 큰 값 + 1로 결정한다.
블루프린트 파일을 생성하기 전에, dev 브랜치로 전환하고 최신 상태로 동기화한다. 작업 브랜치는 생성하지 않으며, dev에서 직접 작업한다. 작업 브랜치 생성은 /pr-merge 실행 시 자동으로 처리된다.
git branch --show-currentdev 브랜치인 경우 스킵: 현재 브랜치가 dev이면 아래 3~5단계를 건너뛰고 pull만 실행한다 (git pull origin dev)git status --porcelain으로 확인하여 변경사항이 있으면 git stash --include-untracked로 임시 저장한다 (untracked 파일도 포함)git fetch origin dev && git checkout dev && git pull origin devgit stash pop으로 복원한다. 충돌 발생 시 충돌 파일 목록을 사용자에게 보고하고 수동 해결을 요청한다.참고:
dev브랜치가 존재하지 않으면main또는master브랜치에서 작업한다. 어떤 기본 브랜치도 없으면 현재 브랜치에서 작업한다.
docs/blueprints/{NNN}-payment/blueprint.md 파일을 생성한다.
블루프린트에 포함할 내용 (레퍼런스 설계를 대상 프로젝트에 맞게 적응):
docs/database/database-design.md에 결제 모듈 테이블 13개를 추가한다 (기존 내용 보존).
블루프린트 작성 완료 후 AskUserQuestion으로 사용자에게 확인한다:
## 블루프린트 검토
결제 모듈 블루프린트가 생성되었습니다:
- 파일: docs/blueprints/{NNN}-payment/blueprint.md
- DB 테이블: 13개 (TB_PAY_PLAN, TB_PAY_SBSC 등)
- API: 32개 기능 (6개 그룹)
- 화면: 9개 페이지
- 크레딧 관리: 6개 API + 크레딧 생명주기
블루프린트를 확인하고 수정사항이 있으면 알려주세요.
계속 진행할까요?
선택지: "예, 계속 진행", "수정 필요 — 피드백 제공"
docs/sprints/ 디렉토리에서 sprint-{N}-{name}/ 패턴 디렉토리를 스캔하여 다음 스프린트 번호를 결정한다.
결제 모듈의 6개 Phase를 Feature 단위로 분할하여 docs/sprints/sprint-{N}-payment/prompt-map.md 파일을 생성한다:
# Sprint {N} - 구독 결제 모듈
## Feature 1: 기반 인프라
- DB 스키마 정의 (13개 테이블)
- DB 마이그레이션
- 빌링키 암호화/복호화 유틸
- 비례 배분 계산 유틸
- Zod 검증 스키마
- PG 추상화 인터페이스
## Feature 2: PG 연동 + 결제 수단
- PG사 어댑터 (토스페이먼츠/KCP)
- PG 어댑터 팩토리 + 에러 매핑
- 결제 수단 CRUD API (4개)
- 웹훅 수신 핸들러 (토스/KCP)
## Feature 3: 구독 관리
- 플랜 CRUD API (4개)
- 구독 시작/조회/변경/해지/일시정지/재개 API (7개)
- 청구서 생성 로직
- 구독 상태 관리 로직
## Feature 4: 크레딧 + 스케줄러 + Dunning
- 크레딧 매니저 서비스 (할당/차감/만료/재조정)
- 크레딧 API (6개)
- 크레딧 가드 미들웨어
- 정기결제 스케줄러 (Cron)
- Dunning 매니저 (4단계 재시도)
- 청구서/결제 API (4개)
## Feature 5: 화면 구현
- 요금제 안내 페이지 (Public)
- 결제 수단 관리 페이지
- 구독 관리 페이지 + 플랜 변경/해지 모달
- 결제 내역 페이지 (목록/상세)
- 결제 실패 안내 페이지
- 크레딧 관리 페이지
- 크레딧 UI 컴포넌트 (사용률 배지, 소진 배너)
## Feature 6: 관리자 + 통합
- 플랜 관리 페이지 (SYSTEM ADMIN)
- 구독 현황 대시보드 (SYSTEM ADMIN)
- 워크스페이스 모듈 연동 (멤버 가입/탈퇴 → 크레딧 할당/만료)
- WorkspaceSubscriptionContext
- Rate Limiting 적용
docs/sprints/sprint-{N}-payment/progress.md 파일을 생성한다:
# Sprint {N} Progress Tracker
## Sprint Information
- **Sprint Number**: {N}
- **Sprint Goal**: 구독 결제 모듈 전체 구축
- **Start Date**: {TODAY}
- **End Date**: {TODAY + 7 days}
- **Status**: In Progress
<!-- PROGRESS_TABLE_START -->
## Feature Progress
| Feature | Blueprint | DB Design | Test Cases | Implementation | Test Report | Status |
|---------|-----------|-----------|------------|----------------|-------------|--------|
| F1. 기반 인프라 | Done | - | - | - | - | Not Started |
| F2. PG 연동 + 결제 수단 | Done | Done | - | - | - | Not Started |
| F3. 구독 관리 | Done | Done | - | - | - | Not Started |
| F4. 크레딧 + 스케줄러 + Dunning | Done | Done | - | - | - | Not Started |
| F5. 화면 구현 | Done | N/A | - | - | - | Not Started |
| F6. 관리자 + 통합 | Done | N/A | - | - | - | Not Started |
**Legend**: `-` Not Started, `WIP` In Progress, `Done` Completed, `N/A` Not Applicable
<!-- PROGRESS_TABLE_END -->
<!-- SUMMARY_START -->
## Summary
- **Total Features**: 6
- **Completed**: 0
- **In Progress**: 0
- **Overall Progress**: 0%
- **Last Updated**: {TIMESTAMP}
<!-- SUMMARY_END -->
<!-- ACTIVITY_LOG_START -->
## Activity Log
| Timestamp | Event | File | Details |
|-----------|-------|------|---------|
| {TIMESTAMP} | blueprint | docs/blueprints/{NNN}-payment/blueprint.md | 결제 모듈 블루프린트 생성 |
| {TIMESTAMP} | db-design | docs/database/database-design.md | 결제 테이블 13개 추가 |
<!-- ACTIVITY_LOG_END -->
Step 0에서 분석한 대상 프로젝트의 기술 스택에 맞게 레퍼런스 설계를 적응하여 구현한다.
lib/db/schema/billing.tsschema.prisma 모델 추가PaymentGateway 인터페이스 (issueBillingKey, chargeBillingKey, getPayment, cancelPayment)PG_PRVDR_CD에 따른 어댑터 선택GET /workspaces/[wsId]/billing/payment-methodsPOST /workspaces/[wsId]/billing/payment-methods (빌링키 발급 → 암호화 → 저장)PATCH .../payment-methods/[id]/defaultDELETE .../payment-methods/[id] (활성 구독 사용 중이면 거부)allocateCreditsForPeriod, deductCredits (SELECT FOR UPDATE), expireCreditsForPeriod, adjustCreditsForPlanChangeuseWorkspaceSubscription, useWorkspacePaymentMethod, useWorkspaceCredit/pricing): 플랜 비교, 월간/연간 토글, 구독 시작 CTA각 Phase 완료 시 progress.md를 업데이트한다.
구현 완료 후 docs/tests/ 디렉토리에 E2E 테스트 시나리오를 생성한다.
TS-1: 플랜 관리
TS-2: 결제 수단
TS-3: 구독 관리
TS-4: 청구서/결제
TS-5: 웹훅
TS-6: 정기결제 + Dunning
TS-7: 크레딧
TS-8: 보안/엣지 케이스
[테스트 실패 감지]
│
│ 1. 에러 메시지 분석
│ 2. 관련 코드 확인 (API Route, Service, Schema)
│ 3. 원인 파악 및 수정
│ 4. 재테스트
│
└─ 성공 시 다음 TC로 이동
└─ 5회 실패 시 사용자에게 도움 요청:
## 테스트 디버깅 지원 요청
다음 테스트 케이스가 5회 반복 디버깅 후에도 통과하지 못했습니다:
- TC: {테스트 케이스 ID}
- 에러: {에러 메시지}
- 시도한 수정: {수정 내역 목록}
도움을 주시거나 이 TC를 건너뛸지 결정해 주세요.
docs/tests/test-reports/sprint-{N}/payment-test-report.md 파일에 결과를 기록한다:
# Test Report - Sprint {N} (구독 결제 모듈)
## Summary
- Total: {총 TC 수}
- Passed: {통과 수}
- Failed: {실패 수}
- Skipped: {건너뜀 수}
## Results
| TC ID | 시나리오 | 결과 | 비고 |
|-------|---------|------|------|
| TC-1.1 | 플랜 목록 조회 | PASS | - |
| ... | ... | ... | ... |
모든 단계가 완료되면 최종 보고를 출력한다:
## 구독 결제 모듈 구축 완료
### 생성된 파일 요약
- 블루프린트: docs/blueprints/{NNN}-payment/blueprint.md
- DB 스키마: {schema-file-path} (13개 테이블)
- API: {api-count}개 엔드포인트
- 화면: {page-count}개 페이지
- 테스트: {tc-count}개 시나리오 ({pass-count} PASS)
### 주요 기능
- 플랜 관리 (CRUD + 기능/제한)
- 결제 수단 관리 (빌링키 AES-256 암호화)
- 구독 관리 (상태 전이 + 비례 배분)
- 크레딧 관리 (할당/차감/만료/재조정)
- PG사 연동 (PG-Agnostic 추상화)
- 정기결제 + Dunning (4단계 재시도)
### 환경 변수 설정 필요
- PG 키 (TOSS_SECRET_KEY 등)
- 빌링키 암호화 키 (BILLING_KEY_ENCRYPTION_KEY)
- 스케줄러 설정 (BILLING_SCHEDULER_ENABLED)
### 운영 전 체크리스트
- [ ] PG사 운영 키 발급 및 설정
- [ ] 빌링키 암호화 키를 KMS/Vault로 이전
- [ ] 웹훅 엔드포인트 PG사에 등록
- [ ] IP 화이트리스트 설정 (웹훅)
- [ ] Rate Limiting 임계값 조정
- [ ] 정기결제 스케줄러 cron 설정 확인
- [ ] Dunning 알림 이메일/SMS 템플릿 설정
- [ ] 초기 플랜 데이터 Seed 실행
progress.md의 해당 Feature 상태를 모두 완료로 업데이트한다.
tools
Runs UAT (User Acceptance Testing) cases in TRUE PARALLEL using Playwright Test runner with isolated browser contexts per worker (separate cookies, localStorage, sessionStorage). Solves the two main limits of /user-test: (1) sequential single-page execution that does not scale beyond a few cases, and (2) one stuck case blocking the rest of the run. Reuses 100% of the /user-test UAT case Markdown+YAML format under docs/tests/uat-cases/, runs them via `npx playwright test --workers=N`, and emits the same report layout (index.html + issues.md + session.json + screenshots/) under docs/tests/uat-reports/. Use when the user asks to "run UAT in parallel", "speed up UAT", "test multi-user", "song song", "uat parallel", or runs /uat-parallel. Distinct from /user-test (sequential Chrome MCP, supports interactive mode), /test-run (developer integration tests), /test-scenario (scenario authoring).
tools
Performs end-user UAT (User Acceptance Testing) by driving a real browser through Chrome MCP, self-verifying each step with hard assertions (DOM / Network / URL / Console), auto-assigning severity on failure, and emitting an HTML report plus issues.md into a timestamped session folder. Supports two modes: interactive (URL + Vietnamese natural-language flow description) and --auto (batch-run pre-authored test cases under docs/tests/uat-cases/). Use when the user asks for "UAT", "user acceptance test", "kiểm thử người dùng", "regression test", or runs /user-test, /uat. Distinct from /test-run (developer-authored technical integration testing) and /test-scenario (scenario authoring from blueprints).
tools
Authors and validates LLM tool descriptions and input schemas (Anthropic Tool Use, MCP servers, LangChain @tool, Pydantic, Zod). Use when the user mentions "tool description", "function calling", "MCP tool", "Pydantic schema", "Zod schema", "@tool decorator", "input_schema", "tool spec", "툴 정의", "함수 호출 스키마", or when editing files that define LLM tool surfaces. Enforces the six required attributes (one-line summary, anti-pattern, synonyms, parameter examples, enum constraints, return shape) and blocks the seven known failure modes — wrong-tool selection, skipped tool, malformed arguments, retry loops, user-intent bypass, wrong side-effect, and un-auditable traces. For authoring ASTRA SKILL.md files use /skill-author instead — this skill is for *runtime* LLM tool surfaces, not for skill files themselves.
development
Creates new SKILL.md files or refactors existing skills to comply with the ASTRA skill best practices guide (docs/development/skill-best-practices.md). Use when user mentions "new skill", "create skill", "SKILL.md", "skill authoring", "스킬 작성", "스킬 만들기", or when editing any file matching skills/**/SKILL.md.