-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/cartridges/int_adyen_SFRA/cartridge/adyen/scripts/analytics/analyticsService.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper'); | ||
const constants = require('*/cartridge/adyen/config/constants'); | ||
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs'); | ||
|
||
function createCheckoutAttemptId() { | ||
try { | ||
const analyticsResponse = {}; | ||
const requestObject = { | ||
applicationInfo: AdyenHelper.getApplicationInfo(), | ||
channel: 'Web', | ||
platform: 'Web', | ||
}; | ||
|
||
const response = AdyenHelper.executeCall( | ||
constants.SERVICE.ADYEN_ANALYTICS, | ||
requestObject, | ||
); | ||
|
||
analyticsResponse.attemptId = response.checkoutAttemptId; | ||
|
||
return analyticsResponse; | ||
} catch (error) { | ||
AdyenLogs.error_log( | ||
'createCheckoutAttemptId for /analytics call failed:', | ||
error, | ||
); | ||
return { error: true }; | ||
} | ||
} | ||
|
||
function submitData(attemptIdParam = null) { | ||
try { | ||
let attemptId = attemptIdParam; | ||
|
||
// If attemptId is not provided as a parameter, generate it | ||
if (!attemptId) { | ||
const initialAnalyticsCall = createCheckoutAttemptId(); | ||
attemptId = initialAnalyticsCall.attemptId; | ||
} | ||
|
||
const requestObject = { | ||
channel: 'Web', | ||
platform: 'Web', | ||
info: [ | ||
{ | ||
timestamp: '1679314125207', | ||
type: 'focus', | ||
component: 'scheme', | ||
target: 'security_code', | ||
id: 'cfea6b0a-7f19-4c31-b065-8d44ea3fdf63', | ||
}, | ||
], | ||
}; | ||
|
||
const response = AdyenHelper.executeCall( | ||
constants.SERVICE.ADYEN_ANALYTICS, | ||
requestObject, | ||
attemptId, | ||
); | ||
|
||
return response; | ||
} catch (error) { | ||
AdyenLogs.error_log('submitData for /analytics call failed:', error); | ||
return { error: true }; | ||
} | ||
} | ||
|
||
module.exports = { | ||
createCheckoutAttemptId, | ||
submitData, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters