-
Notifications
You must be signed in to change notification settings - Fork 161
feat: add support for sdkData API field #3511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ( There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current logic for creating
sdkData
could result in sending an invalidcheckoutAttemptId
. ThecheckoutAttemptId
variable can hold the value ofNO_CHECKOUT_ATTEMPT_ID
(which is'fetch-checkoutAttemptId-failed'
), a truthy string. This meanssdkData
would be created with this 'failed' value ifclientData
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 validcheckoutAttemptId
is used, you should add a check to excludeNO_CHECKOUT_ATTEMPT_ID
.