Extra Merchant Data (EMD)
Last modified:
Use the example below to add an attachment (often referred to as Extra Merchant Data, EMD) to the request body when creating or updating a Klarna Payments session.
Extra Merchant Data allows you to send additional structured information to Klarna, such as industry-specific data (for example travel, tickets or other regulated verticals). In some cases, this data is required for certain Klarna products or markets.
Note: The code below is provided as an example only and should not be used in production as-is.
You must adjust the data structure, attachment type, and content to match your specific use case and Klarna’s API requirements.
Important
- The structure of the attachment must follow Klarna’s API specification.
- The
content_typemust match the type of data you are sending. - Invalid or incorrectly formatted EMD data will result in API validation errors.
You can find more information about this here: https://docs.klarna.com/api/payments/#operation/createCreditSession
/**
* Example code for how to add EMD to the KP request args.
* Please check https://docs.klarna.com/api/payments/#operation/createCreditSession for the exact attachment you need.
* This is only an example code, you might need to change some of the data or logic based on your own needs.
*/
add_filter( 'wc_klarna_payments_create_session_args', 'kp_add_emd' );
add_filter( 'wc_klarna_payments_update_session_args', 'kp_add_emd' );
/**
* Adds EMD to the request args sent to Klarna.
*
* @param array $request_args The KP Request arguments.
* @return array
*/
function kp_add_emd( $request_args ) {
$body = json_decode( $request_args['body'], true );
$emd_data = array(
'product_category' => 'Fashion',
'product_name' => 'Women Sweatshirt',
);
$emd_data = array( $emd_data );
$emd = array(
'content_type' => 'application/vnd.klarna.internal.emd-v2+json',
'body' => wp_json_encode(
array( 'marketplace_seller_info' => $emd_data )
),
);
$body['attachment'] = $emd;
$request_args['body'] = wp_json_encode( $body );
return $request_args;
}Adding the code
There are several ways to add code to your site, a couple of examples are:
- Code snippets
- Modify the theme’s
functions.phpfile or include it in a separate functionality plugin.
Please note that we at Krokedil do not offer support for third party plugins.