我目前正在建立一个电子商务网站,用于5家使用woocommerce和authorize.net
付款的独立公司。
到目前为止,授权对于单个供应商来说效果很好,问题是一旦我按位置选择了供应商,我需要在处理付款之前将api_transaction_key
和api_login_id
更改为正确的供应商。
我已经搜索文件几个小时了,找不到设置密钥和 id 的位置。
有人可以帮助我找到可以将键和 id 值覆盖到我需要的位置吗?还是为每个供应商创建一个新的支付网关并复制除密钥和ID之外的所有authorize.net
网关信息会更好?
如果有人对我如何能够完成这项工作感到好奇,这个答案就在这里。
在 Authorize.net WooCommerce支付网关中,您会找到一个名为
正是class-wc-authorize-net-cim-api.php
在这个文件的构造函数中,你的钩子需要被放置。
public function __construct( $api_user_id, $api_transaction_key, $environment ) {
// File default code
}
这需要将以下三行代码放在默认文件代码之前
$custom_auth_info = apply_filters('get_custom_auth', $custom_auth_info ); $api_user_id = $custom_auth_info['api_user_id']; $api_transaction_key = $custom_auth_info['api_transaction_key'];
apply_filters是指放置在我的插件中的以下函数
add_filter('get_custom_auth', 'select_distributor_by_state');
function select_distributor_by_state($custom_auth_info = []) {
global $wpdb;
//Your Query is here to select the proper distributor from the DB
//and retrieve their custom Authorize.net ID and Transaction Key
$custom_auth_info['api_user_id'] = $your_query[0]['api_loginid'];
$custom_auth_info['api_transaction_key'] = $your_query[0]['api_transactionkey'];
$_SESSION['dealer'] = $vendor[0]['id'];
return $custom_auth_info;
}
此过滤器允许您挂钩,获取所需的数据,然后将其返回并在处理付款之前直接应用于代码中。