跳到主要内容

WooCommerce 集成

在你的 WooCommerce 商店中通过 Pelago 接受加密货币支付。

安装​

WordPress 插件​

  1. 下载 Pelago WooCommerce 插件
  2. 前往 插件 → 添加新插件 → 上传插件
  3. 上传并激活插件
  4. 前往 WooCommerce → 设置 → 支付 → Pelago

手动安装​

cd wp-content/plugins
git clone https://github.com/polyflow/pelago-woocommerce.git

然后在 WordPress 管理后台中激活。

配置​

插件设置​

前往 WooCommerce → 设置 → 支付 → Pelago:

设置描述
启用/禁用开关 Pelago 支付
标题结账时的支付方式名称
描述结账页面描述
API Key你的 Pelago 公钥
API Secret你的 Pelago 私钥
Merchant Wallet你的加密钱包地址
Network默认区块链网络
Cryptocurrencies接受的加密货币
Sandbox Mode使用测试环境

环境变量(可选)​

// wp-config.php
define('PELAGO_API_KEY', 'pk_live_xxxxx');
define('PELAGO_API_SECRET', 'sk_live_xxxxx');
define('PELAGO_WALLET', 'GXXXXX...');

支付流程​

自定义​

自定义按钮文字​

// functions.php
add_filter('pelago_button_text', function($text) {
return '加密货币支付 💰';
});

自定义重定向 URL​

add_filter('pelago_redirect_url', function($url, $order) {
return home_url('/thank-you/?order=' . $order->get_id());
}, 10, 2);

订单状态映射​

add_filter('pelago_order_status_completed', function() {
return 'completed'; // 默认: 'processing'
});

钩子与动作​

支付完成后​

add_action('pelago_payment_completed', function($order_id, $payment) {
$order = wc_get_order($order_id);

// 添加自定义订单备注
$order->add_order_note(sprintf(
'通过 Pelago 支付。交易哈希: %s',
$payment['transactionHash']
));

// 触发自定义动作
do_action('my_custom_payment_action', $order, $payment);
}, 10, 2);

支付失败​

add_action('pelago_payment_failed', function($order_id, $reason) {
$order = wc_get_order($order_id);
$order->update_status('failed', 'Pelago 支付失败: ' . $reason);
});

多币种​

WooCommerce 货币切换器兼容:

add_filter('pelago_payment_currency', function($currency) {
// 获取当前展示货币
if (function_exists('wcpmc_get_current_currency')) {
return wcpmc_get_current_currency();
}
return $currency;
});

短代码​

在任意位置展示 Pelago 支付按钮:

[pelago_button amount="99.99" currency="USD" product_id="123"]

REST API 端点​

插件添加的 REST 端点:

# 创建支付
POST /wp-json/pelago/v1/payment

# Webhook 处理
POST /wp-json/pelago/v1/webhook

测试​

沙盒模式​

  1. 在插件设置中启用沙盒
  2. 使用测试 API 密钥
  3. 创建测试订单

调试模式​

// wp-config.php
define('PELAGO_DEBUG', true);

日志将写入 wp-content/debug.log。

故障排除​

支付未显示​

  1. 确保插件已激活
  2. 检查 WooCommerce 支付设置
  3. 验证 API 凭证

Webhook 不工作​

  1. 检查固定链接设置(不能是"朴素"模式)
  2. 验证 Webhook URL 可访问
  3. 检查服务器日志中的错误

需要 SSL​

Pelago 需要 HTTPS。请确保你的网站拥有有效的 SSL 证书。

下一步​