diff --git a/notification/src/handler/notification/notification.handler.js b/notification/src/handler/notification/notification.handler.js index 20d1d1c88..311cfd469 100644 --- a/notification/src/handler/notification/notification.handler.js +++ b/notification/src/handler/notification/notification.handler.js @@ -54,6 +54,17 @@ async function processNotification( originalReference || pspReference, ctpClient, ) + + if ( + !payment.custom.fields.makePaymentResponse && + !payment.custom.fields.createSessionResponse + ) { + const error = new Error(`Payment ${merchantReference} is not created yet.`) + error.statusCode = 503 + + throw new VError(error, `Payment ${merchantReference} is not created yet.`) + } + if (payment) await updatePaymentWithRepeater(payment, notification, ctpClient, logger) else diff --git a/notification/test/resources/payment-credit-card.json b/notification/test/resources/payment-credit-card.json index bba7cc65e..6b8712863 100644 --- a/notification/test/resources/payment-credit-card.json +++ b/notification/test/resources/payment-credit-card.json @@ -16,7 +16,8 @@ "key": "ctp-adyen-integration-web-components-payment-type" }, "fields": { - "createSessionRequest": "{ \"amount\": { \"currency\": \"EUR\", \"value\": 1000 }, \"reference\": \"YOUR_REFERENCE\", \"channel\": \"Web\", \"returnUrl\": \"https://your-company.com/...\", \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }" + "createSessionRequest": "{ \"amount\": { \"currency\": \"EUR\", \"value\": 1000 }, \"reference\": \"YOUR_REFERENCE\", \"channel\": \"Web\", \"returnUrl\": \"https://your-company.com/...\", \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }", + "createSessionResponse": "{ \"amount\": { \"currency\": \"EUR\", \"value\": 1000 }, \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }" } }, "paymentStatus": {}, diff --git a/notification/test/resources/payment-draft.json b/notification/test/resources/payment-draft.json index 50ece6870..41baccb80 100644 --- a/notification/test/resources/payment-draft.json +++ b/notification/test/resources/payment-draft.json @@ -13,6 +13,10 @@ "type": { "typeId": "type", "key": "ctp-adyen-integration-web-components-payment-type" + }, + "fields": { + "createSessionRequest": "{ \"amount\": { \"currency\": \"EUR\", \"value\": 795 }, \"reference\": \"YOUR_REFERENCE\", \"channel\": \"Web\", \"returnUrl\": \"https://your-company.com/...\", \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }", + "createSessionResponse": "{ \"amount\": { \"currency\": \"EUR\", \"value\": 795 }, \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }" } }, "transactions": [ diff --git a/notification/test/test-utils.js b/notification/test/test-utils.js index 814dc9112..2ebed4782 100644 --- a/notification/test/test-utils.js +++ b/notification/test/test-utils.js @@ -149,10 +149,8 @@ async function ensurePayment( ) const paymentDraft = _.cloneDeep(payment) paymentDraft.key = paymentKey - paymentDraft.custom.fields = { - commercetoolsProjectKey, - adyenMerchantAccount, - } + paymentDraft.custom.fields.commercetoolsProjectKey = commercetoolsProjectKey + paymentDraft.custom.fields.adyenMerchantAccount = adyenMerchantAccount if (pspReference) { paymentDraft.transactions[0].interactionId = pspReference }