skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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!


  2. First you mot use $order->get_order_number()when trying to get order meta data but use $order->get_id() with get_post_meta() function instead.

    Now you can also use the WC_Data method get_meta() to be used on $order object variable.

    What you need to find out is the key slug that you need to use to incorporate that custom field value to the vendor data via opayo_direct_custom_field_vendordata filter hook.

    Try the following (where I use ‘reference’ as key slug, to be replaced with the right slug):

    add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );
    
    function my_opayo_direct_custom_field_vendordata ( $vendor_data, $order ) {
        $reference = $order->get_meta('_reference_field');
    
        if ( ! empty($reference) ) {
            $vendor_data['reference'] = $reference;
        }
        
        return $vendor_data;
    }
    

    or using get_post_meta() function:

    add_filter( 'opayo_direct_custom_field_vendordata', 'my_opayo_direct_custom_field_vendordata', 10, 2 );
    
    function my_opayo_direct_custom_field_vendordata ( $vendor_data, $order ) {
        $reference = get_post_meta($order->get_id(), '_reference_field', true);
    
        if ( ! empty($reference) ) {
            $vendor_data['reference'] = $reference;
        }
        
        return $vendor_data;
    }
    

    It could better work…

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search