Skip to content
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

Analytics Service #1186

Merged
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
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
Loading