站点图标 Linux-技术共享

VmShell,Stripe WordPress Payment Gateway 插件

 

Stripe WordPress Payment Gateway 插件

一个功能完整的 WordPress Stripe 支付网关插件,支持 Alipay、WeChat Pay、Stripe Link 三种支付方式,包含 3D Secure 验证、退款功能和 Webhook 事件监听。

功能特性

支持的支付方式

核心功能

Webhook 事件监听

插件监听以下 5 个关键 Stripe Webhook 事件:
  1. charge.succeeded - 费用成功
  2. charge.refunded - 费用已退款
  3. checkout.session.completed - 结账会话完成
  4. payment_intent.payment_failed - 支付意图失败
  5. payment_intent.succeeded - 支付意图成功

安装步骤

1. 上传插件

Bash
 
# 将插件文件夹上传到 WordPress 插件目录
/wp-content/plugins/stripe-wp-gateway/

2. 激活插件

3. 配置 Stripe 密钥

配置指南

获取 Stripe API 密钥

  1. 登录 Stripe Dashboard
  2. 获取 API 密钥
    • 进入 Developers → API Keys
    • 复制 Secret Key (sk_live_... )
    • 复制 Publishable Key (pk_live_...)
  3. 配置 Webhook
    • 进入 Developers → Webhooks
    • 点击 "Add endpoint"
    • 输入 Webhook URL:https://yoursite.com/wp-json/stripe-wp-gateway/v1/webhook
    • 选择事件:
      • charge.succeeded
      • charge.refunded
      • checkout.session.completed
      • payment_intent.payment_failed
      • payment_intent.succeeded
    • 复制 Signing Secret (whsec_... )

插件设置

设置项
说明
示例
显示在订购表格上
是否在结账页面显示此支付方式
✓ 已启用
显示称号
支付方式名称
Stripe Payment Gateway
Stripe 秘密密钥
SK_LIVE 密钥
sk_live_...
Stripe 发布密钥
PK_LIVE 密钥
pk_live_...
Webhook 密钥
Webhook 签名密钥
whsec_...
收款货币
支持的货币列表
USD, EUR, GBP, CNY 等
手续费百分比
交易手续费百分比
2.9
固定手续费
固定交易费用
0.3
启用 3D Secure
是否启用 3D 验证
✓ 已启用
启用 Alipay
是否启用支付宝
✓ 已启用
启用 WeChat Pay
是否启用微信支付
✓ 已启用
启用 Stripe Link
是否启用 Stripe Link
✓ 已启用
 

数据库结构

插件创建以下数据库表:

1. stripe_payments - 支付记录表

SQL
 
CREATE TABLE stripe_payments (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    order_id BIGINT NOT NULL,
    stripe_charge_id VARCHAR(255) UNIQUE NOT NULL,
    stripe_payment_intent_id VARCHAR(255),
    amount DECIMAL(10, 2) NOT NULL,
    currency VARCHAR(3) NOT NULL,
    payment_method VARCHAR(50),
    status VARCHAR(50),
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

2. stripe_refunds - 退款记录表

SQL
 
CREATE TABLE stripe_refunds (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    payment_id BIGINT NOT NULL,
    order_id BIGINT NOT NULL,
    stripe_refund_id VARCHAR(255) UNIQUE NOT NULL,
    amount DECIMAL(10, 2) NOT NULL,
    reason VARCHAR(255),
    status VARCHAR(50),
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

3. stripe_webhook_logs - Webhook 日志表

SQL
 
CREATE TABLE stripe_webhook_logs (
    id BIGINT PRIMARY KEY AUTO_INCREMENT,
    event_id VARCHAR(255) UNIQUE NOT NULL,
    event_type VARCHAR(100),
    payload LONGTEXT,
    status VARCHAR(50),
    created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);

支付流程

前端支付流程

  1. 用户选择支付方式(卡片、Alipay、WeChat Pay 或 Stripe Link)
  2. 用户填写必要信息
  3. 点击 "下单" 按钮
  4. 前端创建 Payment Intent
  5. 根据支付方式确认支付
  6. 支付成功后提交订单

后端处理流程

  1. 接收支付数据
  2. 验证 Payment Intent 状态
  3. 标记订单为已支付
  4. 保存支付记录
  5. 清空购物车
  6. 返回成功页面

Webhook 处理流程

  1. Stripe 发送 Webhook 事件
  2. 验证 Webhook 签名
  3. 记录 Webhook 日志
  4. 根据事件类型处理
  5. 更新订单和支付记录状态
  6. 发送通知

退款处理

全额退款

  1. 进入 WooCommerce 订单详情
  2. 在订单项目中点击 "退款"
  3. 系统自动处理 Stripe 退款
  4. 订单状态更新为已退款

部分退款

  1. 进入 WooCommerce 订单详情
  2. 输入退款金额
  3. 点击 "退款"
  4. 系统处理部分退款
  5. 订单状态相应更新

安全性

密钥管理

Webhook 验证

数据安全

故障排除

常见问题

1. "Invalid API Key" 错误

2. Webhook 未收到

3. 支付失败

4. 退款失败

日志查看

支付记录

退款记录

Webhook 日志

开发者文档

自定义 Hooks

支付成功

PHP
 
do_action('stripe_wp_gateway_charge_succeeded', $order, $charge);
do_action('stripe_wp_gateway_payment_intent_succeeded', $order, $intent);

支付失败

PHP
 
do_action('stripe_wp_gateway_payment_intent_failed', $order, $intent);

退款

PHP
 
do_action('stripe_wp_gateway_charge_refunded', $order, $charge);

结账完成

PHP
 
do_action('stripe_wp_gateway_checkout_completed', $order, $session);

自定义支付方式

在 stripe-payment.js 中添加新的支付方式:
JavaScript
 
// 在 initPaymentMethods() 函数中添加
html += '<label class="payment-method-option">';
html += '<input type="radio" name="stripe_payment_method" value="new_method" />';
html += '<span class="method-label">New Payment Method</span>';
html += '</label>';

// 在 handleCheckoutSubmit() 函数中添加处理逻辑
} else if (selectedPaymentMethod === 'new_method') {
    result = await handleNewMethod(paymentIntentData.client_secret);
}

支持

如有问题或建议,请:
  1. 查看本文档的故障排除部分
  2. 检查 Stripe 官方文档:https://stripe.com/docs
  3. 查看 WooCommerce 官方文档:https://woocommerce.com/documentation/
  4. 联系插件开发者

许可证

本插件采用 GPL v2 或更高版本许可证 。详见 LICENSE 文件。

更新日志

v1.0.0 (2024-03-05)

VmShell支付插件地址:https://linuxword.com/wp-content/uploads/2026/03/vmshell-stripe-payment-v1.0.0-complete.zip

退出移动版