1

我已经使用 Wordpress 5.0.3 和最新的 WC 和 WC Eway 插件(WooCommerce eWAY 网关)设置了一个新的 docker 容器。

用一些产品创建了一个商店,连接了我的 Eway 沙盒环境,启用了 Save Cards(这将启用令牌)并创建了一个订单。在我的数据库中检查了 post_meta 的订单后,我没有看到一个_eway_token_customer_id字段。在以客户身份登录时,我再次尝试了新订单,但我仍然没有得到令牌。

进行此测试的原因是我在真实的新网站中遇到了这种奇怪的行为,其中新客户的第一个订单不会产生令牌。但是,当我在登录时创建第二个订单时,我确实_eway_token_customer_idorder_meta.

我必须在第一次订购时获得该代币,因为之后我将使用代币支付选项自动更新产品。

调试这个问题是地狱,我发现在我全新的 WP 安装中我根本没有得到任何令牌,这非常令人不安。

有没有人有一个好主意?

**更新在Eway插件中进行了一些挖掘之后,我发现我第一次下订单时,request_access_code()该类的函数WC_Gateway_EWAY 正在检查数据库中是否有该用户的令牌。

函数体:

protected function request_access_code( $order ) {

        $token_payment = $this->get_token_customer_id( $order );

        if ( $token_payment && 'new' === $token_payment ) {
            $result = json_decode( $this->get_api()->request_access_code( $order, 'TokenPayment', 'Recurring' ) );
        } elseif ( 0 === $order->get_total() && 'shop_subscription' === ( version_compare( WC_VERSION, '3.0', '<' ) ? $order->order_type : $order->get_type() ) ) {
            $result = json_decode( $this->get_api()->request_access_code( $order, 'CreateTokenCustomer', 'Recurring' ) );
        } else {
            $result = json_decode( $this->get_api()->request_access_code( $order ) );
        }

        if ( isset( $result->Errors ) && ! is_null( $result->Errors ) ) {
            throw new Exception( $this->response_message_lookup( $result->Errors ) );
        }

        return $result;

    }

该函数处理三种可能的结果:

1) new customer: results in calling `$this->get_api()->request_access_code( $order, 'TokenPayment', 'Recurring' )` <-- this is the one we are after!

2) shop_subscription: calls `$this->get_api()->request_access_code( $order, 'CreateTokenCustomer', 'Recurring' )`

3) else..: calls `$this->get_api()->request_access_code( $order )`

调试期间发生的情况是,该$token_payment变量具有新客户的空字符串值,而不是new. 因此,我将尝试通过过滤器/操作挂钩来解决此问题,或者找出发生这种情况的原因。

当我强制该函数始终使用第一个if块时,我得到了我的令牌。:)

**更新 2:我使用现有用户帐户进行了测试,创建了一个新订单。当我查看post_meta表格时: 在此处输入图像描述 瞧,new价值是存在的。

但是,当我未登录并创建帐户时,new不会添加该值,这就是出错的地方。

临时修复将是使用钩子并将new值添加到订单中,以便在get_token_customer_id调用时检索一个new值而不是空字符串。

我认为这是一个错误,因为应该添加这个值。它解释了为什么第二个交易获得令牌而不是第一个。

如果只有 Woocommerce Eway 插件有一个 git repo....我可以标记一个问题或分叉它。

***没有破解的解决方案将此添加到我的插件(或functions.php,如果你喜欢):

add_action( 'woocommerce_checkout_order_processed', function( $order_id, $posted_data, $order ) {
            update_post_meta( $order_id, '_eway_token_customer_id', 'new' );
        }, 10, 3);

当您与不存在的用户结帐时,这将添加新值。添加我的信用卡详细信息后,令牌被很好地添加了。

事实是该插件仍然存在错误,您可以解决该错误。

4

0 回答 0