feat(payment): Integrate Stripe API and refactor payment flow

- Add new stripe_api.py module with StripePaymentAPI class and payment retry logic
- Import Stripe payment module in auto_gpt_team.py with graceful fallback handling
- Refactor run_payment_flow() to extract form filling logic into _fill_payment_form()
- Simplify error handling by returning structured tuples (success, error_type, error_msg)
- Remove redundant comments and streamline selector logic for payment form elements
- Improve code maintainability by separating concerns between form filling and flow orchestration
- Add STRIPE_API_AVAILABLE flag to track payment module availability at runtime
This commit is contained in:
2026-01-30 09:57:55 +08:00
parent ad03fab8e9
commit 11395bf1ba
3 changed files with 992 additions and 477 deletions

View File

@@ -3861,6 +3861,13 @@ class ProvisionerBot:
api_supported = False
current_mode = "browser"
# 获取当前并发数
try:
from config import CONCURRENT_WORKERS, CONCURRENT_ENABLED
current_workers = CONCURRENT_WORKERS if CONCURRENT_ENABLED else 1
except ImportError:
current_workers = 1
keyboard = [
[
InlineKeyboardButton("📋 查看配置", callback_data="autogptplus:config"),
@@ -3887,6 +3894,11 @@ class ProvisionerBot:
InlineKeyboardButton(f"⚙️ 注册模式: {mode_icon} {mode_text}", callback_data="autogptplus:select_mode"),
])
# 添加并发设置按钮
keyboard.append([
InlineKeyboardButton(f"⚡ 并发数: {current_workers}", callback_data="autogptplus:set_concurrent"),
])
keyboard.append([
InlineKeyboardButton("🚀 开始注册", callback_data="autogptplus:register"),
])
@@ -3932,6 +3944,10 @@ class ProvisionerBot:
await self._set_autogptplus_mode(query, sub_action)
elif action == "register":
await self._start_autogptplus_register(query, context)
elif action == "set_concurrent":
await self._show_autogptplus_concurrent_selection(query)
elif action == "concurrent":
await self._set_autogptplus_concurrent(query, sub_action)
elif action == "back":
# 返回主菜单
await query.edit_message_text(
@@ -4086,7 +4102,119 @@ class ProvisionerBot:
reply_markup=reply_markup
)
async def _test_autogptplus_email(self, query):
async def _show_autogptplus_concurrent_selection(self, query):
"""显示并发数选择界面"""
try:
from config import CONCURRENT_WORKERS, CONCURRENT_ENABLED
current_workers = CONCURRENT_WORKERS if CONCURRENT_ENABLED else 1
except ImportError:
current_workers = 1
keyboard = [
[
InlineKeyboardButton(
f"{'' if current_workers == 1 else ''}1 并发",
callback_data="autogptplus:concurrent:1"
),
InlineKeyboardButton(
f"{'' if current_workers == 3 else ''}3 并发",
callback_data="autogptplus:concurrent:3"
),
InlineKeyboardButton(
f"{'' if current_workers == 5 else ''}5 并发",
callback_data="autogptplus:concurrent:5"
),
],
[InlineKeyboardButton("◀️ 返回", callback_data="autogptplus:back")],
]
reply_markup = InlineKeyboardMarkup(keyboard)
await query.edit_message_text(
"<b>⚡ 设置并发数</b>\n\n"
f"当前并发数: <b>{current_workers}</b>\n\n"
"选择注册时的并发数量:\n"
"• 1 并发 - 稳定,适合测试\n"
"• 3 并发 - 平衡速度和稳定性\n"
"• 5 并发 - 最快,需要较好的网络",
parse_mode="HTML",
reply_markup=reply_markup
)
async def _set_autogptplus_concurrent(self, query, workers_str: str):
"""设置并发数"""
try:
workers = int(workers_str)
if workers not in [1, 3, 5]:
await query.answer("❌ 无效的并发数", show_alert=True)
return
except ValueError:
await query.answer("❌ 无效的并发数", show_alert=True)
return
# 更新 config.toml
try:
from config import CONFIG_FILE
# 读取当前配置文件
with open(CONFIG_FILE, "r", encoding="utf-8") as f:
content = f.read()
# 检查是否存在 [concurrent] section
if "[concurrent]" not in content:
# 添加 [concurrent] section
content += f"\n\n[concurrent]\nenabled = true\nworkers = {workers}\n"
else:
# 更新 workers 值
import re
# 更新 enabled
if re.search(r"^\s*enabled\s*=", content, re.MULTILINE):
content = re.sub(
r"^(\s*enabled\s*=\s*).*$",
f"\\g<1>true",
content,
flags=re.MULTILINE
)
else:
# 在 [concurrent] 后添加 enabled
content = content.replace("[concurrent]", "[concurrent]\nenabled = true")
# 更新 workers
if re.search(r"^\s*workers\s*=", content, re.MULTILINE):
content = re.sub(
r"^(\s*workers\s*=\s*).*$",
f"\\g<1>{workers}",
content,
flags=re.MULTILINE
)
else:
# 在 [concurrent] section 中添加 workers
content = re.sub(
r"(\[concurrent\][^\[]*)",
f"\\g<1>workers = {workers}\n",
content
)
# 写回配置文件
with open(CONFIG_FILE, "w", encoding="utf-8") as f:
f.write(content)
# 重载配置
from config import reload_config
reload_config()
await query.answer(f"✅ 并发数已设置为 {workers}", show_alert=True)
# 返回主菜单
await query.edit_message_text(
"<b>🤖 AutoGPTPlus 管理面板</b>\n\n"
"ChatGPT 订阅自动化配置管理\n\n"
"请选择功能:",
parse_mode="HTML",
reply_markup=self._get_autogptplus_main_keyboard()
)
except Exception as e:
await query.answer(f"❌ 设置失败: {e}", show_alert=True)
"""测试 AutoGPTPlus 邮件创建"""
await query.edit_message_text("⏳ 正在测试邮件创建...")