Title: Creating a Merchant Reference
Last modified: August 21, 2016

---

# Creating a Merchant Reference

 *  Resolved [cbfuk](https://wordpress.org/support/users/cbfuk/)
 * (@cbfuk)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/)
 * Hi
 * We’re having some trouble setting a dynamic value into a hidden field which we
   can map onto the DPS Merchant Ref.
 * I’ve seen some comment elsewhere about setting a default value , or the form 
   Id, or something else relatively static (and we can do that OK). However, the
   DPS spec actually requires that the merchant ref be unique (and I’ve run into
   trouble in the past trying to use a non-unique value).
 * I’ve created a filter to generate a unique 16-char string from the Entry ID field
   and return that into the field which is mapped to the PxPay merchant Ref parameter–
 * add_filter(‘gform_save_field_value’, ‘wired_set_merchant_ref’, 10, 4);
    function
   wired_set_merchant_ref($value, $entry, $field, $form) { if ( DPS_MERCHANT_REF_FIELD_LABEL!
   = $field[‘label’] ) return $value; // OK, DPS ref field – create unique ref $
   ref = str_pad($entry[‘id’], 16, ‘0’, STR_PAD_LEFT); return $ref; }
 * The function works fine and generates a valid code, but it doesn’t seem to get
   picked up by the plugin – when we reach the DPS payment form, the default value
   is displayed and not the value we’ve created.
 * Am I using the wrong WP function to set this, or in the wrong way? Do I maybe
   need a different priority to get in before your filters attach? Or is it just
   not possible – do you assume the value is static and get it before filters are
   run?
 * Any advice would be appreciated!
 * Many thanks for a great plugin.
 * Cheers
    Colin
 * [http://wordpress.org/extend/plugins/gravity-forms-dps-pxpay/](http://wordpress.org/extend/plugins/gravity-forms-dps-pxpay/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706910)
 * G’day Colin,
 * Firstly, the Merchant Reference doesn’t need to be unique. It’s a reference for
   the merchant, not a transaction ID. You can make it unique, or use a unique reference
   you already have, of course. What should be unique (if you need to query it later,
   which this plugin doesn’t allow anyway) is the Transaction Number. This plugin
   sets that to the Gravity Forms lead ID.
 * Now, you’re setting the hidden merchant reference field on save, which happens
   after the form data is grabbed for the payment. You should be setting it pre-
   render so that it’s available as form data when the payment occurs. You can do
   that via the [gform_pre_render](http://www.gravityhelp.com/documentation/page/Gform_pre_render)
   filter hook, or more easily by using [dynamic population](http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population)
   with a filter hook.
 * cheers,
    Ross
 *  Plugin Author [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706911)
 * G’day again, Colin.
 * Just thinking some more: if you want to incorporate the lead ID into your merchant
   reference, you should probably set the field value on the [gform_confirmation](http://www.gravityhelp.com/documentation/page/Gform_confirmation)
   filter hook. I catch that hook at priority 1000, so if you use that hook with
   the default priority you’ll be able to set that field value before the transaction
   is processed.
 * cheers,
    Ross
 *  Thread Starter [cbfuk](https://wordpress.org/support/users/cbfuk/)
 * (@cbfuk)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706913)
 * Hi Ross
    Fantastic, many thanks for the quick response – I’ll have a go as you
   suggest and let you know what works best. Ah, I just dusted off my DPS spec and
   of course you’re right about Merchant Ref; what I was thinking of is TxnRef which
   is why I was constructing a 16-byte key in the first place :/ Duh… Yep, I guess
   so long as you set that to the Lead Id that is doing what I was trying to anyway!
   Cheers Colin
 *  Plugin Author [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706914)
 * No worries, let me know which way you end up going.
 * For other payment gateway plugins I’ve written, I’ve added filter hooks that 
   let you change the merchant reference and some other bits just before the payment
   is submitted. I’ll add that functionality to the next version of this plugin 
   too, which will make your job a little easier.
 * cheers,
    Ross
 *  Thread Starter [cbfuk](https://wordpress.org/support/users/cbfuk/)
 * (@cbfuk)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706974)
 * Hi Ross
    Yeh, a hook to set/override DPS parameters would be good tho given I
   was just being seriously stoooopid, not sure how much need there is to set MerchantRef
   dynamically. More useful would be a hook to let us set the TxnRef directly, as
   I can imagine situations where I would need/prefer to conform it with another
   UID scheme, for example if other DPS txns are being routed through a different
   area of the site which doesn’t use your plugin. Just out of interest, I had a
   quick go at hooking the MerchantRef change into gform_confirmation, but couldn’t
   get it to work – again, I was seeing the default value coming through. Probably
   just something I did wrong tho, anyway there’s probably no point in pursuing 
   it. Look forward to seeing any changes you make on setting the DPS parameters!
   Thanks again Cheers Colin
 *  Plugin Author [webaware](https://wordpress.org/support/users/webaware/)
 * (@webaware)
 * [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706975)
 * G’day Colin,
 * Yes, the transaction number will be one of the filtered settings. If you look
   at my [eWAY plugin for Gravity Forms](http://wordpress.org/extend/plugins/gravityforms-eway/),
   you’ll see that I allow most bits to be altered through filters. Next version,
   I promise!
 * For the attempt you made, I guess the problem was that I’m reading the form post
   values, and you’re setting the field values. You could set the form post values
   instead, but of course the next version will make all this unnecessary anyway.
 * cheers,
    Ross

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Creating a Merchant Reference’ is closed to new replies.

 * ![](https://ps.w.org/gravity-forms-dps-pxpay/assets/icon-256x256.png?rev=2590624)
 * [GF Windcave Free](https://wordpress.org/plugins/gravity-forms-dps-pxpay/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-dps-pxpay/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-dps-pxpay/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-dps-pxpay/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-dps-pxpay/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-dps-pxpay/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [webaware](https://wordpress.org/support/users/webaware/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/creating-a-merchant-reference/#post-3706975)
 * Status: resolved