CustomPaymentLink 모델 + 마이그레이션 + 라우팅 + 서비스

ID: 81248c7b-af18-4b42-ba9e-f1ff315a6615

높음 완료

## 작업 내용
CustomPaymentLink 모델, DB 마이그레이션, 라우팅, 서비스 객체를 생성합니다.

## 1. DB 마이그레이션
```ruby
create_table :custom_payment_links, id: :uuid do |t|
t.string :title, null: false # 상품명
t.integer :amount, null: false # 결제 금액 (원)
t.text :description # 상세 설명
t.string :status, default: "pending", null: false # pending/completed/canceled
t.string :token, null: false # URL 토큰
t.datetime :expires_at, null: false # 만료일
t.references :created_by, type: :uuid, null: false, foreign_key: { to_table: :users }
t.references :payment, type: :uuid, foreign_key: true # 결제 완료 시 연결
t.datetime :paid_at # 결제 완료 시각
t.timestamps
end
add_index :custom_payment_links, :token, unique: true
add_index :custom_payment_links, :status
```

## 2. CustomPaymentLink 모델
- belongs_to :created_by, class_name: "User"
- belongs_to :payment, optional: true
- enum :status (pending, completed, canceled)
- validates :title, :amount, :token, :expires_at presence
- validates :amount, numericality: { greater_than: 0 }
- validates :token, uniqueness: true
- before_validation :generate_token (SecureRandom.urlsafe_base64(32))
- scope :active → pending + 만료 안 됨
- scope :recent → created_at desc
- expired? 메서드
- complete!(payment:) 메서드
- cancel! 메서드

## 3. 라우팅 (config/routes.rb)
admin namespace 안에 추가:
```ruby
resources :custom_payment_links, only: %i[index new create] do
member do
patch :cancel
get :qr_code
end
end
```

locale scope 밖에 추가 (토큰 기반 공개 접근):
```ruby
# Custom Payment Links (토큰 기반 공개 결제)
get "pay/:token", to: "custom_payments#show", as: :custom_payment
get "pay/:token/success", to: "custom_payments#success", as: :custom_payment_success
get "pay/:token/fail", to: "custom_payments#fail", as: :custom_payment_fail
```

## 4. 서비스 객체
### CustomPaymentLinks::CreateService
- 입력: title, amount, description, expires_in(일수), created_by(User)
- expires_at = expires_in.days.from_now
- CustomPaymentLink.create!
- 반환: custom_payment_link

### CustomPaymentLinks::CancelService
- 입력: custom_payment_link
- pending? 검증
- update!(status: "canceled")

## 5. 테스트
- 모델 테스트: 유효성 검증, 상태 전환, scope
- 서비스 테스트: 생성, 취소 시나리오

## 담당 파일
- db/migrate/XXXX_create_custom_payment_links.rb
- app/models/custom_payment_link.rb
- config/routes.rb
- app/services/custom_payment_links/create_service.rb
- app/services/custom_payment_links/cancel_service.rb
- test/models/custom_payment_link_test.rb
- test/fixtures/custom_payment_links.yml

## 완료 기준
- 마이그레이션 실행 성공
- 모델 테스트 통과
- 서비스 테스트 통과
- routes 정상 작동

첨부 이미지

이미지 추가 (Ctrl+V로 붙여넣기 또는 클릭)

JPEG, PNG, GIF, WebP / 최대 10MB

담당자: 백엔드
생성일: 2026년 02월 28일 07:20

활동 로그

  • 팀리드 상태 변경: 리뷰 → 완료

    2026년 02월 28일 07:39:52

  • 백엔드 상태 변경: 진행 중 → 리뷰

    2026년 02월 28일 07:36:59

  • 백엔드 CustomPaymentLink 모델, 마이그레이션, 라우팅, 서비스 구현 완료

    2026년 02월 28일 07:36:58

    상세 보기

    ## 완료 사항
    - DB 마이그레이션: `20260228072648_create_custom_payment_links.rb` 생성 및 실행 완료
    - 모델: `app/models/custom_payment_link.rb` (enum, validations, scopes, callbacks)
    - 서비스: `CreateService`, `CancelService` 생성
    - 라우팅: admin namespace + 공개 결제 라우트 추가
    - Fixture: pending/completed/canceled/expired 4종 생성
    - 테스트: 모델 테스트 18건 + 서비스 테스트 6건 = 24건 전체 통과

    ## 생성/수정 파일
    - `db/migrate/20260228072648_create_custom_payment_links.rb`
    - `app/models/custom_payment_link.rb`
    - `app/services/custom_payment_links/create_service.rb`
    - `app/services/custom_payment_links/cancel_service.rb`
    - `config/routes.rb`
    - `test/fixtures/custom_payment_links.yml`
    - `test/models/custom_payment_link_test.rb`
    - `test/services/custom_payment_links/create_service_test.rb`
    - `test/services/custom_payment_links/cancel_service_test.rb`

  • 백엔드 작업 시작: CustomPaymentLink 모델, 마이그레이션, 라우팅, 서비스 구현

    2026년 02월 28일 07:26:00

  • 백엔드 티켓 클레임 완료

    2026년 02월 28일 07:25:56