Adding custom metadata to payments

What is the use case?

Let’s say you’re working with affiliates to send prospects to your payment page.

Affiliates send you traffic which includes an affiliate ID in a URL parameter, like this:



You’d need to save the affiliate id as metadata of the payment, so that you can identify payments for which you have to pay an affiliate fee.

How to implement it

If you’d like to add metadata via URL parameters, then you have to do the following:

  1. Pass metadata in URL parameter(s) to the payment page.
  2. Implement a Wordpress filter that processes the URL parameter(s), and add them as metadata. 

    (Example implementation provided below)

The following subsections explain these steps in detail.

1) Pass metadata in URL parameters

Add the metadata as URL parameters. In the example below, the affiliate id is passed in the affidURL parameter to any page: 

https://ExampleDomain.com/sell-recurring-services-inline/?wpfsPlan=price_1JmD2iKit80XPxkD8jLNNvVM

2) Implement a Wordpress filter to process the URL parameter

For the sake of security, the plugin doesn’t let anyone set metadata directly without your consent.

You can give consent by implementing a short piece of code in the form of a WordPress filter, which picks URL parameters and adds them as metadata. The code needs to be added to the functions.php file of your active Wordpress theme.

Here is an example implementation, see description below:


/**
 * Example implementation of the 'fullstripe_add_transaction_metadata' Wordpress filter 
 * for WP Full Stripe.
 *
 * @param $metadata    Associative array of metadata set by a previous filter instance
 * @param $formName    Name of the form that triggered the filter
 * @param $pageParams  Associative array of page URL parameters
 *
 * @return Associative array of metadata to be added to the transaction
 */

function set_affiliate_metadata($metadata, $formName, $pageParams) {
	$result_meta = is_null($metadata) ? array() : $metadata;

	if (array_key_exists('affid', $pageParams)) {
		$result_meta['affid'] = $pageParams['affid'];
 	}

 	return $result_meta;
}

add_action('fullstripe_add_transaction_metadata', 'set_affiliate_metadata', 10, 3);

In the example above, the code checks whether the $pageParams array contains the affidparameter, and if it does then adds it to the $result_meta array which contains the metadata to be added to the transaction.

Where are metadata on the Stripe dashboard?

Depending on your form type, metadata is saved into different Stripe items.

Please refer to our knowledge base article on where are custom fields on the Stripe dashboard, which explains it in detail (custom fields are also saved as metadata).

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us