菲律宾本地支付 · 原生通道直连

WooCommerce整合菲律宾支付的实操步骤

·

·

WooCommerce整合菲律宾支付的实操步骤

前期准备

  1. 确认业务合法性:确保您的业务在菲律宾合法运营,符合当地支付法规
  2. 选择支付网关:研究适合菲律宾市场的支付方式(如GCash、PayMaya、Dragonpay等)
  3. 注册商家账户:在选定的支付平台完成商户注册和验证流程

技术整合步骤

方法一:使用官方插件(推荐)

  1. 安装插件

    • 登录WooCommerce后台
    • 导航至"插件"→"添加新"
    • 搜索您选择的菲律宾支付网关插件(如"Dragonpay for WooCommerce")
    • 安装并激活插件
  2. 配置基本设置

    导航至: WooCommerce → Settings → Payments
    启用您选择的菲律宾支付方式
    输入商户ID、API密钥等认证信息(从您的支付提供商处获取)
    设置交易货币为PHP(菲律宾比索)
  3. 测试模式设置

    • 启用沙盒/测试模式进行初步测试
    • 使用测试卡号或模拟账户验证交易流程

方法二:自定义API集成(适用于无官方插件的服务商)

  1. 创建自定义支付网关
// functions.php中添加以下代码或创建独立插件文件

add_filter('woocommerce_payment_gateways', 'add_custom_ph_gateway');
function add_custom_ph_gateway($gateways) {
$gateways[] = 'WC_Custom_PH_Gateway';
return $gateways;
}

class WC_Custom_PH_Gateway extends WC_Payment_Gateway {

public function __construct() {
// Gateway初始化代码...
$this->init_form_fields();
$this->init_settings();

// API端点配置示例:
$this->api_url = "https://api.payment-provider.ph/v2/";

add_action('woocommerce_update_options_payment_gateways_' .
$this->id, array($this, 'process_admin_options'));
}

}

  1. 实现核心功能方法
public function process_payment($order_id) {

global $woocommerce;

// Get order details from WooCommerce database.
try{
if(!$order = new WC_Order($order_id)) throw new Exception("Invalid Order");

// Prepare payload for Philippine payment provider's API.
switch ($selected_provider){
case "gcash":
return gcash_process_order($order);
case "dragonpay":
return dragonpay_process_order($order);
default:
throw new Exception("Unsupported Payment Method");
}

} catch(Exception $e){
wc_add_notice(__('Payment error:', 'woothemes') .
esc_html__($e->getMessage()), 'error');
return false;
}
}

PHP特定注意事项

  • curl扩展必须启用以处理API请求:
if (!extension_loaded('curl')) { /* fallback handling */ }
  • SSL证书验证:
// Always verify peer certificates when dealing with financial data!
curl_setopt_array([
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => true,
]);

BSP合规性要求 (Bangko Sentral ng Pilipinas)

  1. PHP金额格式化规范:
number_format((float)$amount,2,'.',','); // Outputs: X,XXX.YY format expected in PH invoices.

2.PHP时区设置为马尼拉时间:

3.PHP日志记录需包含完整事务详情以满足审计要求。

4.GDPR类似数据处理考虑因素(PDPA法律)。

5.SEC注册企业可能需要额外字段收集。

6.BIR税务计算规则集成建议。

7.Mobile-first优化特别重要(85%+PH用户通过手机购物)。

8.Lazada/Shopee流行度考量可能需要的特殊集成。

WooCommerce整合菲律宾支付的进阶实操步骤(续)

支付网关特定配置

GCash集成细节

  1. 获取API凭证

  2. Webhook设置

// 在functions.php中添加webhook处理器
add_action('woocommerce_api_wc_gcash_webhook', 'handle_gcash_callback');
function handle_gcash_callback() {
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_GCASH_SIGNATURE'];

// 验证签名示例:
$computed_signature = hash_hmac('sha256', $payload, SECRET_KEY);

if (hash_equals($signature, $computed_signature)) {
// 处理订单状态更新逻辑
wp_send_json_success(['status' => 'processed']);
} else {
wp_send_json_error(['error' => 'Invalid signature'], 403);
}
}

  1. 沙盒测试参数
