Klevr Product Documentation logo

Payment Metadata

Klevr Portal – Dynamics 365 Customer Engagement

💳 Payment Metadata Feature

Klevr Portal – Dynamics 365 Customer Engagement

📌 Overview

The Payment Metadata Feature allows administrators to configure how data from Dynamics 365 CE is mapped into metadata sent to external payment gateways such as Stripe and Payfurl.

This is achieved through a configurable Environment Variable, enabling:

  • Dynamic metadata enrichment without code changes
  • Flexible fallback logic
  • Support for lookup traversal
  • Hard-coded metadata values

⚙️ Configuration

Environment Variable

SolutionKlevr Portal
Nameklevr_PaymentToGatewayMetadataMap
TypeJSON KVP (e.g. {"x":"y", "z":"a"} )

📍 Location

1
Open the solution

Navigate to Solutions → Klevr Portal

2
Open Environment Variables

Open Environment Variables

3
Locate the variable

Locate klevr_PaymentToGatewayMetadataMap

4
Set the value

Set the Current Value

🧱 JSON Structure

The configuration must be a JSON Dictionary:

Definitions

metadataKey : Name of the metadata field sent to the payment gateway

valueSource: Dynamics field path OR hard-coded value

🔁 Mapping Behaviour

✅ 1. Direct Field Mapping

Fields are sourced from the payment record

  • Retrieves value from the name field
  • Assigns it to metadata key m1

🔗 2. Lookup Traversal (Dot Notation)

Starting point is the payment record

Process:

  1. klevr_contactid → lookup field
  2. Retrieve related record
  3. emailaddress1 → field on that record

🔄 3. Recursive Lookup Traversal

Supports multi-level lookups:

Each segment is processed sequentially.

⚠️ 4. Null Handling

A mapping is ignored if any of the following occurs:

  • Field is not a lookup where expected
  • Lookup field has no value
  • Related record cannot be retrieved
  • Final field value is null or empty

🔄 Fallback Logic (Multiple Mappings)

You can define multiple mappings for the same metadata key.

📘 Example

Evaluation Order

  1. Try name
  2. If null → try amount
  3. If null → use 'blank'

🧩 Hard-Coded Values

If the value is wrapped in single quotes, it is treated as a constant.

Behaviour

  • No field lookup is performed
  • Value is inserted directly
  • Quotes are not included in final output

📘 Full Example

Field names below are mostly ficticious and you should verify the correct schema names for your fields

✅ Result

CustomerEmail:

  1. Contact email
  2. Account email
  3. Fallback to "unknown"

Reference:

  1. Invoice number from associated gif (if it is associated to a gift)
  2. Fallback to "no-ref"

🚫 Reserved Metadata Fields

The following keys are system-controlled and cannot be overridden:

  • TransactionId
  • CustomerId

⚠️ Any mappings configured for these keys will be ignored

🔁 Processing Logic Summary

For each metadata key:

  1. Iterate mappings in order
  2. Evaluate value (field or literal)
  3. If valid → assign and stop
  4. If invalid → continue
  5. If none valid → key not included

✅ Best Practices

✔️ Prioritise Likely Fields First

Improves performance and clarity

✔️ Always Include a Fallback

✔️ Keep Mappings Readable

Avoid overly deep lookup chains where possible

You could use powerfx columns to surface lower level data upwards too

✔️ Validate Schema Names

Ensure:

  • Correct logical names
  • Relationships exist
  • Fields are accessible

✔️ Test End-to-End

Confirm metadata is correctly sent to:

  • Stripe
  • Payfurl

🛠 Troubleshooting

IssueCause
Metadata missingAll mappings returned null
Incorrect valueInvalid field name
Lookup failedEmpty or invalid lookup
JSON errorInvalid syntax

🧾 Summary

The Payment Metadata Feature provides a flexible, configuration-driven approach to enriching payment transactions with contextual Dynamics 365 data.

Key Capabilities

  • JSON-based configuration
  • Lookup traversal with dot notation
  • Fallback prioritisation
  • Hard-coded values
  • No-code extensibility

Last updated on