Platform Payment Flows
Platform-specific payment business logic, including Post Fees, Tipping, and PRO Membership upgrades.
Install
mkdir -p .claude/skills/platform-payment-flows && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14190" && unzip -o skill.zip -d .claude/skills/platform-payment-flows && rm skill.zipInstalls to .claude/skills/platform-payment-flows
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Platform-specific payment business logic, including Post Fees, Tipping, and PRO Membership upgrades.About this skill
Platform Payment Flows Skill
Overview
This skill details the business logic for payments within the platform. While pi-payments covers the technical SDK integration, this skill focuses on how payments are applied to specific features: Creating Posts, Tipping, and PRO Membership.
Payment Model:
- Client-Side: Initiates Pi Payment via SDK -> Gets
txid. - Server-Side: Receives
txid+ Business Action -> Verifies -> Fulfills.
Key Files:
- Frontend:
web/js/forum.js(Post/Tip),web/js/premium.js(Membership) - Backend:
api/routers/forum.py(create_post,tip_post),api/routers/user.py(upgrade_to_pro) - Database:
core/database/forum.py,core/database/user.py
Payment Scenarios
1. Paid Post Creation
Users pay a small fee (e.g., 0.1 Pi) to create a post in specific boards or to bypass daily limits.
Workflow:
- Frontend: Checks if payment is required (based on
ForumLimits). - Frontend: Calls Pi SDK
createPayment. - Frontend: On success, sends
createPost(data, tx_hash)to backend. - Backend:
- Validates
tx_hashformat (and optionally queries blockchain). - Creates post with
payment_tx_hashstored inforum_posts. - Result: Post is live.
- Validates
2. Tipping
Users send direct P2P tips to content creators.
Workflow:
- Frontend: User clicks "Tip", selects amount.
- Frontend: SDK Payment to Creator's Wallet (Visual verification key).
- Frontend: Sends
tipPost(postId, amount, tx_hash)to backend. - Backend:
- Records tip in
forum_tips. - Updates
tips_totalcount on the post. - Sends notification to recipient (see
platform-notification-system).
- Records tip in
3. PRO Membership Upgrade
Users pay a monthly fee (e.g., 10 Pi) to upgrade account status.
Workflow:
- Frontend:
PremiumManagerinitiates payment to Platform Wallet. - Frontend: Sends
upgradeToPro(tx_hash)to backend. - Backend:
- Records in
membership_payments. - Updates user
membership_tierto 'PRO' and setsmembership_expires_at. - Result: Instant access to PRO features.
- Records in
Database Integration
forum_posts
Stores payment proof for the post itself.
- payment_tx_hash: VARCHAR(100) -- Proof of payment
forum_tips
Records P2P transactions for history and gamification.
- from_user_id: VARCHAR(100)
- to_user_id: VARCHAR(100)
- amount: NUMERIC
- tx_hash: VARCHAR(100) -- UNIQUE constraint prevents replay
membership_payments
Records revenue and subscription history.
- user_id: VARCHAR(100)
- amount: NUMERIC
- months: INTEGER
- tx_hash: VARCHAR(100) -- UNIQUE constraint
Validation & Security
Transaction Hash Validation
Backend uses pi-wallet-validation skill logic:
- Length check (64 chars).
- Character check (Hexadecimal).
Replay Attack Prevention
All relevant tables (forum_tips, membership_payments) enforce UNIQUE(tx_hash).
If a user tries to reuse a hash:
try:
insert_payment(tx_hash)
except IntegrityError:
return Error("Transaction already used")
On-Chain Verification (Recommended)
Currently, the system uses "Optimistic Verification" (checks hash format).
Future Improvement: Backend should query Pi Blockchain API /transactions/{tx_hash} to verify:
- Sender: Matches current user.
- Recipient: Matches Platform/Creator wallet.
- Amount: Matches expected cost.
- Memo: Matches order ID (if used).
API Endpoints
Post & Tip (api/routers/forum.py)
POST /api/forum/posts
Payload: { ..., "payment_tx_hash": "..." }
POST /api/forum/posts/{id}/tip
Payload: { "amount": 1.0, "tx_hash": "..." }
Membership (api/routers/user.py)
POST /api/user/upgrade
Payload: { "months": 1, "tx_hash": "..." }
Common Issues
Issue 1: "Post created but payment failed"
Cause: User closed app after payment but before API call.
Solution: Frontend should cache tx_hash in localStorage and retry API call on next load.
Issue 2: "Transaction already exists"
Cause: Double submission or Replay attack. Solution: Show friendly error "This payment has already been processed".
Issue 3: PRO status not updating
Cause: Backend error recording payment. Solution: Admin tool to manual verify hash and grant PRO status.
Related Skills
- pi-payments: SDK technical implementation.
- platform-wallet-system: Where history is displayed.
- pi-wallet-validation: Hash format rules.
Maintenance Notes
Last Updated: 2026-02-08
Config:
Prices are defined in core/config.py or system_config table:
PRO_MONTHLY_PRICE: 3.14 PiPOST_CREATION_FEE: 0.1 Pi