WooCommerce Eway插件未为新客户创建客户令牌

时间:2019-01-26 11:31:52

标签: wordpress woocommerce eway

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

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

进行此测试的原因是,我在真实的新网站中遇到了这种奇怪的行为,在该网站中,新客户的第一笔订单未产生令牌。 但是,当我在登录时创建第二个订单时,确实在_eway_token_customer_id中得到了一个order_meta值。

对我来说,必须首先获得该令牌,因为在此之后,我将使用tokenpayy选项自动更新产品。

调试此问题很麻烦,我感到非常不安的是,在全新的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表时: enter image description here 瞧,new值存在。

但是,当我没有登录并创建帐户时,new值不会添加,这就是问题所在。

一个临时解决方法是使用一个钩子并将new值添加到顺序中,以便在调用get_token_customer_id时它检索一个new值而不是一个空字符串。 / p>

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

如果只有Woocommerce Eway插件具有git存储库...。我可以标记问题或将其分叉。

***没有黑客的解决方案 将此添加到我的插件(如果需要,也可以添加到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);

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

事实上,插件仍然存在一个错误,您可以解决该问题。

0 个答案:

没有答案
相关问题