Skip to content

Commit 148ccc0

Browse files
Merge pull request #142 from mollie/feature/MOL-78/PICT-204_merge-dev
Feature/mol 78/pict 204 merge dev
2 parents afde7eb + 38b3333 commit 148ccc0

File tree

5 files changed

+41
-31
lines changed

5 files changed

+41
-31
lines changed

Diff for: processor/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: processor/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "shopmacher-mollie-processor",
33
"description": "Integration between commercetools and mollie payment service provider",
4-
"version": "1.2.1-build28.02.25.1313",
4+
"version": "1.2.1-build04.03.25.0957",
55
"main": "index.js",
66
"private": true,
77
"scripts": {

Diff for: processor/src/service/payment.service.ts

+36-26
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ const filterMethodsByPricingConstraints = (
195195

196196
const isCaptureFromMollie = (
197197
manualCapture: boolean,
198-
ctTransactions: CTTransaction[],
198+
ctTransactions: Transaction[],
199199
molliePayment: MPayment,
200200
): DoCapturePaymentFromMollie => {
201201
const hasSuccessAuthorizedTransaction = ctTransactions.some((transaction) => {
@@ -232,8 +232,13 @@ const isCaptureFromMollie = (
232232
transaction.interactionId === molliePayment.id,
233233
);
234234

235+
const hasSurchargeCost =
236+
pendingChargeTransaction?.custom?.fields?.[CustomFields.surchargeAndCapture.fields.surchargeCode.name] !==
237+
undefined;
238+
235239
return {
236240
answer,
241+
hasSurchargeCost,
237242
id: pendingChargeTransaction?.id,
238243
};
239244
};
@@ -333,13 +338,7 @@ export const handlePaymentWebhook = async (paymentId: string): Promise<boolean>
333338
return false;
334339
}
335340

336-
logger.debug('SCTM - handlePaymentWebhook - debugging', {
337-
mollieStatus: molliePayment.status,
338-
ctPaymentId: ctPayment.id,
339-
ctPaymentTransactions: JSON.stringify(ctPayment.transactions),
340-
});
341-
342-
const action = getPaymentStatusUpdateAction(ctPayment.transactions as CTTransaction[], molliePayment);
341+
const action = getPaymentStatusUpdateAction(ctPayment.transactions as Transaction[], molliePayment);
343342

344343
// If refunds are present, update their status
345344
const refunds = molliePayment._embedded?.refunds;
@@ -366,7 +365,7 @@ export const handlePaymentWebhook = async (paymentId: string): Promise<boolean>
366365
};
367366

368367
export const getPaymentStatusUpdateAction = (
369-
ctTransactions: CTTransaction[],
368+
ctTransactions: Transaction[],
370369
molliePayment: MPayment,
371370
): UpdateAction[] => {
372371
const updateActions: UpdateAction[] = [];
@@ -444,23 +443,34 @@ export const getPaymentStatusUpdateAction = (
444443
logger.debug(
445444
`SCTM - getPaymentStatusUpdateAction - Capture payment triggered from Mollie paymentID: ${molliePaymentId}`,
446445
);
447-
updateActions.push(
448-
setTransactionCustomField(
449-
CustomFields.surchargeAndCapture.fields.shouldCapture.name,
450-
true,
451-
doCaptureInMollie.id as string,
452-
),
453-
setTransactionCustomField(
454-
CustomFields.surchargeAndCapture.fields.descriptionCapture.name,
455-
'Payment is captured from Mollie.',
456-
doCaptureInMollie.id as string,
457-
),
458-
setTransactionCustomField(
459-
CustomFields.surchargeAndCapture.fields.captureErrors.name,
460-
'',
461-
doCaptureInMollie.id as string,
462-
),
463-
);
446+
447+
if (doCaptureInMollie.hasSurchargeCost) {
448+
updateActions.push(
449+
setTransactionCustomField(
450+
CustomFields.surchargeAndCapture.fields.shouldCapture.name,
451+
true,
452+
doCaptureInMollie.id as string,
453+
),
454+
setTransactionCustomField(
455+
CustomFields.surchargeAndCapture.fields.descriptionCapture.name,
456+
'Payment is captured from Mollie.',
457+
doCaptureInMollie.id as string,
458+
),
459+
setTransactionCustomField(
460+
CustomFields.surchargeAndCapture.fields.captureErrors.name,
461+
'',
462+
doCaptureInMollie.id as string,
463+
),
464+
);
465+
} else {
466+
updateActions.push(
467+
setTransactionCustomType(doCaptureInMollie.id as string, CustomFields.surchargeAndCapture.typeKey, {
468+
[CustomFields.surchargeAndCapture.fields.shouldCapture.name]: true,
469+
[CustomFields.surchargeAndCapture.fields.descriptionCapture.name]: 'Payment is captured from Mollie.',
470+
[CustomFields.surchargeAndCapture.fields.captureErrors.name]: '',
471+
}),
472+
);
473+
}
464474
}
465475

466476
return updateActions;

Diff for: processor/src/types/commercetools.types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,4 @@ export enum CaptureModes {
181181
Automatic = 'automatic',
182182
}
183183

184-
export type DoCapturePaymentFromMollie = { answer: boolean } & Pick<CTTransaction, 'id'>;
184+
export type DoCapturePaymentFromMollie = { answer: boolean; hasSurchargeCost: boolean; id?: string };

Diff for: processor/tests/service/payment.service.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,7 @@ describe('Test handlePaymentWebhook', () => {
23362336
],
23372337
});
23382338
await handlePaymentWebhook(fakePaymentId);
2339-
expect(logger.debug).toBeCalledTimes(3);
2339+
expect(logger.debug).toBeCalledTimes(2);
23402340
expect(logger.debug).toBeCalledWith(`SCTM - handlePaymentWebhook - paymentId:${fakePaymentId}`);
23412341
expect(logger.debug).toBeCalledWith(`handlePaymentWebhook - No actions needed`);
23422342
});

0 commit comments

Comments
 (0)