Skip to content

Commit

Permalink
Fix webhook handling when payment is not yet created
Browse files Browse the repository at this point in the history
ACS0TSLIC-4
  • Loading branch information
MarijaIv committed Jan 23, 2024
1 parent 393c3b1 commit d6cdb72
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
11 changes: 11 additions & 0 deletions notification/src/handler/notification/notification.handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion notification/test/resources/payment-credit-card.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {},
Expand Down
4 changes: 4 additions & 0 deletions notification/test/resources/payment-draft.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 2 additions & 4 deletions notification/test/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit d6cdb72

Please sign in to comment.