测试号码: +6390512345678 
测试金额限制: ≤10,000 PHP
测试OTP: 123456

Dragonpay配置要点

  1. 特殊字段要求
// Dragonpay需要附加的账单字段:
add_filter('woocommerce_billing_fields', 'add_dragonpay_fields');
function add_dragonpay_fields($fields) {
$fields['billing_middle_name'] = array(
'label' => __('Middle Name', 'woocommerce'),
'required' => true,
'class' => array('form-row-wide')
);

return apply_filters('ph_billing_fields',$fields);
}

  1. 银行转账处理流程
Dragonpay特有流程需包含以下步骤:
1. [客户选择银行] →
2. [生成虚拟账户] →
3. [等待资金到账确认] →
4. [自动回调通知]
超时设置建议:24-48小时(PH银行清算周期较长)

OTC支付方案集成(适用于7-Eleven等)

1.PHP生成付款条码

function generate_payment_reference($order_id) {
return strtoupper(
substr(hash('sha256', NONCE_SALT . time()),0,12).'-'.
str_pad($order_id %9999,4,'0',STR_PAD_LEFT)
);
}

// PDF收据模板示例使用TCPDF库:
$pdf->write2DBarcode(
'$refNum|$amount|$dueDate',
'PDF417,,5',
'', '',40,15,
);

PHP性能优化建议

1.交易缓存策略

wp_cache_add("ph_trans_{$txnId}", [
"status" => "pending",
"last_check" => time(),
], "", CACHE_EXPIRE_SECONDS);

// CRON任务检查未完成交易:
if (defined('WP_CLI')) {
WP_CLI::add_command(‘check-ph-payments’, function(){
// Batch query payment provider API...
});
}

2.数据库索引优化
确保wp_postmeta表中菲律宾交易的元数据有适当索引:

ALTER TABLE `wp_postmeta` ADD INDEX `ph_payment_idx` (`meta_key`,`meta_value`(20));
-- meta_key应包含'_transaction_id','_payment_method'

BSP合规性增强措施

1.反洗钱(AML)检查层:

interface AMLCheckerInterface {   
public function screenCustomer(WC_Customer $customer): bool;
}

class PHAMLChecker implements AMLCheckerInterface {
const RESTRICTED_NAME_MATCHES = ['/dela cruz/i']; //示例过滤规则

public function screenCustomer(WC_Customer $customer){
foreach(self::RESTRICTED_NAME_MATCHES as $pattern){
if(preg_match($pattern,$customer->get_last_name())){
throw new AMLException("Potential restricted name match");
}
}

/* Additional checks... */
}
}

需要继续深入哪个具体环节?例如:

[ ] Lazada钱包的特殊集成方式
[ ] ShopeePay的技术实现细节
[ ] BIR税务计算的具体代码范例

# WooCommerce整合菲律宾支付的深度优化与特殊场景处理

Lazada钱包集成专项方案

1. LazPay商户接入流程
– 注册Lazada卖家中心 (sellercenter.lazada.com.ph)
– 申请开通LazPay服务(需提供BIR注册证明)
– 获取API凭证:
“`bash
# API认证示例(使用Lazada Open Platform签名机制)
$signature = hash_hmac(‘sha256’, $requestBody, $apiSecret);
$headers = [
‘Authorization: lazada ‘.$apiKey.’-‘.$signature,
‘Content-Type: application/json’
];
“`

2. PHP异步通知处理
“`php
// Lazada支付回调验证器
class LazadaPaymentValidator {
const ALLOWED_IPS = [‘203.177.42.0/24′,’118.107.44.0/24’];

public function verifyRequest() {
if(!$this->isValidIP($_SERVER[‘REMOTE_ADDR’])) {
throw new SecurityException(‘IP not whitelisted’);
}

$receivedSign = $_SERVER[‘HTTP_X_LAZADA_SIGNATURE’];
$computedSign = base64_encode(hash_hmac(
‘sha256’,
file_get_contents(‘php://input’),
LAZADA_CALLBACK_KEY,
true
));

return hash_equals($receivedSign, $computedSign);
}

private function isValidIP($ip) { /* CIDR检查实现… */ }
}
“`

