Commercetools: Configuration
Adyen Commercetools Integration Configuration Options
Our Adyen commercetools has two parts: Middleware integration and SDK Module. See the configuration options for each below.
Middleware integration
Configuration interface
middleware.config.js
import { Client } from "@adyen/api-library";
export interface MiddlewareConfig {
ctApi: {
projectKey: string;
clientId: string;
clientSecret: string;
scopes: Array<string>;
authHost: string;
apiHost: string;
};
adyenApiKey: string;
adyenEnvironment: "TEST" | "LIVE";
adyenMerchantAccount: string;
integrationName: string;
origin: string;
userSessionCookie?: string;
partialPaymentTTL?: number;
customOrderType?: string;
buildCustomGetPaymentMethodsAttributes?: ((params: BuildCustomGetPaymentMethodsAttributesParams) => Promise<Record<string, any>>) | ((params: BuildCustomGetPaymentMethodsAttributesParams) => Record<string, any>);
buildCustomPaymentAttributes?: ((params: BuildCustomPaymentAttributesParams) => Promise<Record<string, any>>) | ((params: BuildCustomPaymentAttributesParams) => Record<string, any>);
buildCustomAdyenClientParameters?: (params: { apiKey: string, environment: 'TEST' | 'LIVE' }) => ConstructorParameters<typeof Client>[0];
onRedirectBack?: TOnRedirectBack
};
type TOnRedirectBack = (
context: AdyenIntegrationContext,
services: {
ct: CommercetoolsService;
adyen: AdyenService;
},
cart: Cart,
payment: PaymentWithFields
) => SyncOrAsync<string>;
type SyncOrAsync<T> = T | Promise<T>;
Configuration options:
Attribute | required | info | |
---|---|---|---|
ctApi.projectKey | ✅ Yes | The project key of your commercetools project. | |
ctApi.clientId | ✅ Yes | The client ID of your commercetools API client. | |
ctApi.clientSecret | ✅ Yes | The client secret of your commercetools API client. | |
ctApi.scopes | ✅ Yes | The scopes of your commercetools API client. It must contain manage_payments , manage_orders , and view_types . | |
ctApi.authHost | ✅ Yes | The commercetools authorization endpoint. | |
ctApi.apiHost | ✅ Yes | The base URL of the commercetools API. It should contain only the base URL, without the path to the GraphQL endpoint. For example, https://.com/ instead of https://.com/vsf-ct-dev/graphql . | |
adyenApiKey | ✅ Yes | Your Adyen API Key | |
adyenEnvironment | ✅ Yes | Adyen's environment, available values are "TEST" or "LIVE" | |
adyenMerchantAccount | ✅ Yes | The merchant account identifier you want to use for processing payments. | |
integrationName | ✅ Yes | Name of the key containing adyen's integration object in the middleware.config.ts file | |
origin | ✅ Yes | Base URL of the frontend application | |
userSessionCookie | ⌥ optional | Name of the session cookie, by default it's "vsf-commercetools-token" . | |
partialPaymentTTL | ⌥ optional | Time after unfinished partial payment expires (in miliseconds) | |
customOrderType | ⌥ optional | Key of custom order type for storing partial payment's information. Use only if you had to extend already existing custom order type | |
buildCustomGetPaymentMethodsAttributes | ⌥ optional | Function returning object that will be assigned to the payload sent to the Adyen's POST /paymentMethods endpoint. | |
buildCustomPaymentAttributes | ⌥ optional | Function returning object that will be assigned to the payload sent to the Adyen's POST /payments endpoint. | |
buildCustomAdyenClientParameters | ⌥ optional | Function returning object that will be passed to the constructor of Client from @adyen/api-library. Mostly all you need to is pass what you got in params and append liveEndpointUrlPrefix . | |
onRedirectBack | ⌥ optional | Function called after coming back from redirect-based method. It has to return URL where an user will be redirected. It's also used to place an order after succesful payment. | |
onRedirectBackFailed | ⌥ optional | Function called in catch block if onRedirectBack thrown an error. It has to return URL where an user will be redirected in that scenario. | |
enableHmacSignature | ⌥ optional | Boolean determining if endpoint for ORDER_CANCEL event should check HMAC signature | |
secretHmacKey | ⌥ optional | HMAC secret key used if enableHmacSignature is enabled |
Example configuration for Commercetools
middleware.config.js
const middlewareConfig = {
// ...
adyen: {
location: '@vsf-enterprise/adyen-commercetools-api/server',
configuration: {
ctApi: {
apiHost: '<CT_HOST_URL>',
authHost: '<CT_AUTH_URL>',
projectKey: '<CT_PROJECT_KEY>',
clientId: '<CT_CLIENT_ID>',
clientSecret: '<CT_CLIENT_SECRET>',
scopes: ['manage_payments:<ADYEN_PROJECT_IDENTIFIER>', 'manage_orders:<ADYEN_PROJECT_IDENTIFIER>']
},
adyenApiKey: '<ADYEN_API_KEY>',
adyenMerchantAccount: '<ADYEN_MERCHANT_ACCOUNT>',
returnUrl: 'http://localhost/adyen-redirect-back',
adyenCheckoutApiBaseUrl: '<ADYEN_CHECKOUT_API_BASE_URL>',
adyenCheckoutApiVersion: 71,
adyenEnvironment: 'TEST',
integrationName: 'adyen', // Name of the key containing adyen's integration object in the middleware.config.ts file
origin: 'https://my-alokai-frontend.local', // URL of frontend
}
},
}
SDK module
Configuration interface
type AdyenEnvironment =
| "test"
| "live";
/**
* Options for the SDK module.
*/
interface Options {
/**
* The API URL of the Middleware Adyen commercetools
* integration accessible from the browser.
*/
apiUrl: string;
/**
* Adyen's client key
*/
adyenClientKey: string;
/**
* Adyen's environment
*/
adyenEnvironment: AdyenEnvironment;
}
Example configuration for Commercetools
{
apiUrl: 'http://localhost/api/adyen',
adyenClientKey: 'test_***',
adyenEnvironment: 'test',
}