Php 我的WooCommerce插件回调函数在wc更新后停止工作
TL;运行同名类的DR WooCommerce回调url已中断。就像我可以通过进入Php 我的WooCommerce插件回调函数在wc更新后停止工作,php,woocommerce,wordpress,Php,Woocommerce,Wordpress,TL;运行同名类的DR WooCommerce回调url已中断。就像我可以通过进入http://mywebsite.com/wc-api/valitorcallback,是否有办法启用该url或以某种方式访问此类 我开发了一个WooCommerce支付网关插件,可以连接到类似冰岛paypal的Valitor公司 付款流程很简单: 客户将商品添加到他的购物车中,然后去结帐 将网络商店的客户重定向到Valitor,请求参数中包含订单信息 顾客用信用卡或借记卡付款 客户被重定向到提供的感谢页面,Val
http://mywebsite.com/wc-api/valitorcallback
,是否有办法启用该url或以某种方式访问此类
我开发了一个WooCommerce支付网关插件,可以连接到类似冰岛paypal的Valitor公司
付款流程很简单:
<?php
function initWooCommerceValitorGatewayPlugin()
{
class WooCommerceValitorGateway extends WC_Payment_Gateway
{
public function __construct()
{
// ...Varible code...
// Actions
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
}
public function init_form_fields()
{
// ...Define settings code...
}
public function process_payment($orderId)
{
// ...Magic code...
// Redirect to Valitor with all necessary data
return array(
'result' => 'success',
'redirect' => add_query_arg($valitorData, $gatewayUrl)
);
}
// ...Helper functions code (like sending an email)...
}
}
class valitorcallback
{
public function __construct()
{
$this->verifyPayment();
}
public function verifyPayment()
{
// ...Verification code...
}
// ...Helper functions code (like sending an email)...
}
// Add plugin to wordpress/woocommerce
add_action('plugins_loaded', 'initWooCommerceValitorGatewayPlugin');
function addValitorGateway($methods)
{
$methods[] = 'WooCommerceValitorGateway';
return $methods;
}
// Add gateway method to woocommerce
add_filter('woocommerce_payment_gateways', 'addValitorGateway');
?>
<?php
function initWooCommerceValitorGatewayPlugin()
{
class WC_Valitor_Gateway extends WC_Payment_Gateway
{
public function __construct()
{
// ...Varible code...
// Actions
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
// Payment listener/API hook
add_action('woocommerce_api_wc_valitor_gateway', array($this, 'valitorcallback'));
}
public function init_form_fields()
{
// ...Define settings code...
}
public function process_payment($orderId)
{
// ...Magic code...
}
public function valitorcallback()
{
// ...Verification code...
}
// ...Helper functions code (like sending an email)...
}
}
// Add plugin to wordpress/woocommerce
add_action('plugins_loaded', 'initWooCommerceValitorGatewayPlugin', 0);
function addValitorGateway($methods)
{
$methods[] = 'WC_Valitor_Gateway';
return $methods;
}
// Add gateway method to woocommerce
add_filter('woocommerce_payment_gateways', 'addValitorGateway');
?>
现在您看到了函数名,也许可以告诉我应该将add_操作放在哪里
我知道mywebsite.com/wc-api/v3/。。。RESTAPI,但我希望我可以再次启用url,这样我就不必再次编写该部分代码,而且我不知道如何从另一个文件获取插件设置
谢谢,西格尔
编辑:添加TL;当我陈述问题时,DR部分位于顶部并以粗体显示。我找到了它,不知道为什么我没有找到它,除了我没有在谷歌上使用正确的搜索词 但事实是: 我不知道为什么文档中没有提到这一点,但这是您需要的动作挂钩:
// Payment listener/API hook
add_action('woocommerce_api_wc_valitor_gateway', array($this, 'valitorcallback'));
我需要将求和函数从第二个类移动到第一个类,然后使用正确的操作名称使其工作。它仍然返回-1
,但是使用url中的所有GET变量执行正确的代码
我还将类名更改为WC\u Valitor\u Gateway
,插件结构如下:
<?php
function initWooCommerceValitorGatewayPlugin()
{
class WooCommerceValitorGateway extends WC_Payment_Gateway
{
public function __construct()
{
// ...Varible code...
// Actions
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
}
public function init_form_fields()
{
// ...Define settings code...
}
public function process_payment($orderId)
{
// ...Magic code...
// Redirect to Valitor with all necessary data
return array(
'result' => 'success',
'redirect' => add_query_arg($valitorData, $gatewayUrl)
);
}
// ...Helper functions code (like sending an email)...
}
}
class valitorcallback
{
public function __construct()
{
$this->verifyPayment();
}
public function verifyPayment()
{
// ...Verification code...
}
// ...Helper functions code (like sending an email)...
}
// Add plugin to wordpress/woocommerce
add_action('plugins_loaded', 'initWooCommerceValitorGatewayPlugin');
function addValitorGateway($methods)
{
$methods[] = 'WooCommerceValitorGateway';
return $methods;
}
// Add gateway method to woocommerce
add_filter('woocommerce_payment_gateways', 'addValitorGateway');
?>
<?php
function initWooCommerceValitorGatewayPlugin()
{
class WC_Valitor_Gateway extends WC_Payment_Gateway
{
public function __construct()
{
// ...Varible code...
// Actions
add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
// Payment listener/API hook
add_action('woocommerce_api_wc_valitor_gateway', array($this, 'valitorcallback'));
}
public function init_form_fields()
{
// ...Define settings code...
}
public function process_payment($orderId)
{
// ...Magic code...
}
public function valitorcallback()
{
// ...Verification code...
}
// ...Helper functions code (like sending an email)...
}
}
// Add plugin to wordpress/woocommerce
add_action('plugins_loaded', 'initWooCommerceValitorGatewayPlugin', 0);
function addValitorGateway($methods)
{
$methods[] = 'WC_Valitor_Gateway';
return $methods;
}
// Add gateway method to woocommerce
add_filter('woocommerce_payment_gateways', 'addValitorGateway');
?>
我没有答案,但我会从WooCommerce如何处理开始,非常感谢@helgatheviking的链接。虽然我没有看到add_操作代码,但我发现了一些有用的东西和合适的搜索词。非常感谢您的反馈。既然valitorcallback()函数没有传入任何参数,我们如何访问传递/发布到回调URL的数据?伙计,已经好多年了。关于如何访问POST参数的问题仍然没有回答。@frostshoxx参数将取决于其他网站/服务如何调用回调URL。如果它确实执行POST请求,您将可以通过POST字段进行访问。@IvRRimUm这将完全取决于其他服务器如何访问您的回调方法。如果他们向您发送$\u POST
请求,您可以像往常一样从$\u POST['some\u value']
获取值。如果它们发送更复杂的数据,您可能需要使用来获取输入数据并根据需要对其进行解析。