【问题标题】:Alter authorize.net transaction key dynamically?动态更改 authorize.net 交易密钥?
【发布时间】:2015-01-05 22:26:12
【问题描述】:

我目前正在构建一个电子商务网站,该网站用于 5 家使用 woocommerce 和 authorize.net 付款的独立公司。

到目前为止,授权对单个供应商非常有效,问题在于,一旦我按位置选择了供应商,我需要在处理付款之前将 api_transaction_keyapi_login_id 更改为正确的供应商。

我已经搜索了几个小时的文件,但找不到 key 和 id 的设置位置。

有人可以帮我找到可以将键和 id 值覆盖为我需要的位置吗? 还是为每个供应商创建一个新的支付网关并复制除密钥和 ID 之外的所有 authorize.net 网关信息会更好吗?

【问题讨论】:

    标签: php wordpress woocommerce authorize.net


    【解决方案1】:

    如果有人对我是如何完成这项工作感到好奇,请提供此答案。
    在 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;
    }
    

    此过滤器允许您连接,获取您需要的数据,然后在处理付款之前将其返回并直接应用到代码中。

    【讨论】:

    • 我不喜欢这个解决方案,因为它需要修改插件的代码。每当更新插件时,这些更改都会丢失。理想情况下,我会寻找一种使用插件内置过滤器的解决方案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2015-01-23
    • 2011-03-29
    • 2012-04-14
    • 2011-05-13
    • 1970-01-01
    相关资源
    最近更新 更多