Woocommerce &opayo:给发送给API的数据添加自定义字段 [英] Woocommerce & Opayo: Add a custom field to the data sent to the API

查看:11
本文介绍了Woocommerce &opayo:给发送给API的数据添加自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

非常具体的问题,但是,在我们使用 Opayo 插件(用于 Opayo Direct)的 Wordpress/Woocommerce 网站上,我被拖到了我们公司支付网关的问题上.

问题是:

  • 最初设置时,没有为发送到 API 的数据/对象上的 Reference 字段选择模板/选项

最初做网站的人然后尝试联系这个现在不受支持的插件的原始开发者,他们被发送了一些代码以放入另一个名为 PHP Injection 的插件中,代码类似于以下:

add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );函数 my_opayo_direct_custom_field_vendordata ( $vendordata, $order ) {//获取订单ID$order_id = $order->get_order_number();$reference = "test_";.$order_id;//获取参考字段 - 将_reference_field"设置为您订单中的 meta_keyif( isset( get_post_meta( $order_id, '_reference_field', TRUE ) ) ) {$vendordata = get_post_meta( $order_id , '_reference_field', TRUE );//$vendordata['_reference_field'] = $reference;###评论,因为我不确定这是否正确}返回 $vendordata;}

在进行了大量测试和小的更改后,Opayo 本身的 Reference 字段中似乎仍然没有显示任何内容?

请告诉我之前有人遇到过这种情况或知道我可能遗漏了什么,我已经有一段时间没有接触 PHP

解决方案

好吧,所以,我自己联系了 Opayo 以查看 MappingReference 列的内容Opayo 网站以及发送到 API 的数据映射到表中的 Reference 列.

显然发送到 API 对应的值是 VendorData(不需要,200 个字符限制,自由文本)

所以,为了解决这个问题,我不得不:

  1. 在 Wordpress 上打开插件编辑器
  2. 选择woocommerce-gateway-sagepay-form插件
  3. 导航并选择 woocommerce-gateway-sagepay-form/classes/direct/sagepay-direct-request-class.php 文件

然后我滚动到 $end 数组内的 Line 335,然后我添加了 VendorData 字段,如下面的代码所示:

 $end = array(客户电子邮件"=>$order->get_billing_email(),客户端IP地址"=>$this->get_ipaddress(),帐户类型"=>$this->accounttype,ReferrerID"=>$this->referred,网站"=>site_url(),供应商数据"=>'#######',地穴"=>MD5( $this->open_salt . $order->get_order_key() . $this->close_salt ),);

然后将 ####### 设置为我需要发送给 Opayo 以显示在支付表中的 Reference 列中的值.>

然后只是为了确保它不会被修剪(再次,有一段时间没有接触 PHP,我去了(现在)Line 378 并将其注释掉,见下文:

//可自定义的字段$end['TransType'] = apply_filters('opayo_direct_custom_field_transtype', '01', $order );//$end['VendorData'] = apply_filters('opayo_direct_custom_field_vendordata', '', $order );

保存此内容,然后在进行订单/购买时,Opayo 网站上的 Reference 字段将填充我将 VendorData 设置为的内容.

快速说明:VendorData 字段最多 200 个字符,并且只有 Aa0-9,当我尝试使用 _ 时,我有几次失败的尝试,直到我搜索了在此页面上收到的错误:

https://www.opayo.co.uk/support/error-codes?keyword=3189


我希望我的问题和解决方案对未来的人有所帮助,并为我浪费了任何人的时间感到抱歉!

Very specific issue but, I've been dragged onto an issue with our companies Payment Gateway on our Wordpress / Woocommerce website where we are using the Opayo Plugin (For Opayo Direct).

The issue is:

  • When originally setup, there was no template / option selected for the Reference field on the data / object sent to the API

The guys originally doing the website then tried contacting the original developer of this now unsupported plugin to which they was sent some code to put into another plugin named PHP Injection the code was similar to below:

add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );

function my_opayo_direct_custom_field_vendordata ( $vendordata, $order ) {

    // Get Order ID
    $order_id = $order->get_order_number();
    $reference = "test_" . $order_id;

    // Get the reference field - set '_reference_field' to the meta_key from your order
    if( isset( get_post_meta( $order_id, '_reference_field', TRUE ) ) ) {
        $vendordata = get_post_meta( $order_id , '_reference_field', TRUE );
        //$vendordata['_reference_field'] = $reference; ### Commented as I'm unsure if this is correct
    }
    
    return $vendordata;
}

After doing numerous testing and small changes, still nothing seems to be showing up in the Reference field in Opayo itself?

Please tell me someone has encountered this situation before or knows what I might be missing, it's been a while since I've touched PHP

解决方案

Alright, so, I contacted Opayo myself to see what the Mapping was for the Reference column on the Opayo website and what data that is sent to the API is mapped to that Reference column in the table.

Apparently the value sent to the API that corresponds to this is the VendorData (Not required, 200 Char limit, free-text)

So, to fix this, I had to:

  1. Open the Plugin Editor on Wordpress
  2. Select the woocommerce-gateway-sagepay-form Plugin
  3. Navigate and select the woocommerce-gateway-sagepay-form/classes/direct/sagepay-direct-request-class.php file

I then scrolled to Line 335 inside of the $end array, I then added the field of VendorData as seen by the code below:

            $end = array(
                "CustomerEMail"     =>  $order->get_billing_email(),
                "ClientIPAddress"   =>  $this->get_ipaddress(),
                "AccountType"       =>  $this->accounttype,
                "ReferrerID"        =>  $this->referrerid,
                "Website"           =>  site_url(),
                "VendorData"        =>  '#######',
                "Crypt"             =>  MD5( $this->open_salt . $order->get_order_key() . $this->close_salt ),
            );

And then set the ####### to the Value I needed to send to Opayo to show in the Reference column in the payments table.

Then just to be sure it wasn't going to get pruned (Again, not touched PHP for a while, I went to (NOW) Line 378 and commented it out, see below:

// Customiseable fields
            $end['TransType'] = apply_filters( 'opayo_direct_custom_field_transtype', '01', $order );
            //$end['VendorData'] = apply_filters( 'opayo_direct_custom_field_vendordata', '', $order );

Saving this, then when an Order / Purchase was made, the Reference field on Opayo's website was populated with what I set the VendorData to.

Quick Note: The VendorData field is max of 200 characters and only Aa or 0-9, I had a couple of failed attempts when I was trying to have _ until I searched the error I received on this page:

https://www.opayo.co.uk/support/error-codes?keyword=3189


I hope that my issue and resolution helps someone in the future and sorry for anyone's time I wasted!

这篇关于Woocommerce &opayo:给发送给API的数据添加自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