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
Alright, so, I contacted Opayo myself to see what the
Mapping
was for theReference
column on the Opayo website and what data that is sent to the API is mapped to thatReference
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:
woocommerce-gateway-sagepay-form
Pluginwoocommerce-gateway-sagepay-form/classes/direct/sagepay-direct-request-class.php
fileI then scrolled to
Line 335
inside of the$end
array, I then added the field ofVendorData
as seen by the code below:And then set the
#######
to the Value I needed to send to Opayo to show in theReference
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:Saving this, then when an Order / Purchase was made, the
Reference
field on Opayo's website was populated with what I set theVendorData
to.Quick Note: The
VendorData
field is max of 200 characters and onlyAa
or0-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!
First you mot use
$order->get_order_number()
when trying to get order meta data but use$order->get_id()
withget_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):
or using
get_post_meta()
function:It could better work…