Managing Static Values
There is often a requirement to manage static values in your projects. Orchestration Components can be used for this purpose in Conscia. This recipe manages the Merchant Account identifier for the Adyen payment provider with this method.
Overall Orchestration Flow
You should use secrets to store values that should not be visible and are only available to Connections. If you try to use the secret() function to access secrets outside of the context of a Connection, you will receive an error "Callee is not a function", because secrets are only available to Connections. Instead of using secrets, you can use a Component to store static values used outside of the context of a Connection.
If you use a release management process to migrate elements from one Conscia environment to another, consider how you will manage secrets and other static values.
To optimize performance, you can cache the response of Components used to store static values.
Mapping Out DX Engine Components and Templates
Many Adyen Webservice APIs require a Merchant Account identifier in the JSON payload passed to the Webservice. You could specify the Merchant Account identifier in every component that invokes an Adyen Webservice. Alternatively, you can implement a Conscia Component to store that value and any other static values in your solution, or you can implement multiple Components for this purpose.
DX Engine Configuration Details
To create a Component to store static values, in the Conscia User Interface:
- Click Manage Experiences in the top navigation, and then click Components. The Manage Components page appears.
- Click Add Component.
- For Component Code, enter an identifier for the Component, such as static-values.
- For Component Name, enter a name for the Component, such as Static Values.
- Optionally, enter a Commponent Description.
- Select the No Rules checkbox.
- For Component Type, select Conscia - Object Mapper.
- Click Submit.
To configure the Component, in the Manage Components page of the Conscia User Intercace:
- Click the Edit button next to the component.
- For Response Transform, enter JavaScript such as the following:
_.assign({},{
"adyen":
{
"merchantAccount": "ConsciaECOM"
}
})
This code uses the assign() function in the Lodash library to create an empty object, and then adds the adyen/merchantAccount key set to the Adyen Merchant Account identifier.
The Component returns the resulting JSON as its response.
- Click Submit.
You can use the componentResponse() function to access values managed by this Component from other Components. The following example is a JS Expression used as the Body of a Component that calls an Adyen Webservice API.
_.assign({},{
"merchantAccount": componentResponse('static-values').adyen.merchantAccount
})
This code uses the assign() function in the Lodash library to create an empty object, and then adds a merchantAccount key set to the Adyen Merchant Account identifier from the static-values Component, and then POSTS that JSON to the Adyen Webservice API.
Alternatives
You could use follow this same recipe but use a Data Transformation Script Component type instead of an Object Mapper, and enter the values into the Script field instead of the Response Transform field.
You could also a Conscia Universal API Connector Component to invoke the Conscia Webservice API used to invoke Orchestration Templates and Orchestration Components that would contain the values.
If you would prefer to define the values through the DX Engine UI, then you can use a Conscia - Metadata Component for the values.
You can use Experience Rules to apply different values under different conditions, such as to vary the response of a Component depending on the Environment.