Adyen / adyen-salesforce-commerce-cloud

Salesforce Commerce Cloud (formerly Demandware)
MIT License
90 stars 75 forks source link

Orders not placed when receiving webhook notification #733

Closed wouterwp closed 11 months ago

wouterwp commented 1 year ago

The intention of this code seems to be that an order that is not yet placed will be placed when a webhook notification of a successful payment authorization is received: https://github.com/Adyen/adyen-salesforce-commerce-cloud/blob/5eeb50ced9107300018dad06c3e9596f776227aa/cartridges/int_adyen_SFRA/cartridge/scripts/adyenService.js#L34-L39

But this does not work, since order.status === Order.ORDER_STATUS_CREATED will always be false, also for orders with status 'Created'. Since order.status is of type dw.value.EnumValue and Order.ORDER_STATUS_CREATED is numeric using === will always be false. Please change this to either using == or to order.status.value === Order.ORDER_STATUS_CREATED.

Similar issues are present at: https://github.com/Adyen/adyen-salesforce-commerce-cloud/blob/5eeb50ced9107300018dad06c3e9596f776227aa/cartridges/int_adyen_overlay/cartridge/scripts/handleCustomObject.js#L123 https://github.com/Adyen/adyen-salesforce-commerce-cloud/blob/5eeb50ced9107300018dad06c3e9596f776227aa/cartridges/int_adyen_overlay/cartridge/scripts/handleCustomObject.js#L105 https://github.com/Adyen/adyen-salesforce-commerce-cloud/blob/5eeb50ced9107300018dad06c3e9596f776227aa/cartridges/int_adyen_overlay/cartridge/scripts/job/notifications.js#L61

olga-adyen commented 1 year ago

Hi @wouterwp,

We are investigating this case internally. I'll close this issue if we can't reproduce the issue, otherwise we will release a fix for the issue.

With kind regards, Olga Kostina Adyen

prestarihab commented 1 year ago

hello , I had this issue also when i place order with 3DS

ERROR PipelineCallServlet|1706873868|Sites-celio-Site|Adyen-ShowConfirmation|PipelineCall|zKqDPsYdQL custom.Adyen [] Could not verify /payment/details: SystemError: com.demandware.beehive.orm.capi.common.ORMOptimisticLockingException: Optimistic locking failure. Object couldn't be updated. [com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO, com.demandware.beehive.orm.internal.state2.RelationalObjectInstanceState@f2399d1[com.demandware.beehive.core.capi.domain.PersistentObjectPOKey(com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO) [2ae33b4e8c95d0d11ba3461318]], com.demandware.beehive.core.capi.domain.PersistentObjectPOKey(com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO) [2ae33b4e8c95d0d11ba3461318], OCA=523194088] in int_adyen_SFRA/cartridge/controllers/middlewares/adyen/showConfirmation/order.js:12

olga-adyen commented 1 year ago

Hi @prestarihab could you please share the cartridge version and SFCC version you're on?

prestarihab commented 1 year ago

hello @olga-adyen I use the last version 23.2.0 and SFCC version SFRA 6.1.0. Thanks

KennethRobbeFrucon commented 1 year ago

@olga-adyen I can confirm the issue described by Wouter in the original comment. The issue is still present in the last version (v23.2.1).

We had to add a customization to resolve it. Without the fix, we were encountering paid orders that weren't properly placed / exported, because the logic inside cartridges/int_adyen_SFRA/cartridge/scripts/adyenService.js fails to execute. The condition order.status === Order.ORDER_STATUS_CREATED can never be true, so the logic to place the order is never executed.

nsquar3d commented 11 months ago

Adding another comment to this because my company ran into this issue as well. We will be implementing a customization for this in our cartridge. There are scenarios (such as iDeal payments in NL) where, if a redirect back to the website doesn't execute properly, then the bank account is debited but the order is never updated via webhook, and thus the order stays in "Created" status until it ultimately fails after X amount of time.

Not a great user experience for our customers if there are issues with redirect.

amihajlovski commented 11 months ago

Hello

This is already fixed on develop https://github.com/Adyen/adyen-salesforce-commerce-cloud/pull/966 and will be included in the next release

Kind Regards Aleksandar Adyen

sunil-veerapura commented 11 months ago

Hello @olga-adyen, Any idea on this issue? Is this resolved in any latest versions?

I am getting the same issue mentioned here very often on production environment. https://github.com/Adyen/adyen-salesforce-commerce-cloud/issues/733#issuecomment-1658704806

Currently we are using https://github.com/Adyen/adyen-salesforce-commerce-cloud/tree/c3737fcafe1898e74cf2639f477cf09848a75e11

Error: SystemError: com.demandware.beehive.orm.capi.common.ORMOptimisticLockingException: Optimistic locking failure. Object couldn't be updated. [com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO, com.demandware.beehive.orm.internal.state2.RelationalObjectInstanceState@455f995[com.demandware.beehive.core.capi.domain.PersistentObjectPOKey(com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO) [50fa75e142588324f534e48ea6]], com.demandware.beehive.core.capi.domain.PersistentObjectPOKey(com.demandware.beehive.bts.internal.orderprocess.fulfillment.OrderPO) [50fa75e142588324f534e48ea6], OCA=528290224]

Thanks, Sunil

olga-adyen commented 11 months ago

@sunil-veerapura

Pls see the comment of Aleksandar above:

This is already fixed on develop https://github.com/Adyen/adyen-salesforce-commerce-cloud/pull/966 and will be included in the next release

Thank you, Olga Adyen

sunil-veerapura commented 11 months ago

@olga-adyen - I don't understand how this fix will resolve the optimistic locking issue which we are getting while placing order through 3DS. We don't get this for everything order. 1 order in 10 is having such issue but not every order.

If you can give me bit more explaination about how this fix will resolve the issue, it would help us communicate to our client.

wouterwp commented 11 months ago

@sunil-veerapura It seems to me that the issue that you describe is a different one then reported here.

It could be that the custom objects containing the notifications are processed at the same time as that the customer returns from the 3DS verification, so two processed are trying to modify the same order. Our solution was to add a 1 minute delay in the processing of the notification custom objects by comparing the order creation time to the current time.

sunil-veerapura commented 11 months ago

@wouterwp , Yes its a different issue for me. We don't use the notification and custom objects in our project. Its a straight process in checkout and we get this error only during 3DS order placement. Also I found multiple transaction code written in the 3DS flow. I am guessing this is causing the issue where the previous transaction has not released the order object yet and the next one tries to process it.

amihajlovski commented 11 months ago

Hello @wouterwp

This issue is now fixed in latest release

Kind Regards Aleksandar Adyen