Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
amihajlovski committed Oct 24, 2024
1 parent d732dd3 commit 31b5fd4
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ function getGiftCardConfig() {
async: false,
success: (data) => {
giftcardBalance = data.balance;
document.querySelector(
'button[value="submit-payment"]',
).disabled = false;
document.querySelector('button[value="submit-payment"]').disabled =
false;
if (data.resultCode === constants.SUCCESS) {
const {
giftCardsInfoMessageContainer,
Expand All @@ -220,9 +219,8 @@ function getGiftCardConfig() {
initialPartialObject.totalDiscountedAmount;
});

document.querySelector(
'button[value="submit-payment"]',
).disabled = true;
document.querySelector('button[value="submit-payment"]').disabled =
true;
giftCardsInfoMessageContainer.innerHTML = '';
giftCardsInfoMessageContainer.classList.remove(
'gift-cards-info-message-container',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ function removeGiftCards() {
giftCardsInfoMessageContainer.classList.remove(
'gift-cards-info-message-container',
);
document.querySelector(
'button[value="submit-payment"]',
).disabled = false;
document.querySelector('button[value="submit-payment"]').disabled =
false;

if (res.resultCode === constants.RECEIVED) {
document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ function createAnalyticsEvent(
customObj.custom.eventType = eventType;
customObj.custom.eventStatus = eventStatus;
customObj.custom.eventCode = eventCode;
customObj.custom.processingStatus =
constants.processingStatus.NOT_PROCESSED;
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,41 @@
const UUIDUtils = require('dw/util/UUIDUtils');

const AdyenHelper = require('*/cartridge/adyen/utils/adyenHelper');
const AdyenConfigs = require('*/cartridge/adyen/utils/adyenConfigs');
const constants = require('*/cartridge/adyen/config/constants');
const AdyenLogs = require('*/cartridge/adyen/logs/adyenCustomLogs');

function execute(serviceType, requestObject, checkoutAttemptID = '') {
const service = AdyenHelper.getService(serviceType);
if (service === null) {
throw new Error(`Could not create ${serviceType} service object`);
}
const clientKey = AdyenConfigs.getAdyenClientKey();
let serviceUrl = service.getURL();
serviceUrl += `/${checkoutAttemptID}?clientKey=${clientKey}`;
service.setURL(serviceUrl);

const apiKey = AdyenConfigs.getAdyenApiKey();
const uuid = UUIDUtils.createUUID();
service.addHeader('Content-type', 'application/json');
service.addHeader('charset', 'UTF-8');
service.addHeader('X-API-KEY', apiKey);
service.addHeader('Idempotency-Key', uuid);

const callResult = service.call(JSON.stringify(requestObject));
AdyenLogs.info_log(`is OK ${JSON.stringify(callResult.isOk())}`);

if (!callResult.isOk()) {
throw new Error(
`${serviceType} service call error code${callResult
.getError()
.toString()} Error => ResponseStatus: ${callResult.getStatus()} | ResponseErrorText: ${callResult.getErrorMessage()} | ResponseText: ${callResult.getMsg()}`,
);
}

return { success: true };
}

function createCheckoutAttemptId() {
try {
const analyticsResponse = {};
Expand All @@ -11,10 +45,7 @@ function createCheckoutAttemptId() {
platform: 'Web',
};

const response = AdyenHelper.executeCall(
constants.SERVICE.ADYEN_ANALYTICS,
requestObject,
);
const response = execute(constants.SERVICE.ADYEN_ANALYTICS, requestObject);

analyticsResponse.attemptId = response.checkoutAttemptId;

Expand All @@ -38,13 +69,7 @@ function submitData(requestObject, attemptIdParam = null) {
attemptId = initialAnalyticsCall.attemptId;
}

const response = AdyenHelper.executeCall(
constants.SERVICE.ADYEN_ANALYTICS,
requestObject,
attemptId,
);

return response;
return execute(constants.SERVICE.ADYEN_ANALYTICS, requestObject, attemptId);
} catch (error) {
AdyenLogs.error_log('submitData for /analytics call failed:', error);
return { error: true };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ function processData() {
);

const payload = createRequestObjectForAllReferenceIds(groupedObjects);
const submissionSuccess = AnalyticsService.submitData(payload);
if (submissionSuccess) {
const submission = AnalyticsService.submitData(payload); // {error: true}
if (submission.success) {
customObjectsToDelete.forEach((customObject) => {
deleteCustomObject(customObject);
});
} else {
AdyenLogs.error_log('Failed to submit full payload for grouped objects.');
// This will be triggered upon completion of SFI-991
customObjectsToDelete.forEach((customObject) => {
updateProcessingStatus(
customObject,
Expand Down
22 changes: 10 additions & 12 deletions src/cartridges/int_adyen_SFRA/cartridge/adyen/utils/adyenHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ let adyenHelperObj = {
}
},

executeCall(serviceType, requestObject, checkoutAttemptID = '') {
executeCall(serviceType, requestObject = '') {
const service = this.getService(serviceType);
if (service === null) {
throw new Error(`Could not create ${serviceType} service object`);
Expand All @@ -938,13 +938,6 @@ 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 Expand Up @@ -975,10 +968,15 @@ let adyenHelperObj = {
if (!resultObject || !resultObject.getText()) {
throw new Error(`No correct response from ${serviceType} service call`);
}
// Once analytics executeCall is separated in SFI-991, this if condition can be removed
if (serviceType !== constants.SERVICE.ADYEN_ANALYTICS) {
analyticsEvent.createAnalyticsEvent(session.sessionID, serviceType, analyticsConstants.eventType.END, analyticsConstants.eventStatus.EXPECTED, analyticsConstants.eventCode.INFO);
}

analyticsEvent.createAnalyticsEvent(
session.sessionID,
serviceType,
analyticsConstants.eventType.END,
analyticsConstants.eventStatus.EXPECTED,
analyticsConstants.eventCode.INFO
);

return JSON.parse(resultObject.getText());
},
};
Expand Down

0 comments on commit 31b5fd4

Please sign in to comment.