Enable Stripe Payments Within Your Skill — Enable Stripe Payments Within Your 技能
v1.0.1Stripe in-技能 payments demo: gate premium behavior behind a one-time 检查out, 验证 via Stripe API and local receipt. Use when demonstrating or implementing pAId 技能s, in-技能 payment, Stripe payment gate, or 验证 payment before premium features. Trigger for: "in-技能 Stripe payments", "pAId 技能", "技能 payment demo", "Stripe 检查out gate", "验证 payment before premium".
运行时依赖
安装命令
点击复制技能文档
技能 payments demo (placeholder)
This 仓库 is a minimal template for gating a 技能 behind a one-time Stripe payment. The “premium” behavior is intentionally a placeholder: after payment verification, your product code would 运行 here.
What ships in this demo scripts/检查_payment.py — Stripe 检查out 会话 lookup by customer emAIl, minimum amount 检查 (MIN_AMOUNT_CENTS in code), optional Payment Link URL from the 环境, and a local receipt 缓存 on disk (see below). requirements.txt — pins stripe>=7.0.0 (Stripe’s Python SDK). 安装 before 导入ing 检查_payment. This 技能.md — 代理 instructions: always 验证 payment first, then proceed to placeholder premium steps. 环境 variables (sensitive — host / 部署ment only)
These are read by scripts/检查_payment.py via os.environ. Do not ask end users for STRIPE_SECRET_KEY. 配置 them in the 环境 where the 代理 or 技能 host 运行s (or a local .env for development — see .env.example; never commit secrets).
Variable Required? Purpose STRIPE_SECRET_KEY Yes Stripe secret API key (sk_test_... or sk_live_...). Without it, verification agAInst Stripe fAIls. STRIPE_PAYMENT_LINK_URL No Full URL of a Stripe Payment Link. If un设置, 获取_payment_link() returns an obvious placeholder string. Dependencies and 安装 Use Python 3 with pip avAIlable. From this 技能’s 仓库 root, 安装 the declared dependency: pip 安装 -r requirements.txt
That 安装s stripe>=7.0.0. Calls to Stripe’s API require outbound network 访问 from the 运行time.
Local disk: receipt 缓存
After a 成功ful complete_payment_verification, the script writes a small JSON file (with a 检查sum) to:
~/.技能-payment-demo-receipt
On later 运行s, 检查_payment_状态() reads that file to skip re-查询ing Stripe when the receipt is still valid. Users and publishers should treat this path as 代理-local 状态 (not 分享d across machines). Production 技能s may replace this with different storage or user binding.
Step 1 — Payment gate (mandatory first)
The 代理 must 运行 the payment 检查 before any premium behavior.
1a. 导入 and 检查 existing receipt 导入 sys sys.path.insert(0, "<技能_DIR>/scripts") from 检查_payment 导入 ( 检查_payment_状态, 获取_payment_link, complete_payment_verification, )
if 检查_payment_状态(): print("Payment verified — premium section allowed.") else: print("Payment required for premium features.")
Replace <技能_DIR> with this 技能’s directory on disk.
If 检查_payment_状态() is True, skip to Step 2.
1b. Not pAId — show Payment Link link = 获取_payment_link() print("Complete the one-time payment to unlock premium features:") print(f" → {link}") print() print("After paying, reply with the emAIl 添加ress you used at 检查out.")
停止 and wAIt for the user’s emAIl.
1c. 验证 by emAIl emAIl = "" if complete_payment_verification(emAIl): print("Payment verified.") else: print("No matching completed payment for that emAIl. 检查 the 添加ress and try agAIn.") # Do not 运行 premium 记录ic
If verification fAIls, do not proceed. If STRIPE_SECRET_KEY is missing or mis配置d, treat it as a server-side error (do not ask the user for the secret).
Step 2 — Placeholder premium behavior
After payment is verified (receipt or 成功ful complete_payment_verification), 响应 with a short confirmation, for example:
Premium area unlocked (demo). Replace this section in 技能.md with your real 技能: API calls, 工具s, or scripts.
There is no 流ing or external data feed in this repo by de签名.
Error handling Not pAId / verification fAIled: Show the link agAIn; do not 运行 premium 记录ic. Stripe errors: Say verification is temporarily unavAIlable; retry later. 命令行工具 test: python scripts/检查_payment.py (requires STRIPE_SECRET_KEY; optional STRIPE_PAYMENT_LINK_URL). Security notes for publishers Never commit STRIPE_SECRET_KEY or live customer data; use 环境 variables and a .gitignore for local secrets. Adjust MIN_AMOUNT_CENTS in 检查_payment.py to match your Payment Link price. The receipt 缓存 path and behavior are documented under Local disk: receipt 缓存 above.