ShopeePay技术实现细节

1. SPay商户配置要点
| 参数 | PHP常量定义建议 | BSP要求 |
|——|——————|———|
| MerchantID | `SHOPEE_MERCHANT_ID` | 必须显示在收据 |
| StoreID | `SHOPEE_STORE_ID` | OTC付款必填 |
| PartnerKey | `define(‘SHOPEE_HMAC_KEY’,…)` | AES-256加密 |

2. QR支付生成代码
“`php
function generateShopeeQRCode(WC_Order $order) {
require_once ABSPATH . ‘includes/vendor/endroid/qr-code/src/Builder.php’;

// PH格式金额:去除千分位逗号但保留两位小数
$amountFormatted = number_format($order->get_total(),2,”,”);

// Shopee Payload规范:
$payload = json_encode([
“paymentType” => “PAY_NOW”,
“currency” => “PHP”,
“merchantExtId” => SHOPEE_MERCHANT_ID,
“storeExtId” => SHOPEE_STORE_ID,
“amount” => (float)$amountFormatted,
“referenceId” => (string)$order->get_id()
]);

return (new QrCodeBuilder())
->size(300)
->margin(10)
->errorCorrectionLevel(ErrorCorrectionLevel::HIGH)
->data(“shopeepay://pay?”.http_build_query([‘payload’ => encryptPayload($payload)]))
->build();
}

// BSP要求的AES-GCM加密:
function encryptPayload(string $data): string { /* openssl实现… */ }
“`

BIR税务计算合规实现

VAT/Sales税计算模块(PHP)

a) Tax Class初始化
“`php
add_filter(‘woocommerce_product_get_tax_class’, function($tax_class, $_product){
if(isPHCustomer()) { //根据客户IP/billing地址判断

// PH特定商品分类税率规则:
switch($_product->get_category_ids()[0] ?? null){
case FOOD_CATEGORY_ID: return ‘PH-VAT-EXEMPT’;
case LUXURY_CATEGORY_ID: return ‘PH-VAT12%’;
default: return apply_filters(‘ph_default_tax_class’,’PH-VAT12%’);
}
}
return apply_filters_deprecated(…);
},10,2);
“`

b) Receipt Generator增强版

“`twig {hl_lines=”5-7″}
{# templates/ph-receipt.twig #}

{% block tax_rows %}
{% for tax in order.get_tax_totals() %}

{{ tax.label }}
BIR TIN: {{ shop.tin_number }} {{ tax.formatted_amount }}

{% endfor %}

VAT included where applicable per R.A.No10963

{% endblock %}
“`

GCash退款特殊处理流程

1.部分退款限制:
“`sql
— WordPress数据库需要扩展存储字段:
ALTER TABLE wp_wc_gcash_transactions ADD COLUMN partial_refund_id VARCHAR(32);
UPDATE wp_postmeta SET meta_key=’_gcash_refundable_amount’ WHERE meta_key LIKE ‘%refund%’;
“`

2.PHP自动冲正逻辑:

“`php
class GCashRefundProcessor {

const MAX_RETRIES=3;
const RETRY_DELAY=3600; //符合BSP的清算周期

public function processRefund(WC_Order $order,$amount,$reason){

if(!$this->isRefundable($order)){/* … */}

try{
for ($i=0;$iconvertToCentavos($amount),
memo:”REFUND#{$order->id}:”.substr(sanitize_text_field($reason),100)
)){ break; }
}

do_action(‘ph_payment_refunded’,$responseData);

update_post_meta(
order_id:’transaction_status’,
meta_value:sprintf(‘%s→REFUNDED@%s’,$oldStatus,date_i18n(DATE_W3C))
);

wc_create_refund([/* WooCommerce标准参数*/]);

} catch(Exception e){ /* … */}
}

private function convertToCentavos(float phpAmount): int{/* x100取整逻辑 */}
}
“`

下一步需要重点探讨的方向:

[ ] PesoNet/Direct Debit的银行直连方案
[ ] SMS支付提醒的本地运营商集成(Globe/Smart)
[ ] COD现金收款的电子化对账系统