Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slimy-dancers-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': minor
---

Feature: add support for sdkData API field
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AnalyticsInitialEvent } from '../../../core/Analytics/types';
import { off, on } from '../../../utils/listenerUtils';
import { AnalyticsInfoEvent } from '../../../core/Analytics/AnalyticsInfoEvent';
import { AnalyticsEvent } from '../../../core/Analytics/AnalyticsEvent';
import { createSdkData } from '../../../utils/createSdkData';

/**
* Verify if the first parameter is instance of Core.
Expand Down Expand Up @@ -104,9 +105,13 @@ abstract class BaseElement<P extends BaseElementProps> implements IBaseElement {
componentData.paymentMethod.checkoutAttemptId = checkoutAttemptId;
}

// Create sdkData when both analytics and risk data are available
const sdkData = checkoutAttemptId && clientData ? createSdkData(checkoutAttemptId, clientData) : undefined;
Comment on lines +108 to +109
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic for creating sdkData could result in sending an invalid checkoutAttemptId. The checkoutAttemptId variable can hold the value of NO_CHECKOUT_ATTEMPT_ID (which is 'fetch-checkoutAttemptId-failed'), a truthy string. This means sdkData would be created with this 'failed' value if clientData is present.

The comment on line 108 indicates that sdkData should only be created when both analytics and risk data are available. To ensure a valid checkoutAttemptId is used, you should add a check to exclude NO_CHECKOUT_ATTEMPT_ID.

Suggested change
// Create sdkData when both analytics and risk data are available
const sdkData = checkoutAttemptId && clientData ? createSdkData(checkoutAttemptId, clientData) : undefined;
// Create sdkData when both a valid checkoutAttemptId and risk data are available
const sdkData = checkoutAttemptId && checkoutAttemptId !== NO_CHECKOUT_ATTEMPT_ID && clientData ? createSdkData(checkoutAttemptId, clientData) : undefined;


return {
...(clientData && { riskData: { clientData } }),
...(order && { order: { orderData: order.orderData, pspReference: order.pspReference } }),
...(sdkData && { sdkData }),
...componentData,
clientStateDataIndicator: true
};
Expand Down
34 changes: 34 additions & 0 deletions packages/lib/src/utils/createSdkData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getUTCTimestamp } from '../core/Analytics/utils';
import base64 from './base64';

export interface SdkDataObject {
schemaVersion: string;
createdAt: number;
analytics: {
checkoutAttemptId: string;
};
riskData: {
clientData: string;
};
}

/**
* Creates the sdkData object with analytics and risk information
* @param checkoutAttemptId - The checkout attempt ID from analytics
* @param clientData - The client data from risk module
* @returns Base64 encoded JSON string of the SDK data object
*/
export function createSdkData(checkoutAttemptId: string, clientData: string): string {
Copy link
Contributor

@sponglord sponglord Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the YT ticket this sdkData should also contain a timestamp?

The Analytics utils (/src/core/Analytics/utils.ts) contains a getUTCTimestamp function - which is what we use in analytics.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, indeed. This has been added to the ticket, it wasn't there when I originally made the change. I'm going to be adding it, thanks for the tip.

const sdkDataObject: SdkDataObject = {
schemaVersion: '1.0',
createdAt: getUTCTimestamp(),
analytics: {
checkoutAttemptId
},
riskData: {
clientData
}
};

return base64.encode(JSON.stringify(sdkDataObject));
}
Loading