Closed dbolufer closed 4 years ago
Hi @dbolufer ,
Thank you for raising this issue and for the detailed description. We are going to release a quick fix for this one to prevent the cron job to stop. Meanwhile could you please check your logs regarding your PSP and merchant reference if you can find any errors for the previous cron jobs running? This issue only occurs if the PSP and merchant reference is already in the database and for some reason the notification is reprocessed - most likely because there was an error later in the process caused by the plugin, Magento or another third party plugin. If you could investigate the issue a bit more it would be a great help for us and also for the community to understand this specific issue.
Thank you for your help in advance. Best. Attila Adyen
Hi @dbolufer ,
Just merged a PR which will introduce a fix for this issue. We are going to release it in the next release cycle.
Best, Attila Adyen
Thank you! So far, we have not been able to investigate the origin of the problem. I wish we can take a look next week
Hi. The fix should work for adyen_notification.done = 0 but for adyen_notification.done = 1 doesn't work.
Now, we have 20 orders payment_review , 3 of them have adyen_notification.done = 1.
Anyway, we are going to apply the fix via patch and check if 100% of cases will be solved
Hi @dbolufer ,
Yes for the adyen_notification.done = 1 it won't work because that is the indicator of the notifications that are already processed so we don't touch them anymore. It was an uncaught exception which now in this patch is caught which prevented the process to be finished the correct way.
So after this patch and after cleaning up the rest of the notifications which experienced this issue, it should be fine but please give us feedback when you have the chance to test it :)
Best, Attila Adyen
Hi!
At this time, we have one order with adyen_notification.done = 1 and order.state & status = payment_review
This is the results of our investigation.
11561204-[2020-01-12 21:37:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Processing notification 33589 {"is_exception":false} []
11561205-[2020-01-12 21:37:09] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Array
11561206-(
11561207- [entity_id] => 33589
11561208: [pspreference] => XXXXX
11561209- [merchant_reference] => XXXXX
11561210- [event_code] => AUTHORISATION
11561211- [success] => true
11561212- [payment_method] => visa
11561213- [amount_value] => 9200
11561214- [amount_currency] => EUR
11561215- [reason] => 352966:8020:04/2022
11561216- [live] => true
11561217- [additional_data] => a:7:{s:10:"expiryDate";s:7:"XXXXX";s:8:"authCode";s:6:"XXXXX";s:11:"cardSummary";s:4:"XXXXX";s:14:"cardHolderName";s:18:"XXXXX";s:24:"recurringProcessingModel";s:10:"CardOnFile";s:12:"visaTemplate";s:17:"InitialCardOnFile";s:13:"hmacSignature";s:44:"XXXXX";}
11561218- [done] => 0
11561219- [processing] => 1
11561220- [created_at] => 2020-01-12 21:35:30
11561221-)
11561222- {"is_exception":false} []
11561223-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created comment history for this notification {"is_exception":false} []
11561224-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Updating the Adyen attributes of the order {"is_exception":false} []
11561225-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Processing the notification {"is_exception":false} []
11561226-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Authorisation of the order {"is_exception":false} []
11561227-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: State is changed to processing {"is_exception":false} []
11561228-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Order status is changed to Pre-authorised status, status is payment_authorisation {"is_exception":false} []
11561229-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Prepare invoice for order {"is_exception":false} []
11561230-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created comment history for this notification {"is_exception":false} []
11561231-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Updating the Adyen attributes of the order {"is_exception":false} []
11561232-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Processing the notification {"is_exception":false} []
11561233-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: CustomerReference is: XXXXX and storeId is 4 and RecurringDetailsReference is XXXXX {"is_exception":false} []
11561234-[2020-01-12 21:37:13] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Capture mode is set to auto capture {"is_exception":false} []
11561235-[2020-01-12 21:37:14] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Validate if AUTHORISATION notification has the total amount of the order {"is_exception":false} []
11561236-[2020-01-12 21:37:14] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: The grandtotal amount is 9200 and the total order amount that is authorised is: 9200 {"is_exception":false} []
11561237-[2020-01-12 21:37:14] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: AUTHORISATION has the full amount {"is_exception":false} []
11561238-[2020-01-12 21:37:14] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Creating invoice for order {"is_exception":false} []
11561239-[2020-01-12 21:37:14] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Capture mode is set to auto capture {"is_exception":false} []
11561240-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created invoice {"is_exception":false} []
11561241-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created invoice entry in the Adyen table {"is_exception":false} []
11561242-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Set order to authorised {"is_exception":false} []
11561243-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: State is changed to processing {"is_exception":false} []
11561244-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Order status is changed to authorised status, status is payment_confirmed {"is_exception":false} []
11561245-[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Send orderconfirmation email to shopper {"is_exception":false} []
11561246-[2020-01-12 21:37:18] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Creating new Billing Agreement {"is_exception":false} []
11561247-[2020-01-12 21:37:18] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created billing agreement #2815788649299700. {"is_exception":false} []
11561248-[2020-01-12 21:37:23] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Notification 33589 is processed {"is_exception":false} []
The log tell us that everything is went all right, adyen_notification.done=1 we had a row over adyen_order_payment
and the order has an invoice,
But the state / status for this order is payment_review
[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: State is changed to processing {"is_exception":false} []
[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Order status is changed to authorised status, status is payment_confirmed {"is
[2020-01-12 21:37:17] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Send orderconfirmation email to shopper {"is_exception":false} []
[2020-01-12 21:37:18] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Creating new Billing Agreement {"is_exception":false} []
[2020-01-12 21:37:18] AdyenLoggerTest.ADYEN_NOTIFICATION_CRONJOB: Created billing agreement #2815788649299700. {"is_exception":false} []
There is not any other important log :-(
UPDATE: When we change done=1 to done=0, the order has been processed
This is the order comments history
- Jan 13, 2020 7:31:05 PM Payment Confirmed (Adyen asynchronous) Customer Not Notified
Adyen Payment Successfully completed
- Jan 13, 2020 7:31:05 PM Payment Authorisation (Adyen synchronous) Customer Not Notified
Payment is authorised waiting for capture
- Jan 13, 2020 7:31:05 PM Payment Review Customer Not Notified
Adyen HTTP Notification(s):
eventCode: AUTHORISATION
pspReference: XXXX
paymentMethod: visa
success: true
reason:visa
- Jan 12, 2020 10:37:19 PM Payment Review Customer Not Notified
Created billing agreement #2815788649299700.
Hi @dbolufer ,
Thank you for the feedback. If I understand correctly, the issue is then solved.
I'll close the ticket for now, but feel free to re-open or create a new one if there are any questions remaining.
Cheers! Marcos Adyen
No, sorry it didn't. Sorry about my explanation :-)
On the last 5 days there was an order with adyen_notification.done = 1
and order.status = 'payment_review'
We have attached all the logs but we didn't find any error
UPDATE: Looking for more info, we found this log entry on adyen/error.log
[2020-01-13 18:31:04] AdyenLoggerTest.ERROR: While processing a notification an exception occured. The payment has already been saved in the adyen_order_payment table but something went wrong later. Please check your logs for potential error messages regarding the merchant reference (order id): "XXXXX" and PSP reference: "YYYY" {"is_exception":false} []
Can you help us in which logs can we looking for the error message?
Hi @dbolufer ,
Usually another module or Magento throws the error and stops our process. You can check in the root exception.log and also in the payment or invoicing related modules log folders as well.
I see that you tried to reprocess the notification itself and for the second time everything went well so I assume that other plugin couldn't reach an API endpoint or another temporary issue occurred which has been resolved for the second try.
I hope this will help.
Best, Attila
@dbolufer did you ever get to the bottom of this? We're running into something very similar (Unique constraint violation), but it's quite hard to reproduce.
For us it doesn't happen in cron, but during order placement. And only in very specific circumstances.
No, sorry. We didn't find the reason of the error, with the patch the problem was minimized but not resolved
@dbolufer Okay I think I found the error in our case, I'm currently doing a write up of the issue and probably will send a PR soon. Not sure if it also fixes your issue, but it seems likely.
If you have a test environment and want to try to reproduce it, try doing two orders: Place order with 5555 4444 3333 1111 10/20 737 Place order with 5555 4444 3333 1111 03/30 737 (notice the difference in expiration dates)
Bigger write up of the issue is coming, but for us it boils down to the fact that vault_payment_token table has UNIQUE indexes for:
But in Vault code, duplicate token check is only done for public_hash. Even though Adyen can return the same gateway_token for different public_hash (when user updates their expiration date etc).
@dbolufer I've written up the issue here: https://github.com/Adyen/adyen-magento2/issues/678
@danslo a way to replicate this is by forcing or faking a deadlock failure on the sales_invoice_grid table. In my case this always started with:
Notification xxxxxx had an error: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction, query was: INSERT INTO `sales_invoice_grid` ...
This happens during $this->_createInvoice:
if ($this->_isTotalAmount($paymentObj->getEntityId(), $orderCurrencyCode)) {
$this->_createInvoice();
} else {
$this->_adyenLogger->addAdyenNotificationCronjob(
'This is a partial AUTHORISATION and the full amount is not reached'
);
}
Because there is no error handling that rolls back the payment creation around $this->_createInvoice();
the code stops there and will arrive at $this->_adyenOrderPaymentFactory->create()...->save()
a minute later, causing the constraint violation.
The code in https://github.com/Adyen/adyen-magento2/commit/f2d13c2576186e0a6362aa446ad3c6e970751d3b helps to get past the constraint violation, but it would be even better if the notification handling would be able to cope with a deadlock on the invoice grid table and roll back the entire procedure somehow to try again later.
Please reopen we are facing this issue at the moment @cyattilakiss Adyen ticet #(#3765581)
[2023-04-04 16:21:57] AdyenLoggerTest.ERROR: While processing a notification an exception occured. The payment has already been saved in the adyen_order_payment table but something went wrong later. Please check your logs for potential error messages regarding the merchant reference (order id): 5000032315 and PSP reference: W9RW3LLKJC2DPK52. Exception message: Unique constraint violation found [] {"uid":"2ef29d1"}
[2023-04-04 17:39:06] AdyenLoggerTest.ADYEN_DEBUG: There are no verified Adyen IP addresses in cache. Updating IP records. [] {"uid":"803b01e"}
also adyen thinks that Rabbit MQ is enabled eventhough it has been disabled [2023-04-04 13:00:10] AdyenLoggerTest.WARNING: Unknown connection name amqp
Solution is the manually reprocess each transaction in adyen notications overview, that is alott of clicking
Magento version: 2.2.8 Plugin version: 5.0 Description
On the production environment we have an order in payment_review status, this order is payed and Adyen has sent the notification.
When the adyen cron process the notification, it raise a "Unique constraint violation found" because there is a row on the table
adyen_order_payment
with the same pspreference and the due to UNIQUE KEY restriction the cronjob the raise an exception.We've solved the error manually:
Please take a look, this is the second time in a month with this bug.
Update We thought we had a couple of bad orders but looking for info we had realized that we had 21 orders payment_review en magento y processing en adyen.
We are using this query to check this missed orders:
This is the log for the error: