Skip to content

Commit

Permalink
Analytics Service (#1186)
Browse files Browse the repository at this point in the history
  • Loading branch information
zenit2001 authored Oct 15, 2024
1 parent 8017d91 commit 2d35487
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
14 changes: 14 additions & 0 deletions metadata/site_import/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@
<user-id></user-id>
<password/>
</service-credential>
<service-credential service-credential-id="AdyenAnalytics">
<url>https://checkoutanalytics-test.adyen.com/checkoutanalytics/v3/analytics</url>
<user-id></user-id>
<password/>
</service-credential>

<service-profile service-profile-id="Adyen">
<timeout-millis>30000</timeout-millis>
Expand Down Expand Up @@ -228,4 +233,13 @@
<profile-id>Adyen</profile-id>
<credential-id>AdyenPaypalUpdateOrder</credential-id>
</service>
<service service-id="AdyenAnalytics">
<service-type>HTTP</service-type>
<enabled>true</enabled>
<log-prefix>adyen</log-prefix>
<comm-log-enabled>true</comm-log-enabled>
<mock-mode-enabled>false</mock-mode-enabled>
<profile-id>Adyen</profile-id>
<credential-id>AdyenAnalytics</credential-id>
</service>
</services>
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = {
CANCELPARTIALPAYMENTORDER: 'AdyenCancelPartialPaymentOrder',
PARTIALPAYMENTSORDER: 'AdyenPartialPaymentsOrder',
PAYPALUPDATEORDER: 'AdyenPaypalUpdateOrder',
ADYEN_ANALYTICS: 'AdyenAnalytics',
},
CONTRACT: {
ONECLICK: 'ONECLICK',
Expand Down
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,
};
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ let adyenHelperObj = {
}
},

executeCall(serviceType, requestObject) {
executeCall(serviceType, requestObject, checkoutAttemptID = '') {
const service = this.getService(serviceType);
if (service === null) {
throw new Error(`Could not create ${serviceType} service object`);
Expand All @@ -936,6 +936,13 @@ let adyenHelperObj = {
service.setURL(serviceUrl);
}

if (serviceType === constants.SERVICE.ADYEN_ANALYTICS) {
const clientKey = AdyenConfigs.getAdyenClientKey();
let serviceUrl = service.getURL();
serviceUrl += `/${checkoutAttemptID}?clientKey=${clientKey}`;
service.setURL(serviceUrl);
}

const maxRetries = constants.MAX_API_RETRIES;
const apiKey = AdyenConfigs.getAdyenApiKey();
const uuid = UUIDUtils.createUUID();
Expand Down

0 comments on commit 2d35487

Please sign in to comment